Avoid use of queues to delay recursion
authorDavid A. Velasco <dvelasco@solidgear.es>
Fri, 6 Jul 2012 07:27:01 +0000 (09:27 +0200)
committerDavid A. Velasco <dvelasco@solidgear.es>
Fri, 6 Jul 2012 07:27:01 +0000 (09:27 +0200)
src/eu/alefzero/owncloud/syncadapter/FileSyncAdapter.java

index 5689262..14237e4 100644 (file)
@@ -100,36 +100,46 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
         } catch (DavException e) {\r
             syncResult.stats.numIoExceptions++;\r
             e.printStackTrace();\r
-        } catch (Throwable t) {\r
+        } catch (RuntimeException r) {\r
             //TODO count ; any type of exception should be treated, and the progress indicator finished;\r
             //             reporting the user about bad synchronizations should be discussed\r
-            t.printStackTrace();\r
+            r.printStackTrace();\r
+            throw r;\r
         }\r
         sendStickyBroadcast(false, -1);        \r
     }\r
 \r
     private void fetchData(String uri, SyncResult syncResult, long parentId) {\r
         try {\r
+            Log.v(TAG, "syncing: fetching " + uri);\r
+            \r
+            boolean logmore = (uri.contains("many-files"));\r
+\r
+            // remote request \r
+            if (logmore) Log.v(TAG, "syncing: fetching many-files, TO REQUEST");\r
             PropFindMethod query = new PropFindMethod(uri);\r
             getClient().executeMethod(query);\r
             MultiStatus resp = null;\r
+            \r
+            if (logmore) Log.v(TAG, "syncing: fetching many-files, TO PREPARE THE RESPONSE");\r
             resp = query.getResponseBodyAsMultiStatus();\r
-            Queue<String> paths = new LinkedList<String>();\r
-            Queue<Long> fileIds = new LinkedList<Long>(); \r
+            \r
+            // insertion of updated files\r
+            if (logmore) Log.v(TAG, "syncing: fetching many-files, TO PARSE REPONSES");\r
             for (int i = 1; i < resp.getResponses().length; ++i) {\r
+                if (logmore) Log.v(TAG, "syncing: fetching many-files, PARSING REPONSE " + i + "-esima");\r
                 WebdavEntry we = new WebdavEntry(resp.getResponses()[i], getUri().getPath());\r
                 OCFile file = fillOCFile(we);\r
                 file.setParentId(parentId);\r
                 getStorageManager().saveFile(file);\r
                 if (parentId == 0)\r
                     parentId = file.getFileId();\r
-                if (we.contentType().equals("DIR")) {\r
-                    // for recursive fetch later\r
-                    paths.add(we.path());\r
-                    fileIds.add(file.getFileId());\r
-                }\r
             }\r
             \r
+            // removal of old files\r
+            // TODO - getDirectoryContent is crashing the app by lack of memory when a lot of files are in the same directory!!!!\r
+            //        tested with the path /\r
+            if (logmore) Log.v(TAG, "syncing: fetching many-files, RETRIEVING VECTOR OF FILES");\r
             Vector<OCFile> files = getStorageManager().getDirectoryContent(\r
                     getStorageManager().getFileById(parentId));\r
             for (OCFile file : files) {\r
@@ -138,14 +148,17 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
             }\r
             \r
             // synched folder -> notice to IU\r
+            if (logmore) Log.v(TAG, "syncing: fetching many-files, NOTIFYING THE UI");\r
             sendStickyBroadcast(true, parentId);\r
 \r
             // recursive fetch\r
-            while(!paths.isEmpty()) {\r
-                fetchData(getUri().toString() + paths.remove(), syncResult, fileIds.remove());\r
+            if (logmore) Log.v(TAG, "syncing: fetching many-files, TRYING TO RECURSE");\r
+            files = getStorageManager().getDirectoryContent(getStorageManager().getFileById(parentId));\r
+            for (OCFile file : files) {\r
+                if (file.getMimetype().equals("DIR")) {\r
+                    fetchData(getUri().toString() + file.getRemotePath(), syncResult, file.getFileId());\r
+                }\r
             }\r
-            paths = null;\r
-            fileIds = null;\r
 \r
 \r
         } catch (OperationCanceledException e) {\r