PropagateDownload: Conflict-rename later
authorChristian Kamm <mail@ckamm.de>
Tue, 5 Feb 2019 10:42:15 +0000 (11:42 +0100)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:58:39 +0000 (10:58 +0100)
The block of code that propagated attributes etc from the previously
existing file was placed *after* the block that renamed the previously
existing file to a conflict name. That meant the propagation didn't work
in the conflict case.

src/libsync/propagatedownload.cpp

index d926542b45e1cf6b169cfd37c9ed0dbf5e3315b7..da9d8435e9293adde173a0bcb29399d6a02e702b 100644 (file)
@@ -947,16 +947,6 @@ void PropagateDownloadFile::downloadFinished()
         return;
     }
 
-    bool isConflict = _item->_instruction == CSYNC_INSTRUCTION_CONFLICT
-        && (QFileInfo(fn).isDir() || !FileSystem::fileEquals(fn, _tmpFile.fileName()));
-    if (isConflict) {
-        QString error;
-        if (!propagator()->createConflict(_item, _associatedComposite, &error)) {
-            done(SyncFileItem::SoftError, error);
-            return;
-        }
-    }
-
     FileSystem::setModTime(_tmpFile.fileName(), _item->_modtime);
     // We need to fetch the time again because some file systems such as FAT have worse than a second
     // Accuracy, and we really need the time from the file system. (#3103)
@@ -970,6 +960,9 @@ void PropagateDownloadFile::downloadFinished()
         }
         preserveGroupOwnership(_tmpFile.fileName(), existingFile);
 
+        // Make the file a hydrated placeholder if possible
+        propagator()->syncOptions()._vfs->convertToPlaceholder(_tmpFile.fileName(), *_item, fn);
+
         // Check whether the existing file has changed since the discovery
         // phase by comparing size and mtime to the previous values. This
         // is necessary to avoid overwriting user changes that happened between
@@ -986,8 +979,15 @@ void PropagateDownloadFile::downloadFinished()
     // Apply the remote permissions
     FileSystem::setFileReadOnlyWeak(_tmpFile.fileName(), !_item->_remotePerm.isNull() && !_item->_remotePerm.hasPermission(RemotePermissions::CanWrite));
 
-    // Make the file a hydrated placeholder if possible
-    propagator()->syncOptions()._vfs->convertToPlaceholder(_tmpFile.fileName(), *_item, fn);
+    bool isConflict = _item->_instruction == CSYNC_INSTRUCTION_CONFLICT
+        && (QFileInfo(fn).isDir() || !FileSystem::fileEquals(fn, _tmpFile.fileName()));
+    if (isConflict) {
+        QString error;
+        if (!propagator()->createConflict(_item, _associatedComposite, &error)) {
+            done(SyncFileItem::SoftError, error);
+            return;
+        }
+    }
 
     QString error;
     emit propagator()->touchedFile(fn);