Process share with password
[pub/Android/ownCloud.git] / src / com / owncloud / android / operations / SynchronizeFolderOperation.java
index 61375c4..e80b42f 100644 (file)
@@ -1,5 +1,8 @@
-/* ownCloud Android client application
- *   Copyright (C) 2012-2014 ownCloud Inc.
+/**
+ *   ownCloud Android client application
+ *
+ *   @author David A. Velasco
+ *   Copyright (C) 2015 ownCloud Inc.
  *
  *   This program is free software: you can redistribute it and/or modify
  *   it under the terms of the GNU General Public License version 2,
@@ -56,8 +59,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
  *  properties, and updates the local database with them.
  *  
  *  Does NOT enter in the child folders to synchronize their contents also.
- * 
- *  @author David A. Velasco
  */
 public class SynchronizeFolderOperation extends SyncOperation {
 
@@ -344,10 +345,11 @@ public class SynchronizeFolderOperation extends SyncOperation {
             /// classify file to sync/download contents later
             if (remoteFile.isFolder()) {
                 /// to download children files recursively
-                startSyncFolderOperation(remoteFile.getRemotePath());
-
-                if (mCancellationRequested.get()) {
-                    throw new OperationCancelledException();
+                synchronized(mCancellationRequested) {
+                    if (mCancellationRequested.get()) {
+                        throw new OperationCancelledException();
+                    }
+                    startSyncFolderOperation(remoteFile.getRemotePath());
                 }
 
             } else if (remoteFile.keepInSync()) {
@@ -389,9 +391,11 @@ public class SynchronizeFolderOperation extends SyncOperation {
             /// classify file to sync/download contents later
             if (child.isFolder()) {
                 /// to download children files recursively
-                startSyncFolderOperation(child.getRemotePath());
-                if (mCancellationRequested.get()) {
-                    throw new OperationCancelledException();
+                synchronized(mCancellationRequested) {
+                    if (mCancellationRequested.get()) {
+                        throw new OperationCancelledException();
+                    }
+                    startSyncFolderOperation(child.getRemotePath());
                 }
 
             } else {
@@ -413,13 +417,15 @@ public class SynchronizeFolderOperation extends SyncOperation {
     
     private void startDirectDownloads() throws OperationCancelledException {
         for (OCFile file : mFilesForDirectDownload) {
-            if (mCancellationRequested.get()) {
-                throw new OperationCancelledException();
+            synchronized(mCancellationRequested) {
+                if (mCancellationRequested.get()) {
+                    throw new OperationCancelledException();
+                }
+                Intent i = new Intent(mContext, FileDownloader.class);
+                i.putExtra(FileDownloader.EXTRA_ACCOUNT, mAccount);
+                i.putExtra(FileDownloader.EXTRA_FILE, file);
+                mContext.startService(i);
             }
-            Intent i = new Intent(mContext, FileDownloader.class);
-            i.putExtra(FileDownloader.EXTRA_ACCOUNT, mAccount);
-            i.putExtra(FileDownloader.EXTRA_FILE, file);
-            mContext.startService(i);
         }
     }
 
@@ -435,7 +441,8 @@ public class SynchronizeFolderOperation extends SyncOperation {
      */
     private void startContentSynchronizations(List<SyncOperation> filesToSyncContents, OwnCloudClient client) 
             throws OperationCancelledException {
-        
+
+        Log_OC.v(TAG, "Starting content synchronization... ");
         RemoteOperationResult contentsResult = null;
         for (SyncOperation op: filesToSyncContents) {
             if (mCancellationRequested.get()) {
@@ -520,4 +527,8 @@ public class SynchronizeFolderOperation extends SyncOperation {
         intent.putExtra(OperationsService.EXTRA_REMOTE_PATH, path);
         mContext.startService(intent);
     }
+
+    public String getRemotePath() {
+        return mRemotePath;
+    }
 }