From: Arvin Schnell Date: Tue, 16 Oct 2018 12:15:45 +0000 (+0200) Subject: - disallow deleting special snapshots X-Git-Tag: v0.7.1~4^2 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=41998dfe23246792ab808cc4035d135d97a2386e;p=thirdparty%2Fsnapper.git - disallow deleting special snapshots --- diff --git a/VERSION b/VERSION index faef31a4..39e898a4 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.7.0 +0.7.1 diff --git a/client/cleanup.cc b/client/cleanup.cc index d7f2f681..1f630bd8 100644 --- a/client/cleanup.cc +++ b/client/cleanup.cc @@ -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& tmp) const; + // Removes snapshots that cannot be removed (e.g. btrfs active and default) + void filter_undeletables(ProxySnapshots& snapshots, list& tmp) const; + // Removes snapshots younger than parameters.min_age from tmp void filter_min_age(ProxySnapshots& snapshots, list& tmp) const; @@ -128,11 +131,36 @@ protected: void Cleaner::filter(ProxySnapshots& snapshots, list& tmp) const { + filter_undeletables(snapshots, tmp); filter_min_age(snapshots, tmp); filter_pre_post(snapshots, tmp); } +void +Cleaner::filter_undeletables(ProxySnapshots& snapshots, list& tmp) const +{ + vector 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::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& tmp) const { diff --git a/client/snapper.cc b/client/snapper.cc index b92b283b..84f37e47 100644 --- a/client/snapper.cc +++ b/client/snapper.cc @@ -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& nums) +{ + vector 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::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) diff --git a/dists/debian/changelog b/dists/debian/changelog index 24ff139c..8fd68669 100644 --- a/dists/debian/changelog +++ b/dists/debian/changelog @@ -1,3 +1,9 @@ +snapper (0.7.1) stable; urgency=low + + * Updated to version 0.7.1 + + -- Arvin Schnell Tue, 16 Oct 2018 14:02:07 +0200 + snapper (0.6.0) stable; urgency=low * Updated to version 0.6.0 diff --git a/doc/snapper.xml.in b/doc/snapper.xml.in index 866bf248..5be5074d 100644 --- a/doc/snapper.xml.in +++ b/doc/snapper.xml.in @@ -2,13 +2,13 @@ - 2014-04-07 + 2018-10-16 snapper 8 - 2014-04-07 + 2018-10-16 @VERSION@ Filesystem Snapshot Management @@ -485,6 +485,9 @@ + 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. diff --git a/package/snapper.changes b/package/snapper.changes index 07b45ed6..46cd4112 100644 --- a/package/snapper.changes +++ b/package/snapper.changes @@ -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