Don't detect file changes during hydration for virtual files
authorKevin Ottens <kevin.ottens@nextcloud.com>
Mon, 4 Jan 2021 15:23:47 +0000 (16:23 +0100)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Thu, 14 Jan 2021 11:57:03 +0000 (12:57 +0100)
Indeed, that file size will almost always change between the 1 byte
placeholder and the hydrated file. Only when using the CfAPI on Windows
this won't be the case since because it will expose the original size
even for placeholders.

Also worth noting: the suffix backend didn't hit that case since the
filename changes (with suffix for placeholders, without for hydrated
files).

Signed-off-by: Kevin Ottens <kevin.ottens@nextcloud.com>
src/libsync/propagatedownload.cpp

index 06c0c6337fe6358c35b8e7562009557ec44ed3cf..25d6e8e153416163f902a2b4ef06baa897a93852 100644 (file)
@@ -985,7 +985,13 @@ void PropagateDownloadFile::downloadFinished()
         previousFileExists = false;
     }
 
-    if (previousFileExists) {
+    const auto vfs = propagator()->syncOptions()._vfs;
+
+    // In the case of an hydration, this size is likely to change for placeholders
+    // (except with the cfapi backend)
+    const auto isVirtualDownload = _item->_type == ItemTypeVirtualFileDownload;
+    const auto isCfApiVfs = vfs && vfs->mode() == Vfs::WindowsCfApi;
+    if (previousFileExists && (isCfApiVfs || !isVirtualDownload)) {
         // 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
@@ -1027,7 +1033,6 @@ void PropagateDownloadFile::downloadFinished()
     if (_conflictRecord.isValid())
         propagator()->_journal->setConflictRecord(_conflictRecord);
 
-    auto vfs = propagator()->syncOptions()._vfs;
     if (vfs && vfs->mode() == Vfs::WithSuffix) {
         // If the virtual file used to have a different name and db
         // entry, remove it transfer its old pin state.