mirror of
https://github.com/owncloud/android-library.git
synced 2025-06-08 08:26:10 +00:00
Simplified flow of interruption of uploads in cancellations
This commit is contained in:
parent
8bf276377c
commit
522ea30da0
@ -32,7 +32,6 @@ import java.io.RandomAccessFile;
|
|||||||
import java.nio.channels.FileChannel;
|
import java.nio.channels.FileChannel;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
import org.apache.commons.httpclient.HttpException;
|
|
||||||
import org.apache.commons.httpclient.methods.PutMethod;
|
import org.apache.commons.httpclient.methods.PutMethod;
|
||||||
|
|
||||||
import com.owncloud.android.lib.common.OwnCloudClient;
|
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()));
|
mPutMethod.addRequestHeader(OC_TOTAL_LENGTH_HEADER, String.valueOf(file.length()));
|
||||||
((ChunkFromFileChannelRequestEntity) mEntity).setOffset(offset);
|
((ChunkFromFileChannelRequestEntity) mEntity).setOffset(offset);
|
||||||
mPutMethod.setRequestEntity(mEntity);
|
mPutMethod.setRequestEntity(mEntity);
|
||||||
|
if (mCancellationRequested.get()) {
|
||||||
|
mPutMethod.abort();
|
||||||
|
// next method will throw an exception
|
||||||
|
}
|
||||||
status = client.executeMethod(mPutMethod);
|
status = client.executeMethod(mPutMethod);
|
||||||
|
|
||||||
if (status == 400) {
|
if (status == 400) {
|
||||||
|
@ -67,7 +67,7 @@ public class UploadRemoteFileOperation extends RemoteOperation {
|
|||||||
protected PutMethod mPutMethod = null;
|
protected PutMethod mPutMethod = null;
|
||||||
protected boolean mForbiddenCharsInServer = false;
|
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 Set<OnDatatransferProgressListener> mDataTransferListeners = new HashSet<OnDatatransferProgressListener>();
|
||||||
|
|
||||||
protected RequestEntity mEntity = null;
|
protected RequestEntity mEntity = null;
|
||||||
@ -83,27 +83,28 @@ public class UploadRemoteFileOperation extends RemoteOperation {
|
|||||||
RemoteOperationResult result = null;
|
RemoteOperationResult result = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// / perform the upload
|
mPutMethod = new PutMethod(client.getWebdavUri() + WebdavUtils.encodePath(mRemotePath));
|
||||||
synchronized (mCancellationRequested) {
|
|
||||||
if (mCancellationRequested.get()) {
|
if (mCancellationRequested.get()) {
|
||||||
throw new OperationCancelledException();
|
// 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(
|
||||||
|
RemoteOperationResult.ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER);
|
||||||
} else {
|
} else {
|
||||||
mPutMethod = new PutMethod(client.getWebdavUri() +
|
result = new RemoteOperationResult(isSuccess(status), status,
|
||||||
WebdavUtils.encodePath(mRemotePath));
|
(mPutMethod != null ? mPutMethod.getResponseHeaders() : null));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int status = uploadFile(client);
|
|
||||||
if (mForbiddenCharsInServer){
|
|
||||||
result = new RemoteOperationResult(
|
|
||||||
RemoteOperationResult.ResultCode.INVALID_CHARACTER_DETECT_IN_SERVER);
|
|
||||||
} else {
|
|
||||||
result = new RemoteOperationResult(isSuccess(status), status,
|
|
||||||
(mPutMethod != null ? mPutMethod.getResponseHeaders() : null));
|
|
||||||
}
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
if (mCancellationRequested.get() && !(e instanceof OperationCancelledException)) {
|
if (mPutMethod != null && mPutMethod.isAborted()) {
|
||||||
result = new RemoteOperationResult(new OperationCancelledException());
|
result = new RemoteOperationResult(new OperationCancelledException());
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
result = new RemoteOperationResult(e);
|
result = new RemoteOperationResult(e);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user