X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/c0c52fa16a79f6be71ffbe7c7cb587af67335793..c54d7e35d0efb3d1352ff6d1330cac185bef0a21:/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 445274c4..7c953b84 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; @@ -534,8 +532,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 +567,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 +586,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 +676,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(); @@ -688,6 +694,8 @@ public class FileUploader extends Service if (result.isSuccess()) { updateOCFile(file, (RemoteFile) result.getData().get(0)); file.setLastSyncDateForProperties(syncDate); + } else { + Log_OC.e(TAG, "Error reading properties of file after successful upload; this is gonna hurt..."); } // / maybe this would be better as part of UploadFileOperation... or @@ -697,6 +705,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 @@ -704,6 +713,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) { @@ -712,7 +725,7 @@ public class FileUploader extends Service file.setMimetype(remoteFile.getMimeType()); file.setModificationTimestamp(remoteFile.getModifiedTimestamp()); file.setModificationTimestampAtLastSyncForData(remoteFile.getModifiedTimestamp()); - // file.setEtag(remoteFile.getEtag()); // TODO Etag, where available + file.setEtag(remoteFile.getEtag()); file.setRemoteId(remoteFile.getRemoteId()); }