]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- disallow deleting special snapshots 439/head
authorArvin Schnell <aschnell@suse.de>
Tue, 16 Oct 2018 12:15:45 +0000 (14:15 +0200)
committerArvin Schnell <aschnell@suse.de>
Tue, 16 Oct 2018 12:45:53 +0000 (14:45 +0200)
VERSION
client/cleanup.cc
client/snapper.cc
dists/debian/changelog
doc/snapper.xml.in
package/snapper.changes

diff --git a/VERSION b/VERSION
index faef31a4357c48d6e4c55e84c8be8e3bc9055e20..39e898a4f952d339c155a7939d571a5fdd6c8cfc 100644 (file)
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.7.0
+0.7.1
index d7f2f681e15855716ff6a7ea9de6626adf0eb6b8..1f630bd827815e3abac523762056c8ed61b825ff 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Copyright (c) [2011-2014] Novell, Inc.
- * Copyright (c) 2016 SUSE LLC
+ * Copyright (c) [2016,2018] SUSE LLC
  *
  * All Rights Reserved.
  *
@@ -102,6 +102,9 @@ protected:
 
     void filter(ProxySnapshots& snapshots, list<ProxySnapshots::iterator>& tmp) const;
 
+    // Removes snapshots that cannot be removed (e.g. btrfs active and default)
+    void filter_undeletables(ProxySnapshots& snapshots, list<ProxySnapshots::iterator>& tmp) const;
+
     // Removes snapshots younger than parameters.min_age from tmp
     void filter_min_age(ProxySnapshots& snapshots, list<ProxySnapshots::iterator>& tmp) const;
 
@@ -128,11 +131,36 @@ protected:
 void
 Cleaner::filter(ProxySnapshots& snapshots, list<ProxySnapshots::iterator>& tmp) const
 {
+    filter_undeletables(snapshots, tmp);
     filter_min_age(snapshots, tmp);
     filter_pre_post(snapshots, tmp);
 }
 
 
+void
+Cleaner::filter_undeletables(ProxySnapshots& snapshots, list<ProxySnapshots::iterator>& tmp) const
+{
+    vector<ProxySnapshots::const_iterator> undeletables;
+
+    ProxySnapshots::const_iterator default_snapshot = snapshots.getDefault();
+    if (default_snapshot != snapshots.end())
+       undeletables.push_back(default_snapshot);
+
+    ProxySnapshots::const_iterator active_snapshot = snapshots.getActive();
+    if (active_snapshot != snapshots.end())
+       undeletables.push_back(active_snapshot);
+
+    for (ProxySnapshots::const_iterator undeletable : undeletables)
+    {
+       list<ProxySnapshots::iterator>::iterator keep = find_if(tmp.begin(), tmp.end(),
+           [undeletable](ProxySnapshots::iterator it){ return undeletable->getNum() == it->getNum(); });
+
+       if (keep != tmp.end())
+           tmp.erase(keep);
+    }
+}
+
+
 void
 Cleaner::filter_min_age(ProxySnapshots& snapshots, list<ProxySnapshots::iterator>& tmp) const
 {
index b92b283b81f1a16b3328a34e0a84ae34b3d7e023..84f37e4751afcb984acf7de99d0a6deb0476d0f6 100644 (file)
@@ -445,18 +445,8 @@ list_from_one_config(ProxySnapper* snapper, ListMode list_mode, bool show_used_s
 {
     const ProxySnapshots& snapshots = snapper->getSnapshots();
 
-    ProxySnapshots::const_iterator default_snapshot = snapshots.end();
-    ProxySnapshots::const_iterator active_snapshot = snapshots.end();
-
-    try
-    {
-       default_snapshot = snapshots.getDefault();
-       active_snapshot = snapshots.getActive();
-    }
-    catch (const UnsupportedException& e)
-    {
-       SN_CAUGHT(e);
-    }
+    ProxySnapshots::const_iterator default_snapshot = snapshots.getDefault();
+    ProxySnapshots::const_iterator active_snapshot = snapshots.getActive();
 
     if (list_mode != LM_ALL && list_mode != LM_SINGLE)
        show_used_space = false;
@@ -797,6 +787,35 @@ help_delete()
 }
 
 
+void
+filter_undeletables(ProxySnapshots& snapshots, vector<ProxySnapshots::iterator>& nums)
+{
+    vector<ProxySnapshots::const_iterator> undeletables;
+
+    undeletables.push_back(snapshots.begin());
+
+    ProxySnapshots::const_iterator default_snapshot = snapshots.getDefault();
+    if (default_snapshot != snapshots.end())
+       undeletables.push_back(default_snapshot);
+
+    ProxySnapshots::const_iterator active_snapshot = snapshots.getActive();
+    if (active_snapshot != snapshots.end())
+       undeletables.push_back(active_snapshot);
+
+    for (ProxySnapshots::const_iterator undeletable : undeletables)
+    {
+       vector<ProxySnapshots::iterator>::iterator keep = find_if(nums.begin(), nums.end(),
+           [undeletable](ProxySnapshots::iterator it){ return undeletable->getNum() == it->getNum(); });
+
+       if (keep != nums.end())
+       {
+           cerr << sformat(_("Cannot delete snapshot %d."), (*keep)->getNum()) << endl;
+           nums.erase(keep);
+       }
+    }
+}
+
+
 void
 command_delete(ProxySnappers* snappers, ProxySnapper* snapper)
 {
@@ -853,6 +872,8 @@ command_delete(ProxySnappers* snappers, ProxySnapper* snapper)
        }
     }
 
+    filter_undeletables(snapshots, nums);
+
     snapper->deleteSnapshots(nums, verbose);
 
     if (sync)
index 24ff139cef0d70aad6b12ee359525f3b9ccd0d28..8fd686691867713e440a95115939bb70b39a351f 100644 (file)
@@ -1,3 +1,9 @@
+snapper (0.7.1) stable; urgency=low
+
+  * Updated to version 0.7.1
+
+ -- Arvin Schnell <aschnell@suse.com>  Tue, 16 Oct 2018 14:02:07 +0200
+
 snapper (0.6.0) stable; urgency=low
 
   * Updated to version 0.6.0
index 866bf24899bbdbd37d2e24e498e3bb0b69c15ded..5be5074d29001dbc5647c69104f94c19d43c3b9d 100644 (file)
@@ -2,13 +2,13 @@
 <refentry id='snapper8'>
 
   <refentryinfo>
-    <date>2014-04-07</date>
+    <date>2018-10-16</date>
   </refentryinfo>
 
   <refmeta>
     <refentrytitle>snapper</refentrytitle>
     <manvolnum>8</manvolnum>
-    <refmiscinfo class='date'>2014-04-07</refmiscinfo>
+    <refmiscinfo class='date'>2018-10-16</refmiscinfo>
     <refmiscinfo class='version'>@VERSION@</refmiscinfo>
     <refmiscinfo class='manual'>Filesystem Snapshot Management</refmiscinfo>
   </refmeta>
              </listitem>
            </varlistentry>
          </variablelist>
+         <para>Snapshot 0 cannot be deleted. For btrfs the currently
+         mounted snapshot and the snapshot that will be mounted next time
+         (the btrfs default subvolume) can also not be deleted.</para>
        </listitem>
       </varlistentry>
 
index 07b45ed61cb945a8dcadd66467ae4a5f0dab7690..46cd4112aa229f57af60bbc055b5435ddad20e47 100644 (file)
@@ -1,3 +1,10 @@
+-------------------------------------------------------------------
+Tue Oct 16 14:00:56 CEST 2018 - aschnell@suse.com
+
+- disallow to delete special (for btrfs currently mounted and next
+  to be mounted) snapshots (fate#326479)
+- version 0.7.1
+
 -------------------------------------------------------------------
 Thu Oct 11 11:10:11 CEST 2018 - aschnell@suse.com