]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- use defines for common values 911/head
authorArvin Schnell <aschnell@suse.de>
Tue, 4 Jun 2024 07:12:51 +0000 (09:12 +0200)
committerArvin Schnell <aschnell@suse.de>
Tue, 4 Jun 2024 07:12:51 +0000 (09:12 +0200)
client/installation-helper.cc
snapper/Bcachefs.cc
snapper/Btrfs.cc
snapper/Compare.cc
snapper/Ext4.cc
snapper/Lvm.cc
snapper/Snapper.cc
snapper/SnapperDefines.h

index 33b21e0ea7c4d91f9c842e3a37e57d60ffc165c6..1fdba8c5b6d45240f59537a2355a79a070cb569d 100644 (file)
@@ -149,11 +149,11 @@ step2(const string& device, const string& root_prefix, const string& default_sub
     string subvol_option = default_subvolume_name;
     if (!subvol_option.empty())
        subvol_option += "/";
-    subvol_option += ".snapshots";
+    subvol_option += SNAPSHOTS_NAME;
 
-    mkdir((root_prefix + "/.snapshots").c_str(), 0777);
+    mkdir((root_prefix + "/" SNAPSHOTS_NAME).c_str(), 0777);
 
-    SDir s_dir(root_prefix + "/.snapshots");
+    SDir s_dir(root_prefix + "/" SNAPSHOTS_NAME);
     if (!s_dir.mount(device, "btrfs", 0, "subvol=" + subvol_option))
     {
        cerr << "mounting .snapshots failed" << endl;
index 19e5bf3cf343687afd938b4da629b26f5fb62ed5..ab9548509d05b0182f40deab2c103fd0cd16a4d2 100644 (file)
@@ -34,6 +34,7 @@
 #include "snapper/File.h"
 #include "snapper/Snapper.h"
 #include "snapper/SnapperTmpl.h"
+#include "snapper/SnapperDefines.h"
 
 #include "snapper/Acls.h"
 #include "snapper/Exception.h"
@@ -72,7 +73,7 @@ namespace snapper
 
        try
        {
-           create_subvolume(subvolume_dir.fd(), ".snapshots");
+           create_subvolume(subvolume_dir.fd(), SNAPSHOTS_NAME);
        }
        catch (const runtime_error_with_errno& e)
        {
@@ -90,7 +91,7 @@ namespace snapper
            }
        }
 
-       SFile x(subvolume_dir, ".snapshots");
+       SFile x(subvolume_dir, SNAPSHOTS_NAME);
 
 #ifdef ENABLE_SELINUX
        try
@@ -119,7 +120,7 @@ namespace snapper
 
        try
        {
-           delete_subvolume(subvolume_dir.fd(), ".snapshots");
+           delete_subvolume(subvolume_dir.fd(), SNAPSHOTS_NAME);
        }
        catch (const runtime_error& e)
        {
@@ -132,8 +133,8 @@ namespace snapper
     string
     Bcachefs::snapshotDir(unsigned int num) const
     {
-       return (subvolume == "/" ? "" : subvolume) + "/.snapshots/" + decString(num) +
-           "/snapshot";
+       return (subvolume == "/" ? "" : subvolume) + "/" SNAPSHOTS_NAME "/" + decString(num) +
+           "/" SNAPSHOT_NAME;
     }
 
 
@@ -161,7 +162,7 @@ namespace snapper
     Bcachefs::openInfosDir() const
     {
        SDir subvolume_dir = openSubvolumeDir();
-       SDir infos_dir(subvolume_dir, ".snapshots");
+       SDir infos_dir(subvolume_dir, SNAPSHOTS_NAME);
 
        struct stat stat;
        if (infos_dir.stat(&stat) != 0)
@@ -200,7 +201,7 @@ namespace snapper
     Bcachefs::openSnapshotDir(unsigned int num) const
     {
        SDir info_dir = openInfoDir(num);
-       SDir snapshot_dir(info_dir, "snapshot");
+       SDir snapshot_dir(info_dir, SNAPSHOT_NAME);
 
        return snapshot_dir;
     }
@@ -218,9 +219,9 @@ namespace snapper
            try
            {
                if (empty)
-                   create_subvolume(info_dir.fd(), "snapshot");
+                   create_subvolume(info_dir.fd(), SNAPSHOT_NAME);
                else
-                   create_snapshot(subvolume_dir.fd(), subvolume, info_dir.fd(), "snapshot", read_only);
+                   create_snapshot(subvolume_dir.fd(), subvolume, info_dir.fd(), SNAPSHOT_NAME, read_only);
            }
            catch (const runtime_error& e)
            {
@@ -235,7 +236,7 @@ namespace snapper
 
            try
            {
-               create_snapshot(snapshot_dir.fd(), subvolume, info_dir.fd(), "snapshot", read_only);
+               create_snapshot(snapshot_dir.fd(), subvolume, info_dir.fd(), SNAPSHOT_NAME, read_only);
            }
            catch (const runtime_error& e)
            {
@@ -253,7 +254,7 @@ namespace snapper
 
        try
        {
-           delete_subvolume(info_dir.fd(), "snapshot");
+           delete_subvolume(info_dir.fd(), SNAPSHOT_NAME);
        }
        catch (const runtime_error& e)
        {
@@ -306,7 +307,7 @@ namespace snapper
            SDir info_dir = openInfoDir(num);
 
            struct stat stat;
-           int r = info_dir.stat("snapshot", &stat, AT_SYMLINK_NOFOLLOW);
+           int r = info_dir.stat(SNAPSHOT_NAME, &stat, AT_SYMLINK_NOFOLLOW);
            return r == 0 && is_subvolume(stat);
        }
        catch (const IOErrorException& e)
index 32511adf74d2068a23a682efc9989bd61724a1f9..8ebdcf6002834b70fe32d9e0e97cd96f8bd856b2 100644 (file)
@@ -133,7 +133,7 @@ namespace snapper
 
        try
        {
-           create_subvolume(subvolume_dir.fd(), ".snapshots");
+           create_subvolume(subvolume_dir.fd(), SNAPSHOTS_NAME);
        }
        catch (const runtime_error_with_errno& e)
        {
@@ -151,7 +151,7 @@ namespace snapper
            }
        }
 
-       SFile x(subvolume_dir, ".snapshots");
+       SFile x(subvolume_dir, SNAPSHOTS_NAME);
 #ifdef ENABLE_SELINUX
        try
        {
@@ -179,7 +179,7 @@ namespace snapper
 #ifdef ENABLE_ROLLBACK
        if (subvolume == "/")
        {
-           subvolume_dir.umount(".snapshots");
+           subvolume_dir.umount(SNAPSHOTS_NAME);
 
            removeFromFstab();
        }
@@ -187,7 +187,7 @@ namespace snapper
 
        try
        {
-           delete_subvolume(subvolume_dir.fd(), ".snapshots");
+           delete_subvolume(subvolume_dir.fd(), SNAPSHOTS_NAME);
        }
        catch (const runtime_error& e)
        {
@@ -238,8 +238,8 @@ namespace snapper
     string
     Btrfs::snapshotDir(unsigned int num) const
     {
-       return (subvolume == "/" ? "" : subvolume) + "/.snapshots/" + decString(num) +
-           "/snapshot";
+       return (subvolume == "/" ? "" : subvolume) + "/" SNAPSHOTS_NAME "/" + decString(num) +
+           "/" SNAPSHOT_NAME;
     }
 
 
@@ -267,7 +267,7 @@ namespace snapper
     Btrfs::openInfosDir() const
     {
        SDir subvolume_dir = openSubvolumeDir();
-       SDir infos_dir(subvolume_dir, ".snapshots");
+       SDir infos_dir(subvolume_dir, SNAPSHOTS_NAME);
 
        struct stat stat;
        if (infos_dir.stat(&stat) != 0)
@@ -306,7 +306,7 @@ namespace snapper
     Btrfs::openSnapshotDir(unsigned int num) const
     {
        SDir info_dir = openInfoDir(num);
-       SDir snapshot_dir(info_dir, "snapshot");
+       SDir snapshot_dir(info_dir, SNAPSHOT_NAME);
 
        return snapshot_dir;
     }
@@ -331,9 +331,9 @@ namespace snapper
            try
            {
                if (empty)
-                   create_subvolume(info_dir.fd(), "snapshot");
+                   create_subvolume(info_dir.fd(), SNAPSHOT_NAME);
                else
-                   create_snapshot(subvolume_dir.fd(), info_dir.fd(), "snapshot", read_only,
+                   create_snapshot(subvolume_dir.fd(), info_dir.fd(), SNAPSHOT_NAME, read_only,
                                    quota ? qgroup : no_qgroup);
            }
            catch (const runtime_error& e)
@@ -349,7 +349,7 @@ namespace snapper
 
            try
            {
-               create_snapshot(snapshot_dir.fd(), info_dir.fd(), "snapshot", read_only,
+               create_snapshot(snapshot_dir.fd(), info_dir.fd(), SNAPSHOT_NAME, read_only,
                                quota ? qgroup : no_qgroup);
            }
            catch (const runtime_error& e)
@@ -387,7 +387,7 @@ namespace snapper
 
        try
        {
-           create_snapshot(tmp_mount_dir.fd(), info_dir.fd(), "snapshot", read_only,
+           create_snapshot(tmp_mount_dir.fd(), info_dir.fd(), SNAPSHOT_NAME, read_only,
                            quota ? qgroup : no_qgroup);
        }
        catch (const runtime_error& e)
@@ -419,7 +419,7 @@ namespace snapper
            subvolid_t subvolid = get_id(openSnapshotDir(num).fd());
 #endif
 
-           delete_subvolume(info_dir.fd(), "snapshot");
+           delete_subvolume(info_dir.fd(), SNAPSHOT_NAME);
 
 #if defined(HAVE_LIBBTRFS) || defined(HAVE_LIBBTRFSUTIL)
            deleted_subvolids.push_back(subvolid);
@@ -427,7 +427,7 @@ namespace snapper
        }
        catch (const runtime_error& e)
        {
-           y2err("delete snapshot " << info_dir.fullname() << "/snapshot failed, " << e.what());
+           y2err("delete snapshot " << info_dir.fullname() << "/" SNAPSHOT_NAME " failed, " << e.what());
            SN_THROW(DeleteSnapshotFailedException());
        }
     }
@@ -476,7 +476,7 @@ namespace snapper
            SDir info_dir = openInfoDir(num);
 
            struct stat stat;
-           int r = info_dir.stat("snapshot", &stat, AT_SYMLINK_NOFOLLOW);
+           int r = info_dir.stat(SNAPSHOT_NAME, &stat, AT_SYMLINK_NOFOLLOW);
            return r == 0 && is_subvolume(stat);
        }
        catch (const IOErrorException& e)
@@ -1614,7 +1614,7 @@ namespace snapper
        string subvol_option = default_subvolume_name;
        if (!subvol_option.empty())
            subvol_option += "/";
-       subvol_option += ".snapshots";
+       subvol_option += SNAPSHOTS_NAME;
 
        MntTable mnt_table(root_prefix);
        mnt_table.parse_fstab();
@@ -1627,7 +1627,7 @@ namespace snapper
        if (!snapshots)
            throw runtime_error("mnt_copy_fs failed");
 
-       mnt_fs_set_target(snapshots, "/.snapshots");
+       mnt_fs_set_target(snapshots, "/" SNAPSHOTS_NAME);
 
        char* options = mnt_fs_strdup_options(snapshots);
        mnt_optstr_remove_option(&options, "defaults");
@@ -1646,7 +1646,7 @@ namespace snapper
        MntTable mnt_table(root_prefix);
        mnt_table.parse_fstab();
 
-       string mountpoint = (subvolume == "/" ? "" : subvolume) +  "/.snapshots";
+       string mountpoint = (subvolume == "/" ? "" : subvolume) +  "/" SNAPSHOTS_NAME;
        libmnt_fs* snapshots = mnt_table.find_target(mountpoint, MNT_ITER_FORWARD);
        if (!snapshots)
            return;
index 9c072c8767a886f09739ca5bd5655276886495db..d713b9b27aa03cdf6500f016a48657683639c729 100644 (file)
@@ -39,6 +39,7 @@
 #include "snapper/Exception.h"
 #include "snapper/XAttributes.h"
 #include "snapper/Acls.h"
+#include "snapper/SnapperDefines.h"
 
 
 namespace snapper
@@ -259,7 +260,7 @@ namespace snapper
     bool
     filter(const string& name)
     {
-       if (name == "/.snapshots")
+       if (name == "/" SNAPSHOTS_NAME)
            return true;
 
        return false;
index 6585bf61b10866fee1349fe99655f38de03c1442..dfb541c484f7bcb200ec47f24777fa44f5062566 100644 (file)
@@ -88,10 +88,10 @@ namespace snapper
     void
     Ext4::createConfig() const
     {
-       int r1 = mkdir((subvolume + "/.snapshots").c_str(), 0700);
+       int r1 = mkdir((subvolume + "/" SNAPSHOTS_NAME).c_str(), 0700);
        if (r1 == 0)
        {
-           SystemCmd cmd1({ CHATTRBIN, "+x", subvolume + "/.snapshots" });
+           SystemCmd cmd1({ CHATTRBIN, "+x", subvolume + "/" SNAPSHOTS_NAME });
            if (cmd1.retcode() != 0)
                throw CreateConfigFailedException("chattr failed");
        }
@@ -101,10 +101,10 @@ namespace snapper
            throw CreateConfigFailedException("mkdir failed");
        }
 
-       int r2 = mkdir((subvolume + "/.snapshots/.info").c_str(), 0700);
+       int r2 = mkdir((subvolume + "/" SNAPSHOTS_NAME "/.info").c_str(), 0700);
        if (r2 == 0)
        {
-           SystemCmd cmd2({ CHATTRBIN, "-x", subvolume + "/.snapshots/.info" });
+           SystemCmd cmd2({ CHATTRBIN, "-x", subvolume + "/" SNAPSHOTS_NAME "/.info" });
            if (cmd2.retcode() != 0)
                throw CreateConfigFailedException("chattr failed");
        }
@@ -119,14 +119,14 @@ namespace snapper
     void
     Ext4::deleteConfig() const
     {
-       int r1 = rmdir((subvolume + "/.snapshots/.info").c_str());
+       int r1 = rmdir((subvolume + "/" SNAPSHOTS_NAME "/.info").c_str());
        if (r1 != 0)
        {
            y2err("rmdir failed errno:" << errno << " (" << stringerror(errno) << ")");
            throw DeleteConfigFailedException("rmdir failed");
        }
 
-       int r2 = rmdir((subvolume + "/.snapshots").c_str());
+       int r2 = rmdir((subvolume + "/" SNAPSHOTS_NAME).c_str());
        if (r2 != 0)
        {
            y2err("rmdir failed errno:" << errno << " (" << stringerror(errno) << ")");
@@ -145,7 +145,7 @@ namespace snapper
     string
     Ext4::snapshotFile(unsigned int num) const
     {
-       return (subvolume == "/" ? "" : subvolume) + "/.snapshots/" + decString(num);
+       return (subvolume == "/" ? "" : subvolume) + "/" SNAPSHOTS_NAME "/" + decString(num);
     }
 
 
index 9caf71db0e1f5ce14004efdc1b08f48901915186..3d6fcd5ac17f447ed324c1f05a58c6ebb7d61d26 100644 (file)
@@ -109,7 +109,7 @@ namespace snapper
     void
     Lvm::createLvmConfig(const SDir& subvolume_dir, int mode) const
     {
-       int r1 = subvolume_dir.mkdir(".snapshots", mode);
+       int r1 = subvolume_dir.mkdir(SNAPSHOTS_NAME, mode);
        if (r1 != 0 && errno != EEXIST)
        {
            y2err("mkdir failed errno:" << errno << " (" << strerror(errno) << ")");
@@ -133,7 +133,7 @@ namespace snapper
 
            try
            {
-               string path(subvolume_dir.fullname() + "/.snapshots");
+               string path(subvolume_dir.fullname() + "/" SNAPSHOTS_NAME);
 
                con = selabel_handle->selabel_lookup(path, mode);
                if (con)
@@ -182,7 +182,7 @@ namespace snapper
     {
        SDir subvolume_dir = openSubvolumeDir();
 
-       int r1 = subvolume_dir.unlink(".snapshots", AT_REMOVEDIR);
+       int r1 = subvolume_dir.unlink(SNAPSHOTS_NAME, AT_REMOVEDIR);
        if (r1 != 0)
        {
            y2err("rmdir failed errno:" << errno << " (" << strerror(errno) << ")");
@@ -194,8 +194,8 @@ namespace snapper
     string
     Lvm::snapshotDir(unsigned int num) const
     {
-       return (subvolume == "/" ? "" : subvolume) + "/.snapshots/" + decString(num) +
-           "/snapshot";
+       return (subvolume == "/" ? "" : subvolume) + "/" SNAPSHOTS_NAME "/" + decString(num) +
+           "/" SNAPSHOT_NAME;
     }
 
 
@@ -203,7 +203,7 @@ namespace snapper
     Lvm::openInfosDir() const
     {
        SDir subvolume_dir = openSubvolumeDir();
-       SDir infos_dir(subvolume_dir, ".snapshots");
+       SDir infos_dir(subvolume_dir, SNAPSHOTS_NAME);
 
        struct stat stat;
        if (infos_dir.stat(&stat) != 0)
@@ -237,7 +237,7 @@ namespace snapper
     Lvm::openSnapshotDir(unsigned int num) const
     {
        SDir info_dir = openInfoDir(num);
-       SDir snapshot_dir(info_dir, "snapshot");
+       SDir snapshot_dir(info_dir, SNAPSHOT_NAME);
 
        return snapshot_dir;
     }
@@ -258,7 +258,7 @@ namespace snapper
            SN_THROW(UnsupportedException());
 
        SDir info_dir = openInfoDir(num);
-       int r1 = info_dir.mkdir("snapshot", 0755);
+       int r1 = info_dir.mkdir(SNAPSHOT_NAME, 0755);
        if (r1 != 0 && errno != EEXIST)
        {
            y2err("mkdir failed errno:" << errno << " (" << strerror(errno) << ")");
@@ -293,7 +293,7 @@ namespace snapper
        }
 
        SDir info_dir = openInfoDir(num);
-       info_dir.unlink("snapshot", AT_REMOVEDIR);
+       info_dir.unlink(SNAPSHOT_NAME, AT_REMOVEDIR);
 
        SDir infos_dir = openInfosDir();
        infos_dir.unlink(decString(num), AT_REMOVEDIR);
@@ -347,7 +347,7 @@ namespace snapper
        {
            SDir info_dir = openInfoDir(num);
 
-           if (!umount(info_dir, "snapshot"))
+           if (!umount(info_dir, SNAPSHOT_NAME))
                SN_THROW(UmountSnapshotFailedException());
        }
 
index d5821c6a1bc6ab21284160d4d0848d5e76c88ba8..7711f21fc917eb1361f8de5308d60b5620c7eb11 100644 (file)
@@ -1033,7 +1033,7 @@ namespace snapper
        try
        {
            SDir subvol_dir = openSubvolumeDir();
-           SDir infos_dir(subvol_dir, ".snapshots");
+           SDir infos_dir(subvol_dir, SNAPSHOTS_NAME);
 
            if (infos_dir.restorecon(selabel_handle))
            {
@@ -1080,7 +1080,7 @@ namespace snapper
 
            if (!skip_snapshot_dir)
            {
-               SFile snapshot_dir(info_dir, "snapshot");
+               SFile snapshot_dir(info_dir, SNAPSHOT_NAME);
                snapshot_dir.restorecon(selabel_handle);
            }
 
index fe2d3ee859ecd9601a9ded69b9d02b527f807003..6285c1567d053efaf9df2447308bdf9acf5b7525 100644 (file)
 #define DEV_MAPPER_DIR "/dev/mapper"
 
 
+// parts of the path of snapshots
+// "/.snapshots/42/snapshot/" = "/SNAPSHOTS_NAME/42/snapshot/"
+
+#define SNAPSHOTS_NAME ".snapshots"
+#define SNAPSHOT_NAME "snapshot"
+
+
 // commands
 
 #define SH_BIN "/bin/sh"