X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/5f41bb14d370e0c9c0a8003e4ed122f466b0ce71..b277d52ab693c57d2f74c2063e8b3f6afa36c356:/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 2695b773..9bc2742e 100644 --- a/src/com/owncloud/android/files/services/FileUploader.java +++ b/src/com/owncloud/android/files/services/FileUploader.java @@ -21,7 +21,6 @@ package com.owncloud.android.files.services; import java.io.File; -import java.io.IOException; import java.util.AbstractList; import java.util.HashMap; import java.util.Iterator; @@ -30,7 +29,6 @@ import java.util.Vector; import android.accounts.Account; import android.accounts.AccountManager; -import android.accounts.AccountsException; import android.accounts.OnAccountsUpdateListener; import android.app.NotificationManager; import android.app.PendingIntent; @@ -100,9 +98,12 @@ public class FileUploader extends Service public static final String KEY_INSTANT_UPLOAD = "INSTANT_UPLOAD"; public static final String KEY_LOCAL_BEHAVIOUR = "BEHAVIOUR"; + public static final String KEY_CANCEL_ALL = "CANCEL_ALL"; + public static final int LOCAL_BEHAVIOUR_COPY = 0; public static final int LOCAL_BEHAVIOUR_MOVE = 1; public static final int LOCAL_BEHAVIOUR_FORGET = 2; + public static final int LOCAL_BEHAVIOUR_REMOVE = 3; public static final int UPLOAD_SINGLE_FILE = 0; public static final int UPLOAD_MULTIPLE_FILES = 1; @@ -196,6 +197,21 @@ public class FileUploader extends Service public int onStartCommand(Intent intent, int flags, int startId) { Log_OC.d(TAG, "Starting command with id " + startId); + if (intent.hasExtra(KEY_CANCEL_ALL) && intent.hasExtra(KEY_ACCOUNT)){ + Account account = intent.getParcelableExtra(KEY_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.equals(account.name)) { + mCurrentUpload.cancel(); + } + } + // Cancel pending uploads + cancelUploadsForAccount(account); + } + if (!intent.hasExtra(KEY_ACCOUNT) || !intent.hasExtra(KEY_UPLOAD_TYPE) || !(intent.hasExtra(KEY_LOCAL_FILE) || intent.hasExtra(KEY_FILE))) { Log_OC.e(TAG, "Not enough information provided in intent"); @@ -534,8 +550,6 @@ public class FileUploader extends Service */ public void uploadFile(String uploadKey) { - Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(), - "Getting upload of " + uploadKey); mCurrentUpload = mPendingUploads.get(uploadKey); if (mCurrentUpload != null) { @@ -571,13 +585,15 @@ public class FileUploader extends Service /// perform the upload if (grantResult.isSuccess()) { - Log_OC.v( "NOW " + TAG + ", thread " + Thread.currentThread().getName(), - "Executing upload of " + mCurrentUpload.getRemotePath()); OCFile parent = mStorageManager.getFileByPath(remoteParentPath); mCurrentUpload.getFile().setParentId(parent.getFileId()); uploadResult = mCurrentUpload.execute(mUploadClient); if (uploadResult.isSuccess()) { saveUploadedFile(); + + } else if (uploadResult.getCode() == ResultCode.SYNC_CONFLICT) { + mStorageManager.saveConflict(mCurrentUpload.getFile(), + mCurrentUpload.getFile().getEtagInConflict()); } } else { uploadResult = grantResult; @@ -588,10 +604,18 @@ public class FileUploader extends Service uploadResult = new RemoteOperationResult(e); } finally { - Log_OC.v("NOW " + TAG + ", thread " + Thread.currentThread().getName(), - "Removing payload " + mCurrentUpload.getRemotePath()); - Pair removeResult = - mPendingUploads.removePayload(mCurrentAccount, mCurrentUpload.getRemotePath()); + Pair removeResult; + if (mCurrentUpload.wasRenamed()) { + removeResult = mPendingUploads.removePayload( + mCurrentAccount, + mCurrentUpload.getOldFile().getRemotePath() + ); + } else { + removeResult = mPendingUploads.removePayload( + mCurrentAccount, + mCurrentUpload.getRemotePath() + ); + } /// notify result notifyUploadResult(mCurrentUpload, uploadResult); @@ -670,7 +694,7 @@ public class FileUploader extends Service * synchronized with the server, specially the modification time and Etag * (where available) * - * TODO refactor this ugly thing + * TODO move into UploadFileOperation */ private void saveUploadedFile() { OCFile file = mCurrentUpload.getFile(); @@ -699,6 +723,7 @@ public class FileUploader extends Service if (oldFile.fileExists()) { oldFile.setStoragePath(null); mStorageManager.saveFile(oldFile); + mStorageManager.saveConflict(oldFile, null); } // else: it was just an automatic renaming due to a name // coincidence; nothing else is needed, the storagePath is right @@ -706,6 +731,10 @@ public class FileUploader extends Service } file.setNeedsUpdateThumbnail(true); mStorageManager.saveFile(file); + mStorageManager.saveConflict(file, null); + + mStorageManager.triggerMediaScan(file.getStoragePath()); + } private void updateOCFile(OCFile file, RemoteFile remoteFile) {