vfs: SocketAPI actions adjust pin state of directories #6815
authorChristian Kamm <mail@ckamm.de>
Tue, 27 Nov 2018 09:31:13 +0000 (10:31 +0100)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:58:29 +0000 (10:58 +0100)
Downloading a folder also sets its pin state; releasing a folder sets
its pin state.

src/gui/socketapi.cpp

index de0923180009417b9aef1b7be3719d1b30bc6f2e..27681d1f80559a0ac276e000c2ba65209cee4401 100644 (file)
@@ -695,10 +695,20 @@ void SocketApi::command_DOWNLOAD_VIRTUAL_FILE(const QString &filesArg, SocketLis
         auto record = data.journalRecord();
         if (!record.isValid())
             continue;
-        if (record._type != ItemTypeVirtualFile && !QFileInfo(file).isDir())
+        bool isDir = QFileInfo(data.localPath).isDir();
+        if (record._type != ItemTypeVirtualFile && !isDir)
             continue;
-        if (data.folder)
-            data.folder->downloadVirtualFile(data.folderRelativePath);
+        if (!data.folder)
+            continue;
+
+        // For directories, update their pin state so new files are available locally too
+        if (isDir) {
+            data.folder->journalDb()->setPinStateForPath(
+                    data.folderRelativePath.toUtf8(), PinState::AlwaysLocal);
+        }
+
+        // Trigger the recursive download
+        data.folder->downloadVirtualFile(data.folderRelativePath);
     }
 }
 
@@ -709,8 +719,17 @@ void SocketApi::command_REPLACE_VIRTUAL_FILE(const QString &filesArg, SocketList
 
     for (const auto &file : files) {
         auto data = FileData::get(file);
-        if (data.folder)
-            data.folder->dehydrateFile(data.folderRelativePath);
+        if (!data.folder)
+            continue;
+
+        // For directories, update the pin state so new files are available online-only
+        if (QFileInfo(data.localPath).isDir()) {
+            data.folder->journalDb()->setPinStateForPath(
+                    data.folderRelativePath.toUtf8(), PinState::OnlineOnly);
+        }
+
+        // Trigger recursive dehydration
+        data.folder->dehydrateFile(data.folderRelativePath);
     }
 }
 
@@ -1004,10 +1023,10 @@ void SocketApi::command_GET_MENU_ITEMS(const QString &argument, OCC::SocketListe
             }
         }
         if (hasVirtualFile || (hasDir && syncFolder->supportsVirtualFiles()))
-            listener->sendMessage(QLatin1String("MENU_ITEM:DOWNLOAD_VIRTUAL_FILE::") + tr("Download file(s)", "", files.size()));
+            listener->sendMessage(QLatin1String("MENU_ITEM:DOWNLOAD_VIRTUAL_FILE::") + tr("Keep updated locally, download if necessary", "", files.size()));
 
         if ((hasNormalFiles || hasDir) && syncFolder->supportsVirtualFiles())
-            listener->sendMessage(QLatin1String("MENU_ITEM:REPLACE_VIRTUAL_FILE::") + tr("Replace file(s) by virtual file", "", files.size()));
+            listener->sendMessage(QLatin1String("MENU_ITEM:REPLACE_VIRTUAL_FILE::") + tr("Make available on demand, clear local data", "", files.size()));
     }
 
     listener->sendMessage(QString("GET_MENU_ITEMS:END"));