X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/b64fd4cc5b9d702f18cbc27ed650ba604d0757dd..acb2da8f02ead5c17a4b6b36466efda91a7b42e9:/src/com/owncloud/android/files/services/FileUploader.java diff --git a/src/com/owncloud/android/files/services/FileUploader.java b/src/com/owncloud/android/files/services/FileUploader.java index f56e1b57..c5b92171 100644 --- a/src/com/owncloud/android/files/services/FileUploader.java +++ b/src/com/owncloud/android/files/services/FileUploader.java @@ -1,6 +1,6 @@ /* ownCloud Android client application * Copyright (C) 2012 Bartek Przybylski - * Copyright (C) 2012-2013 ownCloud Inc. + * Copyright (C) 2012-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,6 +56,7 @@ import com.owncloud.android.lib.common.OwnCloudClient; import com.owncloud.android.lib.common.OwnCloudClientManagerFactory; import com.owncloud.android.lib.common.accounts.AccountUtils.Constants; import com.owncloud.android.lib.common.network.OnDatatransferProgressListener; +import com.owncloud.android.lib.common.operations.OperationCancelledException; import com.owncloud.android.lib.common.operations.RemoteOperation; import com.owncloud.android.lib.common.operations.RemoteOperationResult; import com.owncloud.android.lib.common.operations.RemoteOperationResult.ResultCode; @@ -211,11 +212,11 @@ public class FileUploader extends Service implements OnDatatransferProgressListe if (intent.hasExtra(KEY_FILE)) { files = (OCFile[]) intent.getParcelableArrayExtra(KEY_FILE); // TODO - // will - // this - // casting - // work - // fine? + // will + // this + // casting + // work + // fine? } else { localPaths = intent.getStringArrayExtra(KEY_LOCAL_FILE); @@ -352,7 +353,39 @@ public class FileUploader extends Service implements OnDatatransferProgressListe upload = mPendingUploads.remove(buildRemoteName(account, file)); } if (upload != null) { - upload.cancel(); + mCurrentUpload.cancel(); + } + } + + /** + * Cancels a pending or current upload for an account + * + * @param account Owncloud accountName where the remote file will be stored. + */ + public void cancel(Account account) { + Log_OC.d(TAG, "Account= " + account.name); + + if (mCurrentUpload != null) { + Log_OC.d(TAG, "Current Upload Account= " + mCurrentUpload.getAccount().name); + if (mCurrentUpload.getAccount().name == account.name) { + mCurrentUpload.cancel(); + } + } + // Cancel pending uploads + Iterator it = mPendingUploads.keySet().iterator(); + Log_OC.d(TAG, "Number of pending updloads= " + mPendingUploads.size()); + while (it.hasNext()) { + String key = it.next(); + Log_OC.d(TAG, "mPendingUploads CANCELLED " + key); + if (key.startsWith(account.name)) { + UploadFileOperation upload; + synchronized (mPendingUploads) { + upload = mPendingUploads.remove(key); + } + if (upload != null) { + mCurrentUpload.cancel(); + } + } } } @@ -562,7 +595,8 @@ public class FileUploader extends Service implements OnDatatransferProgressListe private RemoteOperationResult grantFolderExistence(String pathToGrant) { RemoteOperation operation = new ExistenceCheckRemoteOperation(pathToGrant, this, false); RemoteOperationResult result = operation.execute(mUploadClient); - if (!result.isSuccess() && result.getCode() == ResultCode.FILE_NOT_FOUND && mCurrentUpload.isRemoteFolderToBeCreated()) { + if (!result.isSuccess() && result.getCode() == ResultCode.FILE_NOT_FOUND && + mCurrentUpload.isRemoteFolderToBeCreated()) { SyncOperation syncOp = new CreateFolderOperation( pathToGrant, true); result = syncOp.execute(mUploadClient, mStorageManager); } @@ -583,7 +617,8 @@ public class FileUploader extends Service implements OnDatatransferProgressListe private OCFile createLocalFolder(String remotePath) { String parentPath = new File(remotePath).getParent(); - parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? parentPath : parentPath + OCFile.PATH_SEPARATOR; + parentPath = parentPath.endsWith(OCFile.PATH_SEPARATOR) ? + parentPath : parentPath + OCFile.PATH_SEPARATOR; OCFile parent = mStorageManager.getFileByPath(parentPath); if (parent == null) { parent = createLocalFolder(parentPath); @@ -891,12 +926,13 @@ public class FileUploader extends Service implements OnDatatransferProgressListe // this can be slow if there are many uploads :( Iterator it = mPendingUploads.keySet().iterator(); Log_OC.d(TAG, "Number of pending updloads= " + mPendingUploads.size()); - boolean found; while (it.hasNext()) { String key = it.next(); - Log_OC.d(TAG, "mPendingUploads CANCELLED" + key); + Log_OC.d(TAG, "mPendingUploads CANCELLED " + key); if (key.startsWith(accountName)) { - mPendingUploads.remove(key); + synchronized (mPendingUploads) { + mPendingUploads.remove(key); + } } } }