소스 검색

Get last modified time from SAF files put it on the uploaded file

Get the modified time from SAF files and set it on the cache file.
The uploaded then sets the correct modified time ob the server.
This fixes #5660
hochwasser 4 년 전
부모
커밋
e36d1e5c41
1개의 변경된 파일27개의 추가작업 그리고 1개의 파일을 삭제
  1. 27 1
      src/main/java/com/owncloud/android/ui/asynctasks/CopyAndUploadContentUrisTask.java

+ 27 - 1
src/main/java/com/owncloud/android/ui/asynctasks/CopyAndUploadContentUrisTask.java

@@ -143,6 +143,19 @@ public class CopyAndUploadContentUrisTask extends AsyncTask<Object, Void, Result
                 currentUri = uris[i];
                 currentRemotePath = remotePaths[i];
 
+                long lastModified = 0;
+                try (Cursor cursor = leakedContentResolver.query(currentUri,
+                                                                 null,
+                                                                 null,
+                                                                 null,
+                                                                 null)) {
+                    if (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);
@@ -158,7 +171,20 @@ public class CopyAndUploadContentUrisTask extends AsyncTask<Object, Void, Result
                 while ((count = inputStream.read(buffer)) > 0) {
                     outputStream.write(buffer, 0, count);
                 }
-
+                
+                try {
+                    if(lastModified != 0 ){
+                        
+                        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,
                     fullTempPath,