|
@@ -165,13 +165,23 @@ public class SynchronizeFolderOperation extends SyncOperation {
|
|
|
sendBroadcastForNotifyingUIUpdate(result.isSuccess());
|
|
|
}
|
|
|
}
|
|
|
- } catch (OperationCancelledException e) {
|
|
|
- result = new RemoteOperationResult(e);
|
|
|
|
|
|
- // cancel 'child' synchronizations
|
|
|
- for (SyncOperation synchOp: mFoldersToWalkDown) {
|
|
|
- ((SynchronizeFolderOperation) synchOp).cancel();
|
|
|
+ if (mCancellationRequested.get()) {
|
|
|
+ throw new OperationCancelledException();
|
|
|
}
|
|
|
+
|
|
|
+ } catch (OperationCancelledException e) {
|
|
|
+ result = new RemoteOperationResult(e);
|
|
|
+
|
|
|
+ // Needed in case that cancellation occurs before starting any download.
|
|
|
+ // If not, yellow arrow continues being shown.
|
|
|
+ sendBroadcastForNotifyingUIUpdate(false);
|
|
|
+
|
|
|
+ Intent intent = new Intent(mContext, FileDownloader.class);
|
|
|
+ intent.setAction(FileDownloader.ACTION_CANCEL_FILE_DOWNLOAD);
|
|
|
+ intent.putExtra(FileDownloader.EXTRA_ACCOUNT, mAccount);
|
|
|
+ intent.putExtra(FileDownloader.EXTRA_FILE, mLocalFolder);
|
|
|
+ mContext.startService(intent);
|
|
|
}
|
|
|
|
|
|
return result;
|
|
@@ -275,7 +285,8 @@ public class SynchronizeFolderOperation extends SyncOperation {
|
|
|
* retrieved.
|
|
|
* @return 'True' when any change was made in the local data, 'false' otherwise
|
|
|
*/
|
|
|
- private void synchronizeData(ArrayList<Object> folderAndFiles, OwnCloudClient client) {
|
|
|
+ private void synchronizeData(ArrayList<Object> folderAndFiles, OwnCloudClient client)
|
|
|
+ throws OperationCancelledException {
|
|
|
FileDataStorageManager storageManager = getStorageManager();
|
|
|
|
|
|
// parse data from remote folder
|
|
@@ -290,7 +301,13 @@ public class SynchronizeFolderOperation extends SyncOperation {
|
|
|
mFilesForDirectDownload.clear();
|
|
|
mFilesToSyncContentsWithoutUpload.clear();
|
|
|
mFavouriteFilesToSyncContents.clear();
|
|
|
- mFoldersToWalkDown.clear();
|
|
|
+
|
|
|
+ synchronized(mFoldersToWalkDown) {
|
|
|
+ if (mCancellationRequested.get()) {
|
|
|
+ throw new OperationCancelledException();
|
|
|
+ }
|
|
|
+ mFoldersToWalkDown.clear();
|
|
|
+ }
|
|
|
|
|
|
// get current data about local contents of the folder to synchronize
|
|
|
List<OCFile> localFiles = storageManager.getFolderContent(mLocalFolder);
|
|
@@ -352,8 +369,14 @@ public class SynchronizeFolderOperation extends SyncOperation {
|
|
|
mAccount,
|
|
|
mCurrentSyncTime
|
|
|
);
|
|
|
- mFoldersToWalkDown.add(synchFolderOp);
|
|
|
-
|
|
|
+
|
|
|
+ synchronized(mFoldersToWalkDown) {
|
|
|
+ if (mCancellationRequested.get()) {
|
|
|
+ throw new OperationCancelledException();
|
|
|
+ }
|
|
|
+ mFoldersToWalkDown.add(synchFolderOp);
|
|
|
+ }
|
|
|
+
|
|
|
} else if (remoteFile.keepInSync()) {
|
|
|
/// prepare content synchronization for kept-in-sync files
|
|
|
SynchronizeFileOperation operation = new SynchronizeFileOperation(
|
|
@@ -387,7 +410,7 @@ public class SynchronizeFolderOperation extends SyncOperation {
|
|
|
}
|
|
|
|
|
|
|
|
|
- private void prepareOpsFromLocalKnowledge() {
|
|
|
+ private void prepareOpsFromLocalKnowledge() throws OperationCancelledException {
|
|
|
List<OCFile> children = getStorageManager().getFolderContent(mLocalFolder);
|
|
|
for (OCFile child : children) {
|
|
|
/// classify file to sync/download contents later
|
|
@@ -399,8 +422,14 @@ public class SynchronizeFolderOperation extends SyncOperation {
|
|
|
mAccount,
|
|
|
mCurrentSyncTime
|
|
|
);
|
|
|
- mFoldersToWalkDown.add(synchFolderOp);
|
|
|
-
|
|
|
+
|
|
|
+ synchronized(mFoldersToWalkDown) {
|
|
|
+ if (mCancellationRequested.get()) {
|
|
|
+ throw new OperationCancelledException();
|
|
|
+ }
|
|
|
+ mFoldersToWalkDown.add(synchFolderOp);
|
|
|
+ }
|
|
|
+
|
|
|
} else {
|
|
|
/// prepare limited synchronization for regular files
|
|
|
if (!child.isDown()) {
|
|
@@ -541,6 +570,13 @@ public class SynchronizeFolderOperation extends SyncOperation {
|
|
|
*/
|
|
|
public void cancel() {
|
|
|
mCancellationRequested.set(true);
|
|
|
+
|
|
|
+ synchronized(mFoldersToWalkDown) {
|
|
|
+ // cancel 'child' synchronizations
|
|
|
+ for (SyncOperation synchOp : mFoldersToWalkDown) {
|
|
|
+ ((SynchronizeFolderOperation) synchOp).cancel();
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
public String getFolderPath() {
|