Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/desktop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Kamm <mail@ckamm.de>2019-04-03 14:32:05 +0300
committerKevin Ottens <kevin.ottens@nextcloud.com>2020-12-15 12:58:46 +0300
commit590db285419ab3eeae8f7f87542fa1642ec4fad3 (patch)
treef87abe1deb7376e159bc8a3d55b7dfa521bc6a5e /src/gui/folder.cpp
parent2738f110f230a425c7bec0a0b068bb3c50802134 (diff)
Vfs: Clear up relationship between _type and pin state
The pin state is a per-item attribute that has an effect on _type: AlwaysLocal dehydrated files will be marked for hydration and OnlineOnly hydrated files will be marked for dehydration. Where exactly this effect materializes depends on how the pin states are stored. If they're stored in the db (suffix) the dbEntry._type is changed during the discovery. If the pin state is stored in the filesystem, the localEntry._type must be adjusted by the plugin's stat callback. This patch makes pin states behave more consistently between plugins. Previously with suffix-vfs pin states only had an effect on new remote files. Now the effect of pinning or unpinning files or directories is as documented and similar to other plugins.
Diffstat (limited to 'src/gui/folder.cpp')
-rw-r--r--src/gui/folder.cpp71
1 files changed, 27 insertions, 44 deletions
diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp
index 633cc9209..8ca941f28 100644
--- a/src/gui/folder.cpp
+++ b/src/gui/folder.cpp
@@ -590,58 +590,36 @@ void Folder::slotWatchedPathChanged(const QString &path)
scheduleThisFolderSoon();
}
-void Folder::downloadVirtualFile(const QString &_relativepath)
+void Folder::implicitlyHydrateFile(const QString &relativepath)
{
- qCInfo(lcFolder) << "Download virtual file: " << _relativepath;
- auto relativepath = _relativepath.toUtf8();
+ qCInfo(lcFolder) << "Implicitly hydrate virtual file:" << relativepath;
// Set in the database that we should download the file
SyncJournalFileRecord record;
- _journal.getFileRecord(relativepath, &record);
- if (!record.isValid() && !relativepath.isEmpty())
+ _journal.getFileRecord(relativepath.toUtf8(), &record);
+ if (!record.isValid()) {
+ qCInfo(lcFolder) << "Did not find file in db";
return;
- if (record._type == ItemTypeVirtualFile) {
- record._type = ItemTypeVirtualFileDownload;
- _journal.setFileRecord(record);
- // Make sure we go over that file during the discovery even if
- // no actual remote discovery would be necessary
- _journal.schedulePathForRemoteDiscovery(relativepath);
- } else if (record._type == ItemTypeDirectory || relativepath.isEmpty()) {
- _journal.markVirtualFileForDownloadRecursively(relativepath);
- } else {
- qCWarning(lcFolder) << "Invalid existing record " << record._type << " for file " << _relativepath;
}
-
- // Schedule a sync (Folder man will start the sync in a few ms)
- slotScheduleThisFolder();
-}
-
-void Folder::dehydrateFile(const QString &_relativepath)
-{
- qCInfo(lcFolder) << "Dehydrating file: " << _relativepath;
- auto relativepath = _relativepath.toUtf8();
-
- auto markForDehydration = [&](SyncJournalFileRecord rec) {
- if (rec._type != ItemTypeFile)
- return;
- rec._type = ItemTypeVirtualFileDehydration;
- _journal.setFileRecord(rec);
- _localDiscoveryTracker->addTouchedPath(relativepath);
- };
-
- SyncJournalFileRecord record;
- _journal.getFileRecord(relativepath, &record);
- if (!record.isValid() && !relativepath.isEmpty())
+ if (!record.isVirtualFile()) {
+ qCInfo(lcFolder) << "The file is not virtual";
return;
- if (record._type == ItemTypeFile) {
- markForDehydration(record);
- } else if (record._type == ItemTypeDirectory || relativepath.isEmpty()) {
- _journal.getFilesBelowPath(relativepath, markForDehydration);
- } else {
- qCWarning(lcFolder) << "Invalid existing record " << record._type << " for file " << _relativepath;
+ }
+ record._type = ItemTypeVirtualFileDownload;
+ _journal.setFileRecord(record);
+
+ // Change the file's pin state if it's contradictory to being hydrated
+ // (suffix-virtual file's pin state is stored at the hydrated path)
+ QString pinPath = relativepath;
+ if (_vfs->mode() == Vfs::WithSuffix && pinPath.endsWith(_vfs->fileSuffix()))
+ pinPath.chop(_vfs->fileSuffix().size());
+ const auto pin = _vfs->pinState(pinPath);
+ if (pin && *pin == PinState::OnlineOnly) {
+ _vfs->setPinState(pinPath, PinState::Unspecified);
}
- // Schedule a sync (Folder man will start the sync in a few ms)
+ // Add to local discovery
+ schedulePathForLocalDiscovery(relativepath);
slotScheduleThisFolder();
}
@@ -684,7 +662,12 @@ bool Folder::newFilesAreVirtual() const
void Folder::setNewFilesAreVirtual(bool enabled)
{
- _vfs->setPinState(QString(), enabled ? PinState::OnlineOnly : PinState::AlwaysLocal);
+ const auto newPin = enabled ? PinState::OnlineOnly : PinState::AlwaysLocal;
+ _vfs->setPinState(QString(), newPin);
+
+ // We don't actually need discovery, but it's important to recurse
+ // into all folders, so the changes can be applied.
+ slotNextSyncFullLocalDiscovery();
}
bool Folder::supportsSelectiveSync() const