فهرست منبع

Changes from comments in Code Review: staring and NPE

masensio 9 سال پیش
والد
کامیت
9fd38ca0dd
2فایلهای تغییر یافته به همراه21 افزوده شده و 13 حذف شده
  1. 1 1
      res/values/strings.xml
  2. 20 12
      src/com/owncloud/android/ui/activity/ManageSpaceActivity.java

+ 1 - 1
res/values/strings.xml

@@ -406,7 +406,7 @@
     <string name="action_switch_list_view">List view</string>
 
     <string name="manage_space_title">Manage space</string>
-    <string name="manage_space_description">Settings, database and server certificates from  %1$s\'s data will be deleted permanentlty. \n\nDownloaded files will be kept untouched.\n\nThis process can take some time.</string>
+    <string name="manage_space_description">Settings, database and server certificates from %1$s\'s data will be deleted permanentlty. \n\nDownloaded files will be kept untouched.\n\nThis process can take some time.</string>
     <string name="manage_space_clear_data">Clear data</string>
     <string name="manage_space_error">Some files could not be deleted.</string>
 </resources>

+ 20 - 12
src/com/owncloud/android/ui/activity/ManageSpaceActivity.java

@@ -146,12 +146,16 @@ public class ManageSpaceActivity extends AppCompatActivity {
             File appDir = new File(getCacheDir().getParent());
             if (appDir.exists()) {
                 String[] children = appDir.list();
-                for (String s : children) {
-                    if (!LIB_FOLDER.equals(s)) {
-                        File fileToDelete = new File(appDir, s);
-                        clearResult = clearResult && deleteDir(fileToDelete);
-                        Log_OC.d(TAG, "Clear Application Data, File: " + fileToDelete.getName()+ " DELETED *******");
+                if (children != null) {
+                    for (String s : children) {
+                        if (!LIB_FOLDER.equals(s)) {
+                            File fileToDelete = new File(appDir, s);
+                            clearResult = clearResult && deleteDir(fileToDelete);
+                            Log_OC.d(TAG, "Clear Application Data, File: " + fileToDelete.getName() + " DELETED *****");
+                        }
                     }
+                } else {
+                    clearResult = false;
                 }
             }
             return  clearResult;
@@ -160,14 +164,18 @@ public class ManageSpaceActivity extends AppCompatActivity {
         public boolean deleteDir(File dir) {
             if (dir != null && dir.isDirectory()) {
                 String[] children = dir.list();
-                for (int i = 0; i < children.length; i++) {
-                    boolean success = deleteDir(new File(dir, children[i]));
-                    if (!success) {
-                        Log_OC.w(TAG, "File NOT deleted " + children[i]);
-                        return false;
-                    } else {
-                        Log_OC.d(TAG, "File deleted " + children[i]);
+                if (children != null) {
+                    for (int i = 0; i < children.length; i++) {
+                        boolean success = deleteDir(new File(dir, children[i]));
+                        if (!success) {
+                            Log_OC.w(TAG, "File NOT deleted " + children[i]);
+                            return false;
+                        } else {
+                            Log_OC.d(TAG, "File deleted " + children[i]);
+                        }
                     }
+                } else {
+                    return false;
                 }
             }