/*
- * Copyright (c) [2011-2012] Novell, Inc.
+ * Copyright (c) [2011-2013] Novell, Inc.
*
* All Rights Reserved.
*
}
+bool
+is_important(XSnapshots::const_iterator it1)
+{
+ map<string, string>::const_iterator it2 = it1->getUserdata().find("important");
+ return it2 != it1->getUserdata().end() && it2->second == "yes";
+}
+
+
bool
do_cleanup_number(DBus::Connection& conn, const string& config_name)
{
time_t min_age = 1800;
size_t limit = 50;
+ size_t limit_important = 10;
XConfigInfo ci = command_get_xconfig(conn, config_name);
map<string, string>::const_iterator pos;
pos->second >> min_age;
if ((pos = ci.raw.find("NUMBER_LIMIT")) != ci.raw.end())
pos->second >> limit;
+ if ((pos = ci.raw.find("NUMBER_LIMIT_IMPORTANT")) != ci.raw.end())
+ pos->second >> limit_important;
+
+ size_t num = 0;
+ size_t num_important = 0;
XSnapshots snapshots = command_list_xsnapshots(conn, config_name);
for (XSnapshots::const_iterator it = snapshots.begin(); it != snapshots.end(); ++it)
{
if (it->getCleanup() == "number")
- tmp.push_back(it);
+ tmp.push_front(it);
}
- if (tmp.size() > limit)
+ list<XSnapshots::const_iterator>::iterator it = tmp.begin();
+ while (it != tmp.end())
{
- list<XSnapshots::const_iterator>::iterator it = tmp.end();
- advance(it, - limit);
- tmp.erase(it, tmp.end());
-
- filter1(tmp, min_age);
- filter2(snapshots, tmp);
+ bool keep = false;
- for (list<XSnapshots::const_iterator>::const_iterator it = tmp.begin(); it != tmp.end(); ++it)
+ if (num_important < limit_important && is_important(*it))
{
- list<unsigned int> nums;
- nums.push_back((*it)->getNum());
- command_delete_xsnapshots(conn, config_name, nums);
+ ++num_important;
+ keep = true;
}
+ if (num < limit)
+ {
+ ++num;
+ keep = true;
+ }
+
+ if (keep)
+ it = tmp.erase(it);
+ else
+ ++it;
+ }
+
+ tmp.reverse();
+
+ filter1(tmp, min_age);
+ filter2(snapshots, tmp);
+
+ for (list<XSnapshots::const_iterator>::const_iterator it = tmp.begin(); it != tmp.end(); ++it)
+ {
+ list<unsigned int> nums;
+ nums.push_back((*it)->getNum());
+ command_delete_xsnapshots(conn, config_name, nums);
}
return true;
}
if (keep)
- {
it = tmp.erase(it);
- }
else
- {
++it;
- }
}
tmp.reverse();
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>NUMBER_LIMIT_IMPORTANT=<replaceable>number</replaceable></option></term>
+ <listitem>
+ <para>Defines how many important snapshots the number cleanup
+ algorithm should keep. Important snapshots have important=yes in the
+ userdata. The youngest important snapshots will be kept.</para>
+ <para>Default value is "10".</para>
+ <para>New in version 0.1.8.</para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><option>TIMELINE_CREATE=<replaceable>boolean</replaceable></option></term>
<listitem>