]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
Implement BtrfsUtils::get_id using libbtrfsutil 832/head
authorDavid Sterba <dsterba@suse.com>
Thu, 19 Jan 2023 18:30:50 +0000 (19:30 +0100)
committerDavid Sterba <dsterba@suse.com>
Thu, 24 Aug 2023 17:44:13 +0000 (19:44 +0200)
The get_id() member can be also implemented using libbtrfsutil. A
separate conditional implementation is added and the #ifdefs updated
to take that into account.

snapper/Btrfs.cc
snapper/BtrfsUtils.cc

index c406daa8cb09012460055c4c44c737662b1250c7..1828ed094a944d56a9915a3a28e4dbd3f4d9c67c 100644 (file)
@@ -402,13 +402,13 @@ namespace snapper
 
        try
        {
-#ifdef HAVE_LIBBTRFS
+#if defined(HAVE_LIBBTRFS) || defined(HAVE_LIBBTRFSUTIL)
            subvolid_t subvolid = get_id(openSnapshotDir(num).fd());
 #endif
 
            delete_subvolume(info_dir.fd(), "snapshot");
 
-#ifdef HAVE_LIBBTRFS
+#if defined(HAVE_LIBBTRFS) || defined(HAVE_LIBBTRFSUTIL)
            deleted_subvolids.push_back(subvolid);
 #endif
 
index dc055165d4e3f4dadf9210fed5db26e274881ea5..2ff0fffdbfa642fb33d46573ff3609468e12ad8a 100644 (file)
@@ -362,9 +362,20 @@ namespace snapper
 
 #endif
 
+#ifdef HAVE_LIBBTRFSUTIL
+       subvolid_t
+       get_id(int fd)
+       {
+           enum btrfs_util_error err;
+           subvolid_t id;
 
-#ifdef HAVE_LIBBTRFS
+           err = btrfs_util_subvolume_id_fd(fd, &id);
+           if (err)
+               throw runtime_error_with_errno("btrfs_util_subvolume_id_fd() failed", errno);
 
+           return id;
+       }
+#elif defined(HAVE_LIBBTRFS)
        subvolid_t
        get_id(int fd)
        {
@@ -378,8 +389,10 @@ namespace snapper
 
            return args.treeid;
        }
+#endif
 
 
+#ifdef HAVE_LIBBTRFS
        bool
        does_subvolume_exist(int fd, subvolid_t subvolid)
        {