From a89b483773ba1e54d4025ef3f30a5e24149d2c3c Mon Sep 17 00:00:00 2001 From: Kevin Ottens <kevin.ottens@nextcloud.com> Date: Mon, 4 Jan 2021 16:13:29 +0100 Subject: [PATCH] Add the plumbing for a new extended attributes backend Ideally this will end up being the backend we use for both Linux and macOS but that will require work with desktop environments on the Linux side and to reverse engineering at least on xattr value on macOS. Signed-off-by: Kevin Ottens <kevin.ottens@nextcloud.com> --- src/common/vfs.cpp | 29 ++++++++++++++++++++++++++++- src/common/vfs.h | 1 + 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/common/vfs.cpp b/src/common/vfs.cpp index b1bdb5324f325..e9cf977d9113d 100644 --- a/src/common/vfs.cpp +++ b/src/common/vfs.cpp @@ -53,6 +53,8 @@ QString Vfs::modeToString(Mode mode) return QStringLiteral("suffix"); case WindowsCfApi: return QStringLiteral("wincfapi"); + case XAttr: + return QStringLiteral("xattr"); } return QStringLiteral("off"); } @@ -145,6 +147,8 @@ static QString modeToPluginName(Vfs::Mode mode) return QStringLiteral("suffix"); if (mode == Vfs::WindowsCfApi) return QStringLiteral("win"); + if (mode == Vfs::XAttr) + return QStringLiteral("xattr"); return QString(); } @@ -171,9 +175,32 @@ Vfs::Mode OCC::bestAvailableVfsMode() { if (isVfsPluginAvailable(Vfs::WindowsCfApi)) { return Vfs::WindowsCfApi; - } else if (isVfsPluginAvailable(Vfs::WithSuffix)) { + } + + if (isVfsPluginAvailable(Vfs::WithSuffix)) { return Vfs::WithSuffix; } + + // For now the "suffix" backend has still precedence over the "xattr" backend. + // Ultimately the order of those ifs will change when xattr will be more mature. + // But what does "more mature" means here? + // + // * On Mac when it properly reads and writes com.apple.LaunchServices.OpenWith + // This will require reverse engineering to see what they stuff in there. Maybe a good + // starting point: + // https://eclecticlight.co/2017/12/20/xattr-com-apple-launchservices-openwith-sets-a-custom-app-to-open-a-file/ + // + // * On Linux when our user.nextcloud.hydrate_exec is adopted by at least KDE and Gnome + // the "user.nextcloud" prefix might turn into "user.xdg" in the process since it would + // be best to have a freedesktop.org spec for it. + // When that time comes, it might still require detecting at runtime if that's indeed + // supported in the user session or even per sync folder (in case user would pick a folder + // which wouldn't support xattr for some reason) + + if (isVfsPluginAvailable(Vfs::XAttr)) { + return Vfs::XAttr; + } + return Vfs::Off; } diff --git a/src/common/vfs.h b/src/common/vfs.h index 77501a67e1c07..bb9ef619274da 100644 --- a/src/common/vfs.h +++ b/src/common/vfs.h @@ -95,6 +95,7 @@ class OCSYNC_EXPORT Vfs : public QObject Off, WithSuffix, WindowsCfApi, + XAttr, }; Q_ENUM(Mode) static QString modeToString(Mode mode);