Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 522ea30d authored by David A. Velasco's avatar David A. Velasco
Browse files

Simplified flow of interruption of uploads in cancellations

parent 8bf27637
Loading
Loading
Loading
Loading
+4 −1
Original line number Diff line number Diff line
@@ -32,7 +32,6 @@ import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;
import java.util.Random;

import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.methods.PutMethod;

import com.owncloud.android.lib.common.OwnCloudClient;
@@ -85,6 +84,10 @@ public class ChunkedUploadRemoteFileOperation extends UploadRemoteFileOperation
                mPutMethod.addRequestHeader(OC_TOTAL_LENGTH_HEADER, String.valueOf(file.length()));
                ((ChunkFromFileChannelRequestEntity) mEntity).setOffset(offset);
                mPutMethod.setRequestEntity(mEntity);
                if (mCancellationRequested.get()) {
                    mPutMethod.abort();
                    // next method will throw an exception
                }
                status = client.executeMethod(mPutMethod);

                if (status == 400) {
+17 −16
Original line number Diff line number Diff line
@@ -67,7 +67,7 @@ public class UploadRemoteFileOperation extends RemoteOperation {
	protected PutMethod mPutMethod = null;
	protected boolean mForbiddenCharsInServer = false;
	
	private final AtomicBoolean mCancellationRequested = new AtomicBoolean(false);
	protected final AtomicBoolean mCancellationRequested = new AtomicBoolean(false);
	protected Set<OnDatatransferProgressListener> mDataTransferListeners = new HashSet<OnDatatransferProgressListener>();

	protected RequestEntity mEntity = null;
@@ -83,16 +83,14 @@ public class UploadRemoteFileOperation extends RemoteOperation {
		RemoteOperationResult result = null;

		try {
			// / perform the upload
			synchronized (mCancellationRequested) {
			mPutMethod = new PutMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath));

			if (mCancellationRequested.get()) {
					throw new OperationCancelledException();
				} else {
					mPutMethod = new PutMethod(client.getWebdavUri() +
                            WebdavUtils.encodePath(mRemotePath));
				}
			}
				// the operation was cancelled before getting it's turn to be executed in the queue of uploads
				result = new RemoteOperationResult(new OperationCancelledException());

			} else {
				// perform the upload
				int status = uploadFile(client);
				if (mForbiddenCharsInServer){
					result = new RemoteOperationResult(
@@ -101,9 +99,12 @@ public class UploadRemoteFileOperation extends RemoteOperation {
					result = new RemoteOperationResult(isSuccess(status), status,
							(mPutMethod != null ? mPutMethod.getResponseHeaders() : null));
				}
			}

		} catch (Exception e) {
			if (mCancellationRequested.get() && !(e instanceof OperationCancelledException)) {
			if (mPutMethod != null && mPutMethod.isAborted()) {
				result = new RemoteOperationResult(new OperationCancelledException());

			} else {
				result = new RemoteOperationResult(e);
			}