New Disco Algo: Handle spurious virtual files
authorOlivier Goffart <ogoffart@woboq.com>
Tue, 21 Aug 2018 11:08:09 +0000 (13:08 +0200)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:58:04 +0000 (10:58 +0100)
Port commit 0b9049e6ff01401883184d29d22dd4a30c092da8
for issue #6718

src/libsync/discovery.cpp

index 4d877485a694d74f976178d38cde90b7254bf446..7331cc0bb057d03e645ede8d5455dc9e25256894 100644 (file)
@@ -636,8 +636,32 @@ void ProcessDirectoryJob::processFile(PathTuple path,
         item->_inode = localEntry.inode;
         bool typeChange = dbEntry.isValid() && localEntry.isDirectory != (dbEntry._type == ItemTypeDirectory);
         if (localEntry.isVirtualFile) {
-            if (item->_type != ItemTypeVirtualFileDownload)
+            if (!dbEntry.isValid()) {
+                // Remove the spurious file if it looks like a placeholder file
+                // (we know placeholder files contain " ")
+                if (localEntry.size <= 1) {
+                    QString filename = _discoveryData->_localDir + _currentFolder._local + localEntry.name;
+                    QFile::remove(filename);
+                    qCWarning(lcDisco) << "Wiping virtual file without db entry for" << filename;
+                } else {
+                    qCWarning(lcDisco) << "Virtual file without db entry for" <<  _currentFolder._local << localEntry.name
+                                        << "but looks odd, keeping";
+                }
+            } else if (dbEntry._type == ItemTypeFile) {
+                // If we find what looks to be a spurious "abc.owncloud" the base file "abc"
+                // might have been renamed to that. Make sure that the base file is not
+                // deleted from the server.
+                if (dbEntry._modtime == localEntry.modtime && dbEntry._fileSize == localEntry.size) {
+                    qCInfo(lcDisco) << "Base file was renamed to virtual file:" << item->_file;
+                    Q_ASSERT(item->_file.endsWith(_discoveryData->_syncOptions._virtualFileSuffix));
+                    item->_direction = SyncFileItem::Down;
+                    item->_instruction = CSYNC_INSTRUCTION_NEW;
+                    item->_type = ItemTypeVirtualFile;
+                }
+            } else if (item->_type != ItemTypeVirtualFileDownload) {
                 item->_type = ItemTypeVirtualFile;
+            }
+
             if (_queryServer != ParentNotChanged && !serverEntry.isValid()) {
                 item->_instruction = CSYNC_INSTRUCTION_REMOVE;
                 item->_direction = SyncFileItem::Down;