Vfs: Remove VfsDefaults
authorChristian Kamm <mail@ckamm.de>
Wed, 6 Feb 2019 09:41:33 +0000 (10:41 +0100)
committerKevin Ottens <kevin.ottens@nextcloud.com>
Tue, 15 Dec 2020 09:58:40 +0000 (10:58 +0100)
That just complicated things. It's ok if Vfs is not a fully abstract
interface class.

The pinstate-in-db methods are instead provided directly on Vfs and
VfsSuffix and VfsOff use them to implement pin states.

The start() method is simply non-virtual and calls into startImpl() for
the plugin-specific startup code.

src/common/vfs.cpp
src/common/vfs.h
src/libsync/vfs/suffix/vfs_suffix.cpp
src/libsync/vfs/suffix/vfs_suffix.h

index e9d4ca081ea04c6580805b88ab0fd67128b64c2c..a40b396a70be55419d0843257b22bbace67f82d6 100644 (file)
@@ -60,17 +60,13 @@ Optional<Vfs::Mode> Vfs::modeFromString(const QString &str)
     return {};
 }
 
-VfsDefaults::VfsDefaults(QObject *parent)
-    : Vfs(parent)
-{
-}
-
-void VfsDefaults::start(const VfsSetupParams &params)
+void Vfs::start(const VfsSetupParams &params)
 {
     _setupParams = params;
+    startImpl(params);
 }
 
-bool VfsDefaults::setPinState(const QString &folderPath, PinState state)
+bool Vfs::setPinStateInDb(const QString &folderPath, PinState state)
 {
     auto path = folderPath.toUtf8();
     _setupParams.journal->internalPinStates().wipeForPathAndBelow(path);
@@ -78,13 +74,13 @@ bool VfsDefaults::setPinState(const QString &folderPath, PinState state)
     return true;
 }
 
-Optional<PinState> VfsDefaults::pinState(const QString &folderPath)
+Optional<PinState> Vfs::pinStateInDb(const QString &folderPath)
 {
     return _setupParams.journal->internalPinStates().effectiveForPath(folderPath.toUtf8());
 }
 
 VfsOff::VfsOff(QObject *parent)
-    : VfsDefaults(parent)
+    : Vfs(parent)
 {
 }
 
index fe4945b5bf629cb5626e76f0cb6a02bddfbe7b5c..e4017639e55294e285ad25f6aed0024567970ba7 100644 (file)
@@ -108,17 +108,15 @@ public:
     /// For WithSuffix modes: the suffix (including the dot)
     virtual QString fileSuffix() const = 0;
 
+    /// Access to the parameters the instance was start()ed with.
+    const VfsSetupParams &params() const { return _setupParams; }
+
 
     /** Initializes interaction with the VFS provider.
      *
-     * For example, the VFS provider might monitor files to be able to start a file
-     * hydration (download of a file's remote contents) when the user wants to open
-     * it.
-     *
-     * Usually some registration needs to be done with the backend. This function
-     * should take care of it if necessary.
+     * The plugin-specific work is done in startImpl().
      */
-    virtual void start(const VfsSetupParams &params) = 0;
+    void start(const VfsSetupParams &params);
 
     /// Stop interaction with VFS provider. Like when the client application quits.
     virtual void stop() = 0;
@@ -221,29 +219,29 @@ signals:
     void beginHydrating();
     /// Emitted when the hydration ends
     void doneHydrating();
-};
 
-class OCSYNC_EXPORT VfsDefaults : public Vfs
-{
-public:
-    explicit VfsDefaults(QObject* parent = nullptr);
-
-    // stores the params
-    void start(const VfsSetupParams &params) override;
-
-    // use the journal to back the pinstates
-    bool setPinState(const QString &folderPath, PinState state) override;
-    Optional<PinState> pinState(const QString &folderPath) override;
+protected:
+    /** Setup the plugin for the folder.
+     *
+     * For example, the VFS provider might monitor files to be able to start a file
+     * hydration (download of a file's remote contents) when the user wants to open
+     * it.
+     *
+     * Usually some registration needs to be done with the backend. This function
+     * should take care of it if necessary.
+     */
+    virtual void startImpl(const VfsSetupParams &params) = 0;
 
-    // access initial setup data
-    const VfsSetupParams &params() const { return _setupParams; }
+    // Db-backed pin state handling. Derived classes may use it to implement pin states.
+    bool setPinStateInDb(const QString &folderPath, PinState state);
+    Optional<PinState> pinStateInDb(const QString &folderPath);
 
-protected:
+    // the parameters passed to start()
     VfsSetupParams _setupParams;
 };
 
 /// Implementation of Vfs for Vfs::Off mode - does nothing
-class OCSYNC_EXPORT VfsOff : public VfsDefaults
+class OCSYNC_EXPORT VfsOff : public Vfs
 {
     Q_OBJECT
 
@@ -269,8 +267,16 @@ public:
     bool isDehydratedPlaceholder(const QString &) override { return false; }
     bool statTypeVirtualFile(csync_file_stat_t *, void *) override { return false; }
 
+    bool setPinState(const QString &folderPath, PinState state) override
+    { return setPinStateInDb(folderPath, state); }
+    Optional<PinState> pinState(const QString &folderPath) override
+    { return pinStateInDb(folderPath); }
+
 public slots:
     void fileStatusChanged(const QString &, SyncFileStatus) override {}
+
+protected:
+    void startImpl(const VfsSetupParams &) override {}
 };
 
 /// Check whether the plugin for the mode is available.
index f489aa407d8f5bf181a0dd71fef48a0f6ee774f2..ca5da6d250425c33227767baefbeabb1e4432457 100644 (file)
@@ -22,7 +22,7 @@
 namespace OCC {
 
 VfsSuffix::VfsSuffix(QObject *parent)
-    : VfsDefaults(parent)
+    : Vfs(parent)
 {
 }
 
index 4abf3920a6b42eef1e317f040bbb04af8b2f327a..45aad10b40e1573946fa89fd96e6a51b749f8103 100644 (file)
@@ -21,7 +21,7 @@
 
 namespace OCC {
 
-class VfsSuffix : public VfsDefaults
+class VfsSuffix : public Vfs
 {
     Q_OBJECT
 
@@ -47,8 +47,16 @@ public:
     bool isDehydratedPlaceholder(const QString &filePath) override;
     bool statTypeVirtualFile(csync_file_stat_t *stat, void *stat_data) override;
 
+    bool setPinState(const QString &folderPath, PinState state) override
+    { return setPinStateInDb(folderPath, state); }
+    Optional<PinState> pinState(const QString &folderPath) override
+    { return pinStateInDb(folderPath); }
+
 public slots:
     void fileStatusChanged(const QString &, SyncFileStatus) override {}
+
+protected:
+    void startImpl(const VfsSetupParams &) override {}
 };
 
 class SuffixVfsPluginFactory : public QObject, public DefaultPluginFactory<VfsSuffix>