Browse Source

Merge pull request #14044 from nextcloud/saveDownloadedFile

two way sync: save updated etag
Tobias Kaminsky 5 months ago
parent
commit
a9302966c0

+ 22 - 2
app/src/main/java/com/owncloud/android/operations/SynchronizeFolderOperation.java

@@ -138,7 +138,7 @@ public class SynchronizeFolderOperation extends SyncOperation {
                 }
 
                 if (result.isSuccess()) {
-                    syncContents();
+                    syncContents(client);
                 }
             }
 
@@ -440,9 +440,29 @@ public class SynchronizeFolderOperation extends SyncOperation {
         }
     }
 
-    private void syncContents() throws OperationCancelledException {
+    private void syncContents(OwnCloudClient client) throws OperationCancelledException {
         startDirectDownloads();
         startContentSynchronizations(mFilesToSyncContents);
+        updateETag(client);
+    }
+
+    /**
+     * Updates the eTag of the local folder after a successful synchronization.
+     * This ensures that any changes to local files, which may alter the eTag, are correctly reflected.
+     *
+     * @param client the OwnCloudClient instance used to execute remote operations.
+     */
+    private void updateETag(OwnCloudClient client) {
+        ReadFolderRemoteOperation operation = new ReadFolderRemoteOperation(mRemotePath);
+        final var result = operation.execute(client);
+
+        if (result.getData().get(0) instanceof RemoteFile remoteFile) {
+            String eTag = remoteFile.getEtag();
+            mLocalFolder.setEtag(eTag);
+
+            final FileDataStorageManager storageManager = getStorageManager();
+            storageManager.saveFile(mLocalFolder);
+        }
     }
 
     private void startDirectDownloads() {