complete two way synchronization
[pub/Android/ownCloud.git] / src / com / owncloud / android / syncadapter / FileSyncAdapter.java
index f7bfa43..7b803fc 100644 (file)
@@ -91,7 +91,7 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
 \r
         sendStickyBroadcast(true, null);  // message to signal the start to the UI\r
 \r
-        PropFindMethod query;\r
+        PropFindMethod query = null;\r
         try {\r
             mCurrentSyncTime = System.currentTimeMillis();\r
             query = new PropFindMethod(getUri().toString() + "/");\r
@@ -123,6 +123,10 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
             // TODO update syncResult\r
             Log.e(TAG, "problem while synchronizing owncloud account " + account.name, t);\r
             t.printStackTrace();\r
+            \r
+        } finally {\r
+            if (query != null)\r
+                query.releaseConnection();  // let the connection available for other methods\r
         }\r
         \r
         /*  Commented code for ugly performance tests\r
@@ -150,11 +154,12 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
     }\r
 \r
     private void fetchData(String uri, SyncResult syncResult, long parentId) {\r
+        PropFindMethod query = null;\r
         try {\r
             Log.d(TAG, "fetching " + uri);\r
             \r
             // remote request \r
-            PropFindMethod query = new PropFindMethod(uri);\r
+            query = new PropFindMethod(uri);\r
             /*  Commented code for ugly performance tests\r
             long responseDelay = System.currentTimeMillis();\r
             */\r
@@ -205,11 +210,12 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
             Vector<OCFile> files = getStorageManager().getDirectoryContent(\r
                     getStorageManager().getFileById(parentId));\r
             OCFile file;\r
+            String currentSavePath = FileDownloader.getSavePath(mAccount.name);\r
             for (int i=0; i < files.size(); ) {\r
                 file = files.get(i);\r
                 if (file.getLastSyncDate() != mCurrentSyncTime) {\r
                     Log.v(TAG, "removing file: " + file);\r
-                    getStorageManager().removeFile(file);\r
+                    getStorageManager().removeFile(file, (file.isDown() && file.getStoragePath().startsWith(currentSavePath)));\r
                     files.remove(i);\r
                 } else {\r
                     i++;\r
@@ -236,8 +242,6 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
             if (mDelaysIndex >= MAX_DELAYS)\r
                 mDelaysIndex = 0;\r
              */\r
-            \r
-\r
 \r
         } catch (OperationCanceledException e) {\r
             e.printStackTrace();\r
@@ -254,6 +258,10 @@ public class FileSyncAdapter extends AbstractOwnCloudSyncAdapter {
             // TODO update syncResult\r
             Log.e(TAG, "problem while synchronizing owncloud account " + mAccount.name, t);\r
             t.printStackTrace();\r
+            \r
+        } finally {\r
+            if (query != null)\r
+                query.releaseConnection();  // let the connection available for other methods\r
         }\r
     }\r
 \r