Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ public RemoteOperationResult run(NextcloudClient client) {
return result;
}


private int downloadFile(NextcloudClient client, File targetFile) throws IOException, OperationCancelledException, CreateLocalFileException {
int status;
boolean savedFile = false;
getMethod = new GetMethod(client.getFilesDavUri(remotePath), false);
getMethod.addRequestHeader("Accept-Encoding", "identity");
Iterator<OnDatatransferProgressListener> it;

FileOutputStream fos = null;
Expand All @@ -102,7 +102,7 @@ private int downloadFile(NextcloudClient client, File targetFile) throws IOExcep
long transferred = 0;

String contentLength = getMethod.getResponseHeader("Content-Length");
long totalToTransfer = (contentLength != null) ? Long.parseLong(contentLength) : 0;
long totalToTransfer = (contentLength != null) ? Long.parseLong(contentLength) : -1;

byte[] bytes = new byte[4096];
int readResult;
Expand All @@ -122,16 +122,13 @@ private int downloadFile(NextcloudClient client, File targetFile) throws IOExcep
}
}
}

// Check if the file is completed
// if transfer-encoding: chunked we cannot check if the file is complete
String transferEncodingHeader = getMethod.getResponseHeader("Transfer-Encoding");
boolean transferEncoding = false;
boolean transferEncoding = "chunked".equalsIgnoreCase(transferEncodingHeader);

if (transferEncodingHeader != null) {
transferEncoding = "chunked".equals(transferEncodingHeader);
}

if (transferred == totalToTransfer || transferEncoding) {
if (transferred == totalToTransfer || transferEncoding) {
savedFile = true;
String modificationTime = getMethod.getResponseHeader("Last-Modified");
if (modificationTime == null) {
Expand All @@ -145,7 +142,7 @@ private int downloadFile(NextcloudClient client, File targetFile) throws IOExcep
}

eTag = WebdavUtils.getEtagFromResponse(getMethod);
if (eTag.length() == 0) {
if (eTag.isEmpty()) {
Log_OC.e(TAG, "Could not read eTag from response downloading " + remotePath);
}

Expand All @@ -154,9 +151,14 @@ private int downloadFile(NextcloudClient client, File targetFile) throws IOExcep
} finally {
if (fos != null) fos.close();
if (!savedFile && targetFile.exists()) {
targetFile.delete();
boolean isDeleted = targetFile.delete();
if (isDeleted) {
Log_OC.i(TAG, "target file is deleted");
}
}
getMethod.releaseConnection(); // let the connection available for other methods

// let the connection available for other methods
getMethod.releaseConnection();
}
return status;
}
Expand Down
Loading