]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- use unique_ptr for filesystem
authorArvin Schnell <aschnell@suse.de>
Fri, 25 Jul 2025 08:07:39 +0000 (10:07 +0200)
committerArvin Schnell <aschnell@suse.de>
Fri, 25 Jul 2025 08:07:39 +0000 (10:07 +0200)
17 files changed:
client/misc.cc
client/misc.h
client/snapper/cmd-modify.cc
client/snapper/cmd-rollback.cc
snapper/Bcachefs.cc
snapper/Bcachefs.h
snapper/Btrfs.cc
snapper/Btrfs.h
snapper/Ext4.cc
snapper/Ext4.h
snapper/Filesystem.cc
snapper/Filesystem.h
snapper/Lvm.cc
snapper/Lvm.h
snapper/Snapper.cc
snapper/Snapper.h
testsuite-cmp/cmp.cc

index a06e76aa49e0bb1253cfb4ccb693dac3873bcffa..61c5eb1c68a30677feee0446b56dbe53f67b8bb0 100644 (file)
@@ -168,7 +168,7 @@ username(uid_t uid)
 }
 
 
-const Filesystem*
+    unique_ptr<const Filesystem>
 get_filesystem(const ProxyConfig& config, const string& target_root)
 {
     const map<string, string>& raw = config.getAllValues();
index 5a62deb89b830842d7b64f9fe81c652b0f24ad7b..d4f4b73ad9ef118a9cec54b465089dd5e6ed6239 100644 (file)
@@ -51,8 +51,8 @@ read_configdata(const vector<string>& v, const map<string, string>& old = map<st
 string
 username(uid_t uid);
 
-const Filesystem*
-get_filesystem(const ProxyConfig& config, const string& target_root);
+    unique_ptr<const Filesystem>
+    get_filesystem(const ProxyConfig& config, const string& target_root);
 
 
 struct Differ
index f1066863223e13efb147a3fc7e20a60bad42c0b5..e9304c55b6633eef1564c9c99225be1ae1d85f7b 100644 (file)
@@ -141,7 +141,7 @@ namespace snapper
            if (set_default)
            {
                ProxyConfig config = snapper->getConfig();
-               const Filesystem* filesystem = get_filesystem(config, global_options.root());
+               unique_ptr<const Filesystem> filesystem = get_filesystem(config, global_options.root());
                filesystem->setDefault(snapshot->getNum(), report);
            }
        }
index 80447fba3dab38c512d23f230b8920d9cc6a0867..319ba66a0e59135345d50c77aa2197e96cd35de2 100644 (file)
@@ -111,7 +111,7 @@ namespace snapper
 
        ProxyConfig config = snapper->getConfig();
 
-       const Filesystem* filesystem = get_filesystem(config, global_options.root());
+       unique_ptr<const Filesystem> filesystem = get_filesystem(config, global_options.root());
        if (filesystem->fstype() != "btrfs")
        {
            cerr << _("Command 'rollback' only available for btrfs.") << endl;
@@ -222,8 +222,8 @@ namespace snapper
 
                Plugins::rollback(filesystem->snapshotDir(snapshot1->getNum()),
                                  filesystem->snapshotDir(snapshot2->getNum()), report);
-               Plugins::rollback(Plugins::Stage::POST_ACTION, subvolume, filesystem, snapshot1->getNum(),
-                                 snapshot2->getNum(), report);
+               Plugins::rollback(Plugins::Stage::POST_ACTION, subvolume, filesystem.get(),
+                                 snapshot1->getNum(), snapshot2->getNum(), report);
 
                if (print_number)
                    cout << snapshot2->getNum() << endl;
@@ -268,8 +268,8 @@ namespace snapper
 
                Plugins::rollback(filesystem->snapshotDir(previous_default->getNum()),
                                  filesystem->snapshotDir(snapshot->getNum()), report);
-               Plugins::rollback(Plugins::Stage::POST_ACTION, subvolume, filesystem, previous_default->getNum(),
-                                 snapshot->getNum(), report);
+               Plugins::rollback(Plugins::Stage::POST_ACTION, subvolume, filesystem.get(),
+                                 previous_default->getNum(), snapshot->getNum(), report);
            }
            break;
 
index c0f7cc4047aa19e9bdfee1781afe981a57574140..6ea886dca51a1b37ef4967fa0a1fffe4d9ac5e1a 100644 (file)
@@ -50,11 +50,11 @@ namespace snapper
     using namespace BcachefsUtils;
 
 
-    Filesystem*
+    std::unique_ptr<Filesystem>
     Bcachefs::create(const string& fstype, const string& subvolume, const string& root_prefix)
     {
        if (fstype == "bcachefs")
-           return new Bcachefs(subvolume, root_prefix);
+           return std::make_unique<Bcachefs>(subvolume, root_prefix);
 
        return nullptr;
     }
index 17be882d19d2dac26a0a35a2edc84f712123fe69..30696ececf8997875837498a7768d30f22d85deb 100644 (file)
@@ -34,8 +34,8 @@ namespace snapper
     {
     public:
 
-       static Filesystem* create(const string& fstype, const string& subvolume,
-                                 const string& root_prefix);
+       static std::unique_ptr<Filesystem> create(const string& fstype, const string& subvolume,
+                                                 const string& root_prefix);
 
        Bcachefs(const string& subvolume, const string& root_prefix);
 
index 71029394e497aa0350679f962e24658df3a64c94..355305cbe509f8e23b786ec418f856d307ed97af 100644 (file)
@@ -69,11 +69,11 @@ namespace snapper
     using namespace std;
 
 
-    Filesystem*
+    std::unique_ptr<Filesystem>
     Btrfs::create(const string& fstype, const string& subvolume, const string& root_prefix)
     {
        if (fstype == "btrfs")
-           return new Btrfs(subvolume, root_prefix);
+           return std::make_unique<Btrfs>(subvolume, root_prefix);
 
        return nullptr;
     }
index d67d7015007adfd5da6d8643d9eda2304caaeecf..4357ef046e66fcbb482bb21cb3151ec27bd76819 100644 (file)
@@ -39,8 +39,8 @@ namespace snapper
     {
     public:
 
-       static Filesystem* create(const string& fstype, const string& subvolume,
-                                 const string& root_prefix);
+       static std::unique_ptr<Filesystem> create(const string& fstype, const string& subvolume,
+                                                 const string& root_prefix);
 
        Btrfs(const string& subvolume, const string& root_prefix);
 
index 8b4b259cd744f7ec3cece4edf4963b59fcce5fab..7fe4a68a292dafeb3acdcba2e59cd9acc91df1f9 100644 (file)
 namespace snapper
 {
 
-    Filesystem*
+    std::unique_ptr<Filesystem>
     Ext4::create(const string& fstype, const string& subvolume, const string& root_prefix)
     {
        if (fstype == "ext4")
-           return new Ext4(subvolume, root_prefix);
+           return std::make_unique<Ext4>(subvolume, root_prefix);
 
        return nullptr;
     }
index 9aafda24ca0b0163b1d394f7beb028e68f71f9bd..62ed67e0cb6771c0b3ff6a7ce1695eeac2f9bb50 100644 (file)
@@ -34,8 +34,8 @@ namespace snapper
     {
     public:
 
-       static Filesystem* create(const string& fstype, const string& subvolume,
-                                 const string& root_prefix);
+       static std::unique_ptr<Filesystem> create(const string& fstype, const string& subvolume,
+                                                 const string& root_prefix);
 
        Ext4(const string& subvolume, const string& root_prefix);
 
index 7cb1bc04920a299e1e4bc8d90b17d1de255e6935..cf54c78df805588488695928a18aa96cc1279795 100644 (file)
@@ -94,11 +94,11 @@ namespace snapper
     }
 
 
-    Filesystem*
+    std::unique_ptr<Filesystem>
     Filesystem::create(const string& fstype, const string& subvolume, const string& root_prefix)
     {
-       typedef Filesystem* (*func_t)(const string& fstype, const string& subvolume,
-                                     const string& root_prefix);
+       typedef std::unique_ptr<Filesystem> (*func_t)(const string& fstype, const string& subvolume,
+                                                     const string& root_prefix);
 
        static const func_t funcs[] = {
 #ifdef ENABLE_BTRFS
@@ -118,7 +118,7 @@ namespace snapper
 
        for (const func_t* func = funcs; *func != nullptr; ++func)
        {
-           Filesystem* fs = (*func)(fstype, subvolume, root_prefix);
+           std::unique_ptr<Filesystem> fs = (*func)(fstype, subvolume, root_prefix);
            if (fs)
                return fs;
        }
@@ -129,13 +129,13 @@ namespace snapper
     }
 
 
-    Filesystem*
+    std::unique_ptr<Filesystem>
     Filesystem::create(const ConfigInfo& config_info, const string& root_prefix)
     {
        string fstype = "btrfs";
        config_info.get_value(KEY_FSTYPE, fstype);
 
-       Filesystem* fs = create(fstype, config_info.get_subvolume(), root_prefix);
+       std::unique_ptr<Filesystem> fs = create(fstype, config_info.get_subvolume(), root_prefix);
 
        fs->evalConfigInfo(config_info);
 
index c587a35d2a14ad3628264b9398cabbeaa6d2b75b..42ebd6effbf590104c855d50c659f9ca3022bf33 100644 (file)
@@ -28,6 +28,7 @@
 #include <string>
 #include <vector>
 #include <utility>
+#include <memory>
 
 #include "snapper/FileUtils.h"
 #include "snapper/Compare.h"
@@ -52,8 +53,9 @@ namespace snapper
            : subvolume(subvolume), root_prefix(root_prefix) {}
        virtual ~Filesystem() {}
 
-       static Filesystem* create(const string& fstype, const string& subvolume, const string& root_prefix);
-       static Filesystem* create(const ConfigInfo& config_info, const string& root_prefix);
+       static std::unique_ptr<Filesystem> create(const string& fstype, const string& subvolume,
+                                                 const string& root_prefix);
+       static std::unique_ptr<Filesystem> create(const ConfigInfo& config_info, const string& root_prefix);
 
        virtual void evalConfigInfo(const ConfigInfo& config_info) {}
 
index 79973b1610664cc3585778359e4f8340293ac9c6..c6276a7fc013f5a33f2a127dbe67bd8834f2f633 100644 (file)
@@ -53,14 +53,14 @@ namespace snapper
     using namespace std;
 
 
-    Filesystem*
+    std::unique_ptr<Filesystem>
     Lvm::create(const string& fstype, const string& subvolume, const string& root_prefix)
     {
        static const regex rx("lvm\\(([_a-z0-9]+)\\)", regex::extended);
        smatch match;
 
        if (regex_match(fstype, match, rx))
-           return new Lvm(subvolume, root_prefix, match[1]);
+           return std::make_unique<Lvm>(subvolume, root_prefix, match[1]);
 
        return nullptr;
     }
index e67009c74e648f850810ae6023a03a53deb7a72f..bb6da1c87dd3b78779a3e14a24f6b9bdf3915e38 100644 (file)
@@ -82,8 +82,8 @@ namespace snapper
     {
     public:
 
-       static Filesystem* create(const string& fstype, const string& subvolume,
-                                 const string& root_prefix);
+       static std::unique_ptr<Filesystem> create(const string& fstype, const string& subvolume,
+                                                 const string& root_prefix);
 
        Lvm(const string& subvolume, const string& root_prefix, const string& mount_type);
 
index 6d86cb6af2f538931fe26da6300ea226db6965ca..61b974cbe4d303b00db7dfcd715994be07143b98 100644 (file)
@@ -123,9 +123,6 @@ namespace snapper
                SN_CAUGHT(e);
            }
        }
-
-       delete filesystem;
-       filesystem = nullptr;
     }
 
 
@@ -343,7 +340,7 @@ namespace snapper
        unique_ptr<Filesystem> filesystem;
        try
        {
-           filesystem.reset(Filesystem::create(fstype, subvolume, ""));
+           filesystem = Filesystem::create(fstype, subvolume, "");
        }
        catch (const InvalidConfigException& e)
        {
@@ -441,7 +438,7 @@ namespace snapper
        y2mil("Snapper delete-config");
        y2mil("libsnapper version " VERSION);
 
-       unique_ptr<Snapper> snapper(new Snapper(config_name, root_prefix));
+       unique_ptr<Snapper> snapper = make_unique<Snapper>(config_name, root_prefix);
 
        Plugins::delete_config(Plugins::Stage::PRE_ACTION, snapper->subvolumeDir(), snapper->getFilesystem(),
                               report);
index df4e841fae761278c161ed862f82eba1f79773df..cc3354d79afa109124c493cad881ebad112758e3 100644 (file)
@@ -144,11 +144,11 @@ namespace snapper
 
        static bool detectFstype(const string& subvolume, string& fstype);
 
-       const Filesystem* getFilesystem() const { return filesystem; }
-
        const ConfigInfo& getConfigInfo() { return *config_info; }
        void setConfigInfo(const map<string, string>& raw);
 
+       const Filesystem* getFilesystem() const { return filesystem.get(); }
+
        void syncAcl() const;
 
        void syncFilesystem() const;
@@ -198,7 +198,7 @@ namespace snapper
 
        std::unique_ptr<ConfigInfo> config_info;
 
-       Filesystem* filesystem = nullptr;
+       std::unique_ptr<Filesystem> filesystem;
 
        vector<string> ignore_patterns;
 
index c6159a0a3e2cb611e6c9aff0f84569322e569759..d01f866c96031da524ac63cd90fdbbae2dffea72 100644 (file)
@@ -27,7 +27,7 @@ struct helper
 bool
 cmp(const string& fstype, const string& subvolume, unsigned int num1, unsigned int num2)
 {
-    Filesystem* filesystem = Filesystem::create(fstype, subvolume, "/");
+    unique_ptr<Filesystem> filesystem = Filesystem::create(fstype, subvolume, "/");
 
     SDir dir1 = filesystem->openSnapshotDir(num1);
     SDir dir2 = filesystem->openSnapshotDir(num2);