X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/acb2da8f02ead5c17a4b6b36466efda91a7b42e9..c0c52fa16a79f6be71ffbe7c7cb587af67335793:/src/com/owncloud/android/operations/UploadFileOperation.java diff --git a/src/com/owncloud/android/operations/UploadFileOperation.java b/src/com/owncloud/android/operations/UploadFileOperation.java index 42ca738f..77de090d 100644 --- a/src/com/owncloud/android/operations/UploadFileOperation.java +++ b/src/com/owncloud/android/operations/UploadFileOperation.java @@ -1,5 +1,8 @@ -/* ownCloud Android client application - * Copyright (C) 2012-2015 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, @@ -26,7 +29,6 @@ import java.io.OutputStream; import java.util.HashSet; import java.util.Iterator; import java.util.Set; -import java.util.concurrent.CancellationException; import java.util.concurrent.atomic.AtomicBoolean; import org.apache.commons.httpclient.methods.PutMethod; @@ -56,8 +58,6 @@ import com.owncloud.android.utils.UriUtils; /** * Remote operation performing the upload of a file to an ownCloud server - * - * @author David A. Velasco */ public class UploadFileOperation extends RemoteOperation { @@ -93,7 +93,8 @@ public class UploadFileOperation extends RemoteOperation { int localBehaviour, Context context) { if (account == null) - throw new IllegalArgumentException("Illegal NULL account in UploadFileOperation creation"); + throw new IllegalArgumentException("Illegal NULL account in UploadFileOperation " + + "creation"); if (file == null) throw new IllegalArgumentException("Illegal NULL file in UploadFileOperation creation"); if (file.getStoragePath() == null || file.getStoragePath().length() <= 0) { @@ -258,7 +259,6 @@ public class UploadFileOperation extends RemoteOperation { (nRead = in.read(data, 0, data.length)) != -1) { out.write(data, 0, nRead); } - out.flush(); } else { @@ -278,6 +278,11 @@ public class UploadFileOperation extends RemoteOperation { } } + if (mCancellationRequested.get()) { + result = new RemoteOperationResult(new OperationCancelledException()); + } + + } catch (Exception e) { result = new RemoteOperationResult(ResultCode.LOCAL_STORAGE_NOT_COPIED); return result; @@ -300,7 +305,7 @@ public class UploadFileOperation extends RemoteOperation { } } } - localCopyPassed = true; + localCopyPassed = (result == null); /// perform the upload if ( mChunked && @@ -316,9 +321,12 @@ public class UploadFileOperation extends RemoteOperation { while (listener.hasNext()) { mUploadOperation.addDatatransferProgressListener(listener.next()); } - if (!mCancellationRequested.get()) { - result = mUploadOperation.execute(client); + if (mCancellationRequested.get()) { + throw new OperationCancelledException(); } + + result = mUploadOperation.execute(client); + /// move local temporal file or original file to its corresponding // location in the ownCloud local folder if (result.isSuccess()) { @@ -329,8 +337,8 @@ public class UploadFileOperation extends RemoteOperation { mFile.setStoragePath(expectedPath); File fileToMove = null; if (temporalFile != null) { // FileUploader.LOCAL_BEHAVIOUR_COPY - // ; see where temporalFile was - // set + // ; see where temporalFile was + // set fileToMove = temporalFile; } else { // FileUploader.LOCAL_BEHAVIOUR_MOVE fileToMove = originalFile; @@ -355,13 +363,7 @@ public class UploadFileOperation extends RemoteOperation { } } catch (Exception e) { - // TODO something cleaner with cancellations - if (mCancellationRequested.get()) { - mUploadOperation.cancel(); - result = new RemoteOperationResult(new OperationCancelledException()); - } else { - result = new RemoteOperationResult(e); - } + result = new RemoteOperationResult(e); } finally { if (temporalFile != null && !originalFile.equals(temporalFile)) { @@ -402,7 +404,7 @@ public class UploadFileOperation extends RemoteOperation { newFile.setModificationTimestampAtLastSyncForData( mFile.getModificationTimestampAtLastSyncForData()); // newFile.setEtag(mFile.getEtag()) - newFile.setKeepInSync(mFile.keepInSync()); + newFile.setFavorite(mFile.isFavorite()); newFile.setLastSyncDateForProperties(mFile.getLastSyncDateForProperties()); newFile.setLastSyncDateForData(mFile.getLastSyncDateForData()); newFile.setStoragePath(mFile.getStoragePath());