X-Git-Url: http://git.linex4red.de/pub/Android/ownCloud.git/blobdiff_plain/b0ab3ce0872d2702e82b5979dddaa5a897be340b..8361540852ec87b51c85937e0f326a83e19cd8ad:/src/com/owncloud/android/operations/DownloadFileOperation.java diff --git a/src/com/owncloud/android/operations/DownloadFileOperation.java b/src/com/owncloud/android/operations/DownloadFileOperation.java index a35a0163..d752b3cc 100644 --- a/src/com/owncloud/android/operations/DownloadFileOperation.java +++ b/src/com/owncloud/android/operations/DownloadFileOperation.java @@ -22,19 +22,21 @@ import java.io.BufferedInputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; +import java.util.Date; import java.util.HashSet; import java.util.Iterator; import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; +import org.apache.commons.httpclient.Header; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.methods.GetMethod; import org.apache.http.HttpStatus; import com.owncloud.android.datamodel.OCFile; -import com.owncloud.android.files.services.FileDownloader; import com.owncloud.android.operations.RemoteOperation; import com.owncloud.android.operations.RemoteOperationResult; +import com.owncloud.android.utils.FileStorageUtils; import eu.alefzero.webdav.OnDatatransferProgressListener; import eu.alefzero.webdav.WebdavClient; @@ -50,12 +52,13 @@ import android.webkit.MimeTypeMap; */ public class DownloadFileOperation extends RemoteOperation { - private static final String TAG = DownloadFileOperation.class.getCanonicalName(); + private static final String TAG = DownloadFileOperation.class.getSimpleName(); - private Account mAccount = null; + private Account mAccount; private OCFile mFile; private Set mDataTransferListeners = new HashSet(); private final AtomicBoolean mCancellationRequested = new AtomicBoolean(false); + private long mModificationTimestamp = 0; public DownloadFileOperation(Account account, OCFile file) { @@ -78,11 +81,15 @@ public class DownloadFileOperation extends RemoteOperation { } public String getSavePath() { - return FileDownloader.getSavePath(mAccount.name) + mFile.getRemotePath(); + String path = mFile.getStoragePath(); // re-downloads should be done over the original file + if (path != null && path.length() > 0) { + return path; + } + return FileStorageUtils.getDefaultSavePathFor(mAccount.name, mFile); } public String getTmpPath() { - return FileDownloader.getTemporalPath(mAccount.name) + mFile.getRemotePath(); + return FileStorageUtils.getTemporalPath(mAccount.name) + mFile.getRemotePath(); } public String getRemotePath() { @@ -110,6 +117,10 @@ public class DownloadFileOperation extends RemoteOperation { return mFile.getFileLength(); } + public long getModificationTimestamp() { + return (mModificationTimestamp > 0) ? mModificationTimestamp : mFile.getModificationTimestamp(); + } + public void addDatatransferProgressListener (OnDatatransferProgressListener listener) { mDataTransferListeners.add(listener); @@ -119,7 +130,7 @@ public class DownloadFileOperation extends RemoteOperation { protected RemoteOperationResult run(WebdavClient client) { RemoteOperationResult result = null; File newFile = null; - boolean moved = false; + boolean moved = true; /// download will be performed to a temporal file, then moved to the final location File tmpFile = new File(getTmpPath()); @@ -134,7 +145,7 @@ public class DownloadFileOperation extends RemoteOperation { moved = tmpFile.renameTo(newFile); } if (!moved) - result = new RemoteOperationResult(RemoteOperationResult.ResultCode.STORAGE_ERROR_MOVING_FROM_TMP); + result = new RemoteOperationResult(RemoteOperationResult.ResultCode.LOCAL_STORAGE_NOT_MOVED); else result = new RemoteOperationResult(isSuccess(status), status); Log.i(TAG, "Download of " + mFile.getRemotePath() + " to " + getSavePath() + ": " + result.getLogMessage()); @@ -185,6 +196,11 @@ public class DownloadFileOperation extends RemoteOperation { } } savedFile = true; + Header modificationTime = get.getResponseHeader("Last-Modified"); + if (modificationTime != null) { + Date d = WebdavUtils.parseResponseDate((String) modificationTime.getValue()); + mModificationTimestamp = (d != null) ? d.getTime() : 0; + } } else { client.exhaustResponse(get.getResponseBodyAsStream());