X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/27112bd200e1bf30897ae94507afeeb272e267ec..e4bc3bdadc47c01e88dd1de94a4666d3753ee90e:/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 1a7938f3..afdd3cbe 100644 --- a/src/com/owncloud/android/operations/UploadFileOperation.java +++ b/src/com/owncloud/android/operations/UploadFileOperation.java @@ -46,13 +46,16 @@ import android.util.Log; */ public class UploadFileOperation extends RemoteOperation { - private static final String TAG = UploadFileOperation.class.getCanonicalName(); + private static final String TAG = UploadFileOperation.class.getSimpleName(); private Account mAccount; private OCFile mFile; + private OCFile mOldFile; private String mRemotePath = null; private boolean mIsInstant = false; + private boolean mRemoteFolderToBeCreated = false; private boolean mForceOverwrite = false; + private boolean mWasRenamed = false; PutMethod mPutMethod = null; private Set mDataTransferListeners = new HashSet(); private final AtomicBoolean mCancellationRequested = new AtomicBoolean(false); @@ -86,13 +89,16 @@ public class UploadFileOperation extends RemoteOperation { return mFile; } + public OCFile getOldFile() { + return mOldFile; + } + public String getStoragePath() { return mFile.getStoragePath(); } public String getRemotePath() { - //return mFile.getRemotePath(); // DON'T MAKE THIS ; the remotePath used can be different to mFile.getRemotePath() if mForceOverwrite is 'false'; see run(...) - return mRemotePath; + return mFile.getRemotePath(); } public String getMimeType() { @@ -102,11 +108,22 @@ public class UploadFileOperation extends RemoteOperation { public boolean isInstant() { return mIsInstant; } + + public boolean isRemoteFolderToBeCreated() { + return mRemoteFolderToBeCreated; + } + public void setRemoteFolderToBeCreated() { + mRemoteFolderToBeCreated = true; + } + public boolean getForceOverwrite() { return mForceOverwrite; } - + + public boolean wasRenamed() { + return mWasRenamed; + } public Set getDataTransferListeners() { return mDataTransferListeners; @@ -124,7 +141,11 @@ public class UploadFileOperation extends RemoteOperation { try { /// rename the file to upload, if necessary if (!mForceOverwrite) { - mRemotePath = getAvailableRemotePath(client, mRemotePath); + String remotePath = getAvailableRemotePath(client, mRemotePath); + mWasRenamed = !remotePath.equals(mRemotePath); + if (mWasRenamed) { + createNewOCFile(remotePath); + } } /// perform the upload @@ -154,6 +175,24 @@ public class UploadFileOperation extends RemoteOperation { } + private void createNewOCFile(String newRemotePath) { + // a new OCFile instance must be created for a new remote path + OCFile newFile = new OCFile(newRemotePath); + newFile.setCreationTimestamp(mFile.getCreationTimestamp()); + newFile.setFileLength(mFile.getFileLength()); + newFile.setMimetype(mFile.getMimetype()); + newFile.setModificationTimestamp(mFile.getModificationTimestamp()); + // newFile.setEtag(mFile.getEtag()) + newFile.setKeepInSync(mFile.keepInSync()); + newFile.setLastSyncDateForProperties(mFile.getLastSyncDateForProperties()); + newFile.setLastSyncDateForData(mFile.getLastSyncDateForData()); + newFile.setStoragePath(mFile.getStoragePath()); + newFile.setParentId(mFile.getParentId()); + mOldFile = mFile; + mFile = newFile; + } + + public boolean isSuccess(int status) { return ((status == HttpStatus.SC_OK || status == HttpStatus.SC_CREATED || status == HttpStatus.SC_NO_CONTENT)); } @@ -221,4 +260,5 @@ public class UploadFileOperation extends RemoteOperation { } } + }