Skip to content

Commit 5cc28ff

Browse files
committed
fix(openvfs): fix loading of the plug-in and make it default on linux
Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
1 parent 702ac22 commit 5cc28ff

9 files changed

Lines changed: 71 additions & 10 deletions

File tree

.clang-format

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ InsertBraces: true
3939

4040
AllowShortEnumsOnASingleLine: false
4141

42-
EnumTrailingComma: ETC_Insert
42+
EnumTrailingComma: Insert
4343

4444
# CrlInstruction *a;
4545
PointerAlignment: Right

src/common/vfs.cpp

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ Optional<Vfs::Mode> Vfs::modeFromString(const QString &str)
5252
return WithSuffix;
5353
} else if (str == QLatin1String("wincfapi")) {
5454
return WindowsCfApi;
55+
} else if (str == QLatin1String("xattr")) {
56+
return XAttr;
57+
} else if (str == QLatin1String("openvfs")) {
58+
return OpenVFS;
5559
}
5660
return {};
5761
}
@@ -136,13 +140,20 @@ VfsOff::~VfsOff() = default;
136140

137141
static QString modeToPluginName(Vfs::Mode mode)
138142
{
139-
if (mode == Vfs::WithSuffix)
143+
switch (mode) {
144+
case Vfs::Off:
145+
return {};
146+
case Vfs::WithSuffix:
140147
return QStringLiteral("suffix");
141-
if (mode == Vfs::WindowsCfApi)
148+
case Vfs::WindowsCfApi:
142149
return QStringLiteral("cfapi");
143-
if (mode == Vfs::XAttr)
150+
case Vfs::XAttr:
144151
return QStringLiteral("xattr");
145-
return QString();
152+
case Vfs::OpenVFS:
153+
return QStringLiteral("openvfs");
154+
}
155+
156+
return {};
146157
}
147158

148159
Q_LOGGING_CATEGORY(lcPlugin, "plugins", QtInfoMsg)
@@ -197,6 +208,10 @@ Vfs::Mode OCC::bestAvailableVfsMode()
197208
return Vfs::WindowsCfApi;
198209
}
199210

211+
if (isVfsPluginAvailable(Vfs::OpenVFS)) {
212+
return Vfs::OpenVFS;
213+
}
214+
200215
if (isVfsPluginAvailable(Vfs::WithSuffix)) {
201216
return Vfs::WithSuffix;
202217
}
@@ -267,3 +282,8 @@ std::unique_ptr<Vfs> OCC::createVfsFromPlugin(Vfs::Mode mode)
267282
qCInfo(lcPlugin) << "Created VFS instance from plugin" << pluginPath;
268283
return vfs;
269284
}
285+
286+
const FileSystem::Path &VfsSetupParams::root() const
287+
{
288+
return rootPath;
289+
}

src/common/vfs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ struct OCSYNC_EXPORT VfsSetupParams
5656
* Always ends with /.
5757
*/
5858
QString filesystemPath;
59+
FileSystem::Path rootPath;
5960

6061
// Folder display name in Windows Explorer
6162
QString displayName;

src/gui/application.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,10 @@ Application::Application(int &argc, char **argv)
416416
qCInfo(lcApplication) << "VFS suffix plugin is available";
417417
}
418418

419+
if (isVfsPluginAvailable(Vfs::OpenVFS)) {
420+
qCInfo(lcApplication) << "VFS openvfs linux plugin is available";
421+
}
422+
419423
_theme->setSystrayUseMonoIcons(ConfigFile().monoIcons());
420424
connect(this, &Application::systemPaletteChanged,
421425
_theme, &Theme::systemPaletteHasChanged);

src/gui/folder.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ void Folder::startVfs()
580580
qCDebug(lcFolder) << "Display name for VFS folder will be:" << displayName;
581581
VfsSetupParams vfsParams;
582582
vfsParams.filesystemPath = path();
583+
vfsParams.rootPath = FileSystem::Path{path()};
583584
vfsParams.displayName = displayName;
584585
vfsParams.alias = alias();
585586
vfsParams.navigationPaneClsid = navigationPaneClsid().toString();

src/libsync/syncfileitem.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,10 @@ class OWNCLOUDSYNC_EXPORT SyncFileItem
348348
};
349349
FolderQuota _folderQuota;
350350

351-
QString _localName;
352-
353-
QString localName() const { return _localName; }
354-
void setLocalName(const QString &newName) { _localName = newName; }
351+
QString localName() const
352+
{
353+
return _file;
354+
}
355355
};
356356

357357
inline bool operator<(const SyncFileItemPtr &item1, const SyncFileItemPtr &item2)

src/libsync/theme.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1019,7 +1019,7 @@ QPixmap Theme::createColorAwarePixmap(const QString &name)
10191019
bool Theme::showVirtualFilesOption() const
10201020
{
10211021
const auto vfsMode = bestAvailableVfsMode();
1022-
return ConfigFile().showExperimentalOptions() || vfsMode == Vfs::WindowsCfApi;
1022+
return ConfigFile().showExperimentalOptions() || vfsMode == Vfs::WindowsCfApi || vfsMode == Vfs::OpenVFS;
10231023
}
10241024

10251025
bool Theme::enforceVirtualFilesSyncFolder() const

src/libsync/vfs/openvfs/vfs_openvfs.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,40 @@ bool OpenVFS::isDehydratedPlaceholder(const QString &filePath)
529529
return false;
530530
}
531531

532+
bool OpenVFS::statTypeVirtualFile(csync_file_stat_t *stat, void *statData)
533+
{
534+
if (stat->type == ItemTypeDirectory) {
535+
return false;
536+
}
537+
538+
const auto parentPath = static_cast<QByteArray *>(statData);
539+
Q_ASSERT(!parentPath->endsWith('/'));
540+
Q_ASSERT(!stat->path.startsWith('/'));
541+
542+
const auto path = QByteArray(*parentPath + '/' + stat->path);
543+
const auto pin = [=, this] {
544+
const auto absolutePath = QString::fromUtf8(path);
545+
Q_ASSERT(absolutePath.startsWith(params().filesystemPath.toUtf8()));
546+
const auto folderPath = absolutePath.mid(params().filesystemPath.length());
547+
return pinState(folderPath);
548+
}();
549+
550+
if (stat->type == ItemTypeFile) {
551+
const auto attribs = placeHolderAttributes(path);
552+
if (attribs.state == ::OpenVFS::Constants::States::DeHydrated) {
553+
stat->type = ItemTypeVirtualFile;
554+
if (attribs.pinState == convertPinState(PinState::AlwaysLocal)) {
555+
stat->type = ItemTypeVirtualFileDownload;
556+
}
557+
} else {
558+
if (attribs.pinState == convertPinState(PinState::OnlineOnly)) {
559+
stat->type = ItemTypeVirtualFileDehydration;
560+
}
561+
}
562+
}
563+
return false;
564+
}
565+
532566
// LocalInfo OpenVFS::statTypeVirtualFile(const std::filesystem::directory_entry &path, ItemType type)
533567
// {
534568
// if (type == ItemTypeFile) {

test/syncenginetestutils.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1315,6 +1315,7 @@ void FakeFolder::switchToVfs(QSharedPointer<OCC::Vfs> vfs)
13151315

13161316
OCC::VfsSetupParams vfsParams;
13171317
vfsParams.filesystemPath = localPath();
1318+
vfsParams.rootPath = OCC::FileSystem::Path{localPath()};
13181319
vfsParams.remotePath = _remotePath + u"/"_s;
13191320
vfsParams.account = _account;
13201321
vfsParams.journal = _journalDb.get();

0 commit comments

Comments
 (0)