projects
/
pub
/
Android
/
ownCloud.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
[tx-robot] updated from transifex
[pub/Android/ownCloud.git]
/
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
42ca738
..
ee9f7c8
100644
(file)
--- 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,
*
* 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,10
+29,9
@@
import java.io.OutputStream;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
-import java.util.concurrent.CancellationException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicBoolean;
-import org.apache.commons.httpclient.
methods.PutMethod
;
+import org.apache.commons.httpclient.
HttpStatus
;
import org.apache.commons.httpclient.methods.RequestEntity;
import android.accounts.Account;
import org.apache.commons.httpclient.methods.RequestEntity;
import android.accounts.Account;
@@
-56,8
+58,6
@@
import com.owncloud.android.utils.UriUtils;
/**
* Remote operation performing the upload of a file to an ownCloud server
/**
* Remote operation performing the upload of a file to an ownCloud server
- *
- * @author David A. Velasco
*/
public class UploadFileOperation extends RemoteOperation {
*/
public class UploadFileOperation extends RemoteOperation {
@@
-75,7
+75,6
@@
public class UploadFileOperation extends RemoteOperation {
private boolean mWasRenamed = false;
private String mOriginalFileName = null;
private String mOriginalStoragePath = null;
private boolean mWasRenamed = false;
private String mOriginalFileName = null;
private String mOriginalStoragePath = null;
- PutMethod mPutMethod = null;
private Set<OnDatatransferProgressListener> mDataTransferListeners = new HashSet<OnDatatransferProgressListener>();
private AtomicBoolean mCancellationRequested = new AtomicBoolean(false);
private Context mContext;
private Set<OnDatatransferProgressListener> mDataTransferListeners = new HashSet<OnDatatransferProgressListener>();
private AtomicBoolean mCancellationRequested = new AtomicBoolean(false);
private Context mContext;
@@
-93,7
+92,8
@@
public class UploadFileOperation extends RemoteOperation {
int localBehaviour,
Context context) {
if (account == null)
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) {
if (file == null)
throw new IllegalArgumentException("Illegal NULL file in UploadFileOperation creation");
if (file.getStoragePath() == null || file.getStoragePath().length() <= 0) {
@@
-258,7
+258,6
@@
public class UploadFileOperation extends RemoteOperation {
(nRead = in.read(data, 0, data.length)) != -1) {
out.write(data, 0, nRead);
}
(nRead = in.read(data, 0, data.length)) != -1) {
out.write(data, 0, nRead);
}
-
out.flush();
} else {
out.flush();
} else {
@@
-278,6
+277,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;
} catch (Exception e) {
result = new RemoteOperationResult(ResultCode.LOCAL_STORAGE_NOT_COPIED);
return result;
@@
-300,25
+304,28
@@
public class UploadFileOperation extends RemoteOperation {
}
}
}
}
}
}
- localCopyPassed =
true
;
+ localCopyPassed =
(result == null)
;
/// perform the upload
if ( mChunked &&
(new File(mFile.getStoragePath())).length() >
ChunkedUploadRemoteFileOperation.CHUNK_SIZE ) {
mUploadOperation = new ChunkedUploadRemoteFileOperation(mFile.getStoragePath(),
/// perform the upload
if ( mChunked &&
(new File(mFile.getStoragePath())).length() >
ChunkedUploadRemoteFileOperation.CHUNK_SIZE ) {
mUploadOperation = new ChunkedUploadRemoteFileOperation(mFile.getStoragePath(),
- mFile.getRemotePath(), mFile.getMimetype());
+ mFile.getRemotePath(), mFile.getMimetype()
, mFile.getEtagInConflict()
);
} else {
mUploadOperation = new UploadRemoteFileOperation(mFile.getStoragePath(),
} else {
mUploadOperation = new UploadRemoteFileOperation(mFile.getStoragePath(),
- mFile.getRemotePath(), mFile.getMimetype());
+ mFile.getRemotePath(), mFile.getMimetype()
, mFile.getEtagInConflict()
);
}
Iterator <OnDatatransferProgressListener> listener = mDataTransferListeners.iterator();
while (listener.hasNext()) {
mUploadOperation.addDatatransferProgressListener(listener.next());
}
}
Iterator <OnDatatransferProgressListener> listener = mDataTransferListeners.iterator();
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()) {
/// move local temporal file or original file to its corresponding
// location in the ownCloud local folder
if (result.isSuccess()) {
@@
-329,8
+336,8
@@
public class UploadFileOperation extends RemoteOperation {
mFile.setStoragePath(expectedPath);
File fileToMove = null;
if (temporalFile != null) { // FileUploader.LOCAL_BEHAVIOUR_COPY
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;
fileToMove = temporalFile;
} else { // FileUploader.LOCAL_BEHAVIOUR_MOVE
fileToMove = originalFile;
@@
-352,16
+359,13
@@
public class UploadFileOperation extends RemoteOperation {
}
}
}
}
}
}
+
+ } else if (result.getHttpCode() == HttpStatus.SC_PRECONDITION_FAILED ) {
+ result = new RemoteOperationResult(ResultCode.SYNC_CONFLICT);
}
} catch (Exception e) {
}
} 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)) {
} finally {
if (temporalFile != null && !originalFile.equals(temporalFile)) {
@@
-401,8
+405,8
@@
public class UploadFileOperation extends RemoteOperation {
newFile.setModificationTimestamp(mFile.getModificationTimestamp());
newFile.setModificationTimestampAtLastSyncForData(
mFile.getModificationTimestampAtLastSyncForData());
newFile.setModificationTimestamp(mFile.getModificationTimestamp());
newFile.setModificationTimestampAtLastSyncForData(
mFile.getModificationTimestampAtLastSyncForData());
- // newFile.setEtag(mFile.getEtag())
- newFile.set
KeepInSync(mFile.keepInSync
());
+ newFile.setEtag(mFile.getEtag());
+ newFile.set
Favorite(mFile.isFavorite
());
newFile.setLastSyncDateForProperties(mFile.getLastSyncDateForProperties());
newFile.setLastSyncDateForData(mFile.getLastSyncDateForData());
newFile.setStoragePath(mFile.getStoragePath());
newFile.setLastSyncDateForProperties(mFile.getLastSyncDateForProperties());
newFile.setLastSyncDateForData(mFile.getLastSyncDateForData());
newFile.setStoragePath(mFile.getStoragePath());