Discovery: Files can have dehydrate/download actions
authorChristian Kamm <mail@ckamm.de>
Tue, 22 Jan 2019 12:32:28 +0000 (13:32 +0100)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:58:38 +0000 (10:58 +0100)
This will be used in conjunction with vfs plugins that detect whether a
file has a pending hydration/dehydration through independent means and
communicate that to the discovery through local file type.

src/csync/csync.h
src/libsync/discovery.cpp
src/libsync/discoveryphase.h

index 759bced4aa44f491184812928d7cbbb43e319b5d..13125cc8e97e49ce10fd60c9903215fd0c85e7b7 100644 (file)
@@ -136,8 +136,23 @@ enum ItemType {
     ItemTypeSoftLink = 1,
     ItemTypeDirectory = 2,
     ItemTypeSkip = 3,
+
+    /** The file is a dehydrated placeholder, meaning data isn't available locally */
     ItemTypeVirtualFile = 4,
+
+    /** A ItemTypeVirtualFile that wants to be hydrated.
+     *
+     * Actions may put this in the db as a request to a future sync.
+     * For some vfs plugins the placeholder files on disk may be marked for
+     * dehydration (like with a file attribute) and then the local discovery
+     * will return this item type.
+     */
     ItemTypeVirtualFileDownload = 5,
+
+    /** A ItemTypeFile that wants to be dehydrated.
+     *
+     * May exist in db or local files, similar to ItemTypeVirtualFileDownload.
+     */
     ItemTypeVirtualFileDehydration = 6,
 };
 
index d4bf83249b307ba31ec4b79b16b5a1d9bedc8398..04e50292c0c78a95b16b3fe775af013fc5293e04 100644 (file)
@@ -281,7 +281,8 @@ void ProcessDirectoryJob::processFile(PathTuple path,
                               << " | checksum: " << dbEntry._checksumHeader << "//" << serverEntry.checksumHeader
                               << " | perm: " << dbEntry._remotePerm << "//" << serverEntry.remotePerm
                               << " | fileid: " << dbEntry._fileId << "//" << serverEntry.fileId
-                              << " | inode: " << dbEntry._inode << "/" << localEntry.inode << "/";
+                              << " | inode: " << dbEntry._inode << "/" << localEntry.inode << "/"
+                              << " | type: " << dbEntry._type << "/" << localEntry.type << "/" << (serverEntry.isDirectory ? ItemTypeDirectory : ItemTypeFile);
 
     if (_discoveryData->isRenamed(path._original)) {
         qCDebug(lcDisco) << "Ignoring renamed";
@@ -325,7 +326,9 @@ void ProcessDirectoryJob::processFile(PathTuple path,
     // server-side nothing has changed
     // NOTE: Normally setting the VirtualFileDownload flag means that local and
     // remote will be rediscovered. This is just a fallback.
-    if (_queryServer == ParentNotChanged && dbEntry._type == ItemTypeVirtualFileDownload) {
+    if (_queryServer == ParentNotChanged
+        && (dbEntry._type == ItemTypeVirtualFileDownload
+            || localEntry.type == ItemTypeVirtualFileDownload)) {
         item->_direction = SyncFileItem::Down;
         item->_instruction = CSYNC_INSTRUCTION_NEW;
         item->_type = ItemTypeVirtualFileDownload;
@@ -371,7 +374,7 @@ void ProcessDirectoryJob::processFileAnalyzeRemoteInfo(
             item->_direction = SyncFileItem::Down;
             item->_modtime = serverEntry.modtime;
             item->_size = serverEntry.size;
-        } else if (dbEntry._type == ItemTypeVirtualFileDownload) {
+        } else if (dbEntry._type == ItemTypeVirtualFileDownload || localEntry.type == ItemTypeVirtualFileDownload) {
             item->_direction = SyncFileItem::Down;
             item->_instruction = CSYNC_INSTRUCTION_NEW;
             item->_type = ItemTypeVirtualFileDownload;
@@ -706,7 +709,7 @@ void ProcessDirectoryJob::processFileAnalyzeLocalInfo(
             if (noServerEntry) {
                 item->_instruction = CSYNC_INSTRUCTION_REMOVE;
                 item->_direction = SyncFileItem::Down;
-            } else if (dbEntry._type == ItemTypeVirtualFileDehydration) {
+            } else if (dbEntry._type == ItemTypeVirtualFileDehydration || localEntry.type == ItemTypeVirtualFileDehydration) {
                 item->_direction = SyncFileItem::Down;
                 item->_instruction = CSYNC_INSTRUCTION_NEW;
                 item->_type = ItemTypeVirtualFileDehydration;
@@ -1340,7 +1343,8 @@ bool ProcessDirectoryJob::runLocalQuery()
         i.isDirectory = dirent->type == ItemTypeDirectory;
         i.isHidden = dirent->is_hidden;
         i.isSymLink = dirent->type == ItemTypeSoftLink;
-        i.isVirtualFile = dirent->type == ItemTypeVirtualFile;
+        i.isVirtualFile = dirent->type == ItemTypeVirtualFile || dirent->type == ItemTypeVirtualFileDownload;
+        i.type = dirent->type;
         _localNormalQueryEntries.push_back(i);
     }
     csync_vio_local_closedir(dh);
index 32c9b1332d1002687d825cd2ef31746968b00d65..6c6d7ff9f7b2fc121aae9ffd49a75eae795c76e7 100644 (file)
@@ -68,6 +68,7 @@ struct LocalInfo
     time_t modtime = 0;
     int64_t size = 0;
     uint64_t inode = 0;
+    ItemType type = ItemTypeSkip;
     bool isDirectory = false;
     bool isHidden = false;
     bool isVirtualFile = false;