Add the plumbing for a new extended attributes backend
authorKevin Ottens <kevin.ottens@nextcloud.com>
Mon, 4 Jan 2021 15:13:29 +0000 (16:13 +0100)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Thu, 14 Jan 2021 11:57:02 +0000 (12:57 +0100)
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
src/common/vfs.h

index b1bdb5324f325f553502449486a94d6cdc01ed06..e9cf977d9113da86b3bfb2b4aa97926709976719 100644 (file)
@@ -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;
 }
 
index 77501a67e1c079bb9883689790f94140a8f94fca..bb9ef619274daa53220471f699c361d2ee6c574e 100644 (file)
@@ -95,6 +95,7 @@ public:
         Off,
         WithSuffix,
         WindowsCfApi,
+        XAttr,
     };
     Q_ENUM(Mode)
     static QString modeToString(Mode mode);