]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- added function to query default snapshot
authorArvin Schnell <aschnell@suse.de>
Mon, 8 May 2017 18:41:38 +0000 (20:41 +0200)
committerArvin Schnell <aschnell@suse.de>
Tue, 9 May 2017 08:27:22 +0000 (10:27 +0200)
LIBVERSION
snapper/Btrfs.cc
snapper/Btrfs.h
snapper/Filesystem.cc
snapper/Filesystem.h

index fcdb2e109f68cff5600955a73908885fe8599bb4..ee74734aa2258df77aa09402d55798a1e2e55212 100644 (file)
@@ -1 +1 @@
-4.0.0
+4.1.0
index 6be6e868d3433f9a92c06f4a3cb3f01760dd9aa2..2ea72d2a4291e628be3c26f0f1785dc86fc07608 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) [2011-2015] Novell, Inc.
- * Copyright (c) 2016 SUSE LLC
+ * Copyright (c) [2016-2017] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -55,6 +55,7 @@
 #include "snapper/SnapperDefines.h"
 #include "snapper/Acls.h"
 #include "snapper/Exception.h"
+#include "snapper/Regex.h"
 #ifdef ENABLE_ROLLBACK
 #include "snapper/MntTable.h"
 #endif
@@ -1448,6 +1449,28 @@ namespace snapper
     }
 
 
+    std::pair<bool, unsigned int>
+    Btrfs::getDefault() const
+    {
+       SDir subvolume_dir = openSubvolumeDir();
+
+       subvolid_t id = get_default_id(subvolume_dir.fd());
+
+       string path = get_subvolume(subvolume_dir.fd(), id);
+
+       Regex rx("/([0-9]+)/snapshot$");
+       if (!rx.match(path))
+           return make_pair(false, 0);
+
+       unsigned int num = stoi(rx.cap(1));
+
+       if (get_id(openSnapshotDir(num).fd()) != id)
+           return make_pair(false, 0);
+
+       return make_pair(true, num);
+    }
+
+
     void
     Btrfs::setDefault(unsigned int num) const
     {
@@ -1506,6 +1529,13 @@ namespace snapper
     }
 
 
+    std::pair<bool, unsigned int>
+    Btrfs::getDefault() const
+    {
+       throw std::logic_error("not implemented");
+    }
+
+
     void
     Btrfs::setDefault(unsigned int num) const
     {
index 7b427828b03f1c42b2ad84ceb3cecc8b56cca270..546335418fa123f3bb15cfab660708fee5f7c554 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) [2011-2015] Novell, Inc.
- * Copyright (c) 2016 SUSE LLC
+ * Copyright (c) [2016-2017] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -83,6 +83,8 @@ namespace snapper
        virtual void cmpDirs(const SDir& dir1, const SDir& dir2, cmpdirs_cb_t cb) const;
 
        virtual bool isDefault(unsigned int num) const;
+
+       virtual std::pair<bool, unsigned int> getDefault() const;
        virtual void setDefault(unsigned int num) const;
 
        virtual bool isActive(unsigned int num) const;
index db51f861745f9ea20848f454511fdc38e338c6cd..204ae98c215bd4df032ddd8818f8e7b1bfbbe0c4 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) [2011-2015] Novell, Inc.
- * Copyright (c) 2016 SUSE LLC
+ * Copyright (c) [2016-2017] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -177,6 +177,13 @@ namespace snapper
     }
 
 
+    std::pair<bool, unsigned int>
+    Filesystem::getDefault() const
+    {
+       throw std::logic_error("not implemented");
+    }
+
+
     void
     Filesystem::setDefault(unsigned int num) const
     {
index 5f1dc2acda871e6ae2eb53d96d5560abab9d03f0..7ae0bb2862f0b4f957e922ba009bb0d6b63a6164 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) [2011-2015] Novell, Inc.
- * Copyright (c) 2016 SUSE LLC
+ * Copyright (c) [2016-2017] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -27,6 +27,7 @@
 
 #include <string>
 #include <vector>
+#include <utility>
 
 #include "snapper/FileUtils.h"
 #include "snapper/Compare.h"
@@ -83,6 +84,14 @@ namespace snapper
        virtual void cmpDirs(const SDir& dir1, const SDir& dir2, cmpdirs_cb_t cb) const;
 
        virtual bool isDefault(unsigned int num) const;
+
+       /**
+        * Query the number of the default snapshot. The first entry of the
+        * pair indicates whether the default snapshot is a snapper snapshot.
+        * Currently only available for btrfs.
+        */
+       virtual std::pair<bool, unsigned int> getDefault() const;
+
        virtual void setDefault(unsigned int num) const;
 
        virtual bool isActive(unsigned int num) const;