Skip to content

Commit

Permalink
Merge pull request nextcloud#7308 from hochwasser/patch-1
Browse files Browse the repository at this point in the history
Get last modified time from SAF files put it on the uploaded file
Signed-off-by: thelittlefireman <thelittlefireman@users.noreply.github.com>
  • Loading branch information
AndyScherzinger authored Nov 16, 2020
2 parents b468964 + 3b34d73 commit 8bec385
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
import android.accounts.Account;
import android.content.ContentResolver;
import android.content.Context;
import android.database.Cursor;
import android.net.Uri;
import android.os.AsyncTask;
import android.provider.DocumentsContract;
import android.widget.Toast;

import com.owncloud.android.R;
Expand Down Expand Up @@ -143,6 +145,19 @@ protected ResultCode doInBackground(Object[] params) {
currentUri = uris[i];
currentRemotePath = remotePaths[i];

long lastModified = 0;
try (Cursor cursor = leakedContentResolver.query(currentUri,
null,
null,
null,
null)) {
if (cursor != null && cursor.moveToFirst()) {
lastModified = cursor.getLong(
cursor.getColumnIndexOrThrow(
DocumentsContract.Document.COLUMN_LAST_MODIFIED));
}
}

fullTempPath = FileStorageUtils.getTemporalPath(account.name) + currentRemotePath;
inputStream = leakedContentResolver.openInputStream(currentUri);
File cacheFile = new File(fullTempPath);
Expand All @@ -158,6 +173,18 @@ protected ResultCode doInBackground(Object[] params) {
while ((count = inputStream.read(buffer)) > 0) {
outputStream.write(buffer, 0, count);
}

if (lastModified != 0) {
try {
if (!cacheFile.setLastModified(lastModified)) {
Log_OC.w(TAG, "Could not change mtime of cacheFile");
}
} catch (SecurityException e) {
Log_OC.e(TAG, "Not enough permissions to change mtime of cacheFile", e);
} catch (IllegalArgumentException e) {
Log_OC.e(TAG, "Could not change mtime of cacheFile, mtime is negativ: "+lastModified, e);
}
}

requestUpload(
account,
Expand Down

0 comments on commit 8bec385

Please sign in to comment.