Skip to content

Commit fc681b9

Browse files
committed
fix(vfs/windows): handle virtual directories as virtual directories
should enable proper type handling for virtual directories (i.e. on-demand populated folders) Signed-off-by: Matthieu Gallien <[email protected]>
1 parent ee48d9f commit fc681b9

File tree

11 files changed

+25
-50
lines changed

11 files changed

+25
-50
lines changed

src/common/syncjournaldb.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,6 @@ class OCSYNC_EXPORT SyncJournalDb : public QObject
167167
SelectiveSyncUndecidedList = 3,
168168
/** List of encrypted folders that will need to be removed from the blacklist when E2EE gets set up*/
169169
SelectiveSyncE2eFoldersToRemoveFromBlacklist = 4,
170-
/** The black list is the list of folders that are unselected in the on-demand VFS feature.
171-
* For the sync engine, those folders are skipped until teh user tries to access them */
172-
SelectiveSyncVfsFoldersOnDemandList = 5,
173170
};
174171
/* return the specified list from the database */
175172
QStringList getSelectiveSyncList(SelectiveSyncListType type, bool *ok);

src/common/syncjournalfilerecord.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ class OCSYNC_EXPORT SyncJournalFileRecord
5353
[[nodiscard]] QByteArray numericFileId() const;
5454
[[nodiscard]] QDateTime modDateTime() const { return Utility::qDateTimeFromTime_t(_modtime); }
5555

56-
[[nodiscard]] bool isDirectory() const { return _type == ItemTypeDirectory; }
56+
[[nodiscard]] bool isDirectory() const { return _type == ItemTypeVirtualDirectory || _type == ItemTypeDirectory; }
5757
[[nodiscard]] bool isFile() const { return _type == ItemTypeFile || _type == ItemTypeVirtualFileDehydration; }
58-
[[nodiscard]] bool isVirtualFile() const { return _type == ItemTypeVirtualFile || _type == ItemTypeVirtualFileDownload; }
58+
[[nodiscard]] bool isVirtualFile() const { return _type == ItemTypeVirtualDirectory || _type == ItemTypeVirtualFile || _type == ItemTypeVirtualFileDownload; }
5959
[[nodiscard]] QString path() const { return QString::fromUtf8(_path); }
6060
[[nodiscard]] QString e2eMangledName() const { return QString::fromUtf8(_e2eMangledName); }
6161
[[nodiscard]] bool isE2eEncrypted() const { return _e2eEncryptionStatus != EncryptionStatus::NotEncrypted; }

src/libsync/account.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1216,7 +1216,6 @@ void Account::listRemoteFolder(QPromise<OCC::PlaceholderCreateInfo> *promise, co
12161216

12171217
QObject::connect(listFolderJob, &OCC::LsColJob::finishedWithoutError, this, [promise, path, journalForFolder] () {
12181218
qCInfo(lcAccount()) << "ls col job" << path << "finished";
1219-
journalForFolder->removeSelectiveSyncLists(SyncJournalDb::SelectiveSyncVfsFoldersOnDemandList, path);
12201219
promise->finish();
12211220
});
12221221

src/libsync/discovery.cpp

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,6 @@ void ProcessDirectoryJob::process()
228228
checkAndUpdateSelectiveSyncListsForE2eeFolders(path._server + "/");
229229
}
230230

231-
if (_discoveryData->_syncOptions._vfs->mode() == Vfs::WindowsCfApi && e.serverEntry.isDirectory && !e.localEntry.isValid() && !e.dbEntry.isValid()) {
232-
checkAndAddSelectiveSyncListsForVfsOnDemandFolders(path._server + "/");
233-
}
234231
const auto isBlacklisted = _queryServer == InBlackList || _discoveryData->isInSelectiveSyncBlackList(path._original) || isEncryptedFolderButE2eIsNotSetup;
235232

236233
const auto willBeExcluded = handleExcluded(path._target, e, entries, isHidden, isBlacklisted);
@@ -554,16 +551,6 @@ void ProcessDirectoryJob::checkAndUpdateSelectiveSyncListsForE2eeFolders(const Q
554551
_discoveryData->_statedb->setSelectiveSyncList(SyncJournalDb::SelectiveSyncE2eFoldersToRemoveFromBlacklist, toRemoveFromBlacklist);
555552
}
556553

557-
void ProcessDirectoryJob::checkAndAddSelectiveSyncListsForVfsOnDemandFolders(const QString &path)
558-
{
559-
_discoveryData->_selectiveSyncVfsFoldersList = _discoveryData->_statedb->addSelectiveSyncLists(SyncJournalDb::SelectiveSyncVfsFoldersOnDemandList, path);
560-
}
561-
562-
void ProcessDirectoryJob::removeSelectiveSyncListsForVfsOnDemandFolders(const QString &path)
563-
{
564-
_discoveryData->_selectiveSyncVfsFoldersList = _discoveryData->_statedb->removeSelectiveSyncLists(SyncJournalDb::SelectiveSyncVfsFoldersOnDemandList, path);
565-
}
566-
567554
void ProcessDirectoryJob::processFile(PathTuple path,
568555
const LocalInfo &localEntry, const RemoteInfo &serverEntry,
569556
const SyncJournalFileRecord &dbEntry)
@@ -681,7 +668,17 @@ void ProcessDirectoryJob::postProcessServerNew(const SyncFileItemPtr &item,
681668
const RemoteInfo &serverEntry,
682669
const SyncJournalFileRecord &dbEntry)
683670
{
671+
const auto opts = _discoveryData->_syncOptions;
672+
684673
if (item->isDirectory()) {
674+
// Turn new remote folders into virtual folders if the option is enabled.
675+
if (!localEntry.isValid() &&
676+
opts._vfs->mode() != Vfs::Off &&
677+
_pinState != PinState::AlwaysLocal &&
678+
!FileSystem::isExcludeFile(item->_file)) {
679+
item->_type = ItemTypeVirtualDirectory;
680+
}
681+
685682
_pendingAsyncJobs++;
686683
_discoveryData->checkSelectiveSyncNewFolder(path._server,
687684
serverEntry.remotePerm,
@@ -696,14 +693,14 @@ void ProcessDirectoryJob::postProcessServerNew(const SyncFileItemPtr &item,
696693
}
697694

698695
// Turn new remote files into virtual files if the option is enabled.
699-
const auto opts = _discoveryData->_syncOptions;
700696
if (!localEntry.isValid() &&
701-
item->_type == ItemTypeFile &&
702697
opts._vfs->mode() != Vfs::Off &&
703698
_pinState != PinState::AlwaysLocal &&
704699
!FileSystem::isExcludeFile(item->_file)) {
705700

706-
item->_type = ItemTypeVirtualFile;
701+
if (item->_type == ItemTypeFile) {
702+
item->_type = ItemTypeVirtualFile;
703+
}
707704
if (isVfsWithSuffix()) {
708705
addVirtualFileSuffix(path._original);
709706
}
@@ -1135,7 +1132,8 @@ void ProcessDirectoryJob::processFileAnalyzeLocalInfo(
11351132
const auto isTypeChange = item->_instruction == CSYNC_INSTRUCTION_TYPE_CHANGE;
11361133

11371134
qCDebug(lcDisco) << "File" << item->_file << "- servermodified:" << serverModified
1138-
<< "noServerEntry:" << noServerEntry;
1135+
<< "noServerEntry:" << noServerEntry
1136+
<< "type:" << item->_type;
11391137

11401138
if (serverEntry.isValid()) {
11411139
item->_folderQuota.bytesUsed = serverEntry.folderQuota.bytesUsed;
@@ -1433,7 +1431,7 @@ void ProcessDirectoryJob::processFileAnalyzeLocalInfo(
14331431
item->_checksumHeader.clear();
14341432
item->_size = localEntry.size;
14351433
item->_modtime = localEntry.modtime;
1436-
item->_type = localEntry.isDirectory ? ItemTypeDirectory : localEntry.isVirtualFile ? ItemTypeVirtualFile : ItemTypeFile;
1434+
item->_type = localEntry.isDirectory && !localEntry.isVirtualFile ? ItemTypeDirectory : localEntry.isDirectory ? ItemTypeVirtualDirectory : localEntry.isVirtualFile ? ItemTypeVirtualFile : ItemTypeFile;
14371435
_childModified = true;
14381436

14391437
if (!localEntry.caseClashConflictingName.isEmpty()) {
@@ -1888,7 +1886,7 @@ void ProcessDirectoryJob::processFileFinalize(
18881886
Q_ASSERT(false);
18891887
}
18901888

1891-
if (recurse && _discoveryData->shouldDiscoverChildFolder(path._server)) {
1889+
if (recurse && item->_type == ItemTypeDirectory) {
18921890
auto job = new ProcessDirectoryJob(path, item, recurseQueryLocal, recurseQueryServer,
18931891
_lastSyncTimestamp, this);
18941892
job->setInsideEncryptedTree(isInsideEncryptedTree() || item->isEncrypted());

src/libsync/discovery.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,6 @@ class ProcessDirectoryJob : public QObject
148148
// check if the path is an e2e encrypted and the e2ee is not set up, and insert it into a corresponding list in the sync journal
149149
void checkAndUpdateSelectiveSyncListsForE2eeFolders(const QString &path);
150150

151-
void checkAndAddSelectiveSyncListsForVfsOnDemandFolders(const QString &path);
152-
153-
void removeSelectiveSyncListsForVfsOnDemandFolders(const QString &path);
154-
155151
/** Reconcile local/remote/db information for a single item.
156152
*
157153
* Can be a file or a directory.

src/libsync/discoveryphase.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -279,16 +279,6 @@ void DiscoveryPhase::setSelectiveSyncWhiteList(const QStringList &list)
279279
_selectiveSyncWhiteList.sort();
280280
}
281281

282-
bool DiscoveryPhase::shouldDiscoverChildFolder(const QString &path) const
283-
{
284-
if (SyncJournalDb::findPathInSelectiveSyncList(_selectiveSyncVfsFoldersList, path)) {
285-
qCInfo(lcDiscovery()) << "do not discover" << path;
286-
return false;
287-
}
288-
289-
return true;
290-
}
291-
292282
bool DiscoveryPhase::isRenamed(const QString &p) const
293283
{
294284
return _renamedItemsLocal.contains(p) || _renamedItemsRemote.contains(p);

src/libsync/discoveryphase.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,6 @@ class DiscoveryPhase : public QObject
288288
// both must contain a sorted list
289289
QStringList _selectiveSyncBlackList;
290290
QStringList _selectiveSyncWhiteList;
291-
QStringList _selectiveSyncVfsFoldersList;
292291

293292
void scheduleMoreJobs();
294293

@@ -355,8 +354,6 @@ class DiscoveryPhase : public QObject
355354
void setSelectiveSyncBlackList(const QStringList &list);
356355
void setSelectiveSyncWhiteList(const QStringList &list);
357356

358-
bool shouldDiscoverChildFolder(const QString &path) const;
359-
360357
// output
361358
QByteArray _dataFingerprint;
362359
bool _anotherSyncNeeded = false;

src/libsync/syncfileitem.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ class OWNCLOUDSYNC_EXPORT SyncFileItem
194194

195195
[[nodiscard]] bool isDirectory() const
196196
{
197-
return _type == ItemTypeDirectory;
197+
return _type == ItemTypeDirectory || _type == ItemTypeVirtualDirectory;
198198
}
199199

200200
/**

src/libsync/syncfilestatustracker.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,9 +228,9 @@ void SyncFileStatusTracker::slotAboutToPropagate(SyncFileItemVector &items)
228228

229229
for (const auto &item : std::as_const(items)) {
230230
if (item->_instruction == CSyncEnums::CSYNC_INSTRUCTION_RENAME) {
231-
qCInfo(lcStatusTracker) << "Investigating" << item->destination() << item->_status << item->_instruction << item->_direction << item->_file << item->_originalFile << item->_renameTarget;
231+
qCInfo(lcStatusTracker) << "Investigating" << item->destination() << item->_status << item->_instruction << item->_direction << item->_type << item->_file << item->_originalFile << item->_renameTarget;
232232
} else {
233-
qCInfo(lcStatusTracker) << "Investigating" << item->destination() << item->_status << item->_instruction << item->_direction;
233+
qCInfo(lcStatusTracker) << "Investigating" << item->destination() << item->_status << item->_instruction << item->_direction << item->_type;
234234
}
235235
_dirtyPaths.remove(item->destination());
236236

src/libsync/vfs/cfapi/cfapiwrapper.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1180,11 +1180,7 @@ OCC::Result<OCC::Vfs::ConvertToPlaceholderResult, QString> OCC::CfApiWrapper::co
11801180
const QByteArray &fileId = item._fileId;
11811181
const auto fileIdentity = QString::fromUtf8(fileId).toStdWString();
11821182
const auto fileIdentitySize = (fileIdentity.length() + 1) * sizeof(wchar_t);
1183-
const auto createPlaceholderFlags = item.isDirectory() ?
1184-
(item._type == ItemType::ItemTypeVirtualDirectory ?
1185-
CF_CONVERT_FLAG_MARK_IN_SYNC | CF_CONVERT_FLAG_ENABLE_ON_DEMAND_POPULATION :
1186-
CF_CONVERT_FLAG_MARK_IN_SYNC | CF_CONVERT_FLAG_ALWAYS_FULL) :
1187-
CF_CONVERT_FLAG_MARK_IN_SYNC;
1183+
const auto createPlaceholderFlags = CF_CONVERT_FLAG_MARK_IN_SYNC | (item.isDirectory() ? (item._type == ItemType::ItemTypeVirtualDirectory ? CF_CONVERT_FLAG_ENABLE_ON_DEMAND_POPULATION : CF_CONVERT_FLAG_ALWAYS_FULL) : CF_CONVERT_FLAG_MARK_IN_SYNC);
11881184

11891185
const auto result = CfConvertToPlaceholder(handleForPath(path).get(), fileIdentity.data(), sizeToDWORD(fileIdentitySize), createPlaceholderFlags, nullptr, nullptr);
11901186
Q_ASSERT(result == S_OK);

0 commit comments

Comments
 (0)