use of com.owncloud.android.lib.resources.files.DownloadRemoteFileOperation in project android by owncloud.
the class DownloadFileOperation method run.
@Override
protected RemoteOperationResult run(OwnCloudClient client) {
RemoteOperationResult result;
File newFile;
boolean moved;
/// download will be performed to a temporal file, then moved to the final location
File tmpFile = new File(getTmpPath());
String tmpFolder = getTmpFolder();
/// perform the download
synchronized (mCancellationRequested) {
if (mCancellationRequested.get()) {
return new RemoteOperationResult(new OperationCancelledException());
}
}
mDownloadOperation = new DownloadRemoteFileOperation(mFile.getRemotePath(), tmpFolder);
Iterator<OnDatatransferProgressListener> listener = mDataTransferListeners.iterator();
while (listener.hasNext()) {
mDownloadOperation.addDatatransferProgressListener(listener.next());
}
result = mDownloadOperation.execute(client);
if (result.isSuccess()) {
mModificationTimestamp = mDownloadOperation.getModificationTimestamp();
mEtag = mDownloadOperation.getEtag();
if (FileStorageUtils.getUsableSpace(mAccount.name) < tmpFile.length()) {
Log_OC.w(TAG, "Not enough space to copy " + tmpFile.getAbsolutePath());
}
newFile = new File(getSavePath());
Log_OC.d(TAG, "Save path: " + newFile.getAbsolutePath());
File parent = newFile.getParentFile();
boolean created = parent.mkdirs();
Log_OC.d(TAG, "Creation of parent folder " + parent.getAbsolutePath() + " succeeded: " + created);
Log_OC.d(TAG, "Parent folder " + parent.getAbsolutePath() + " exists: " + parent.exists());
Log_OC.d(TAG, "Parent folder " + parent.getAbsolutePath() + " is directory: " + parent.isDirectory());
moved = tmpFile.renameTo(newFile);
Log_OC.d(TAG, "New file " + newFile.getAbsolutePath() + " exists: " + newFile.exists());
Log_OC.d(TAG, "New file " + newFile.getAbsolutePath() + " is directory: " + newFile.isDirectory());
if (!moved) {
result = new RemoteOperationResult(RemoteOperationResult.ResultCode.LOCAL_STORAGE_NOT_MOVED);
}
}
Log_OC.i(TAG, "Download of " + mFile.getRemotePath() + " to " + getSavePath() + ": " + result.getLogMessage());
return result;
}
Aggregations