/*
- * Copyright (c) [2011-2013] Novell, Inc.
+ * Copyright (c) [2011-2014] Novell, Inc.
*
* All Rights Reserved.
*
#include <snapper/SnapperTmpl.h>
+#include "utils/equal-date.h"
+
#include "commands.h"
using namespace std;
}
-bool
-equal_year(const struct tm& tmp1, const struct tm& tmp2)
-{
- return tmp1.tm_year == tmp2.tm_year;
-}
-
-bool
-equal_month(const struct tm& tmp1, const struct tm& tmp2)
-{
- return equal_year(tmp1, tmp2) && tmp1.tm_mon == tmp2.tm_mon;
-}
-
-bool
-equal_day(const struct tm& tmp1, const struct tm& tmp2)
-{
- return equal_month(tmp1, tmp2) && tmp1.tm_mday == tmp2.tm_mday;
-}
-
-bool
-equal_hour(const struct tm& tmp1, const struct tm& tmp2)
-{
- return equal_day(tmp1, tmp2) && tmp1.tm_hour == tmp2.tm_hour;
-}
-
-
bool
is_first_yearly(list<XSnapshots::const_iterator>::const_iterator first,
list<XSnapshots::const_iterator>::const_iterator last,
return is_first(first, last, it1, equal_month);
}
+bool
+is_first_weekly(list<XSnapshots::const_iterator>::const_iterator first,
+ list<XSnapshots::const_iterator>::const_iterator last,
+ XSnapshots::const_iterator it1)
+{
+ return is_first(first, last, it1, equal_week);
+}
+
bool
is_first_daily(list<XSnapshots::const_iterator>::const_iterator first,
list<XSnapshots::const_iterator>::const_iterator last,
size_t limit_hourly = 10;
size_t limit_daily = 10;
size_t limit_monthly = 10;
+ size_t limit_weekly = 0;
size_t limit_yearly = 10;
XConfigInfo ci = command_get_xconfig(conn, config_name);
pos->second >> limit_hourly;
if ((pos = ci.raw.find("TIMELINE_LIMIT_DAILY")) != ci.raw.end())
pos->second >> limit_daily;
+ if ((pos = ci.raw.find("TIMELINE_LIMIT_WEEKLY")) != ci.raw.end())
+ pos->second >> limit_weekly;
if ((pos = ci.raw.find("TIMELINE_LIMIT_MONTHLY")) != ci.raw.end())
pos->second >> limit_monthly;
if ((pos = ci.raw.find("TIMELINE_LIMIT_YEARLY")) != ci.raw.end())
size_t num_hourly = 0;
size_t num_daily = 0;
+ size_t num_weekly = 0;
size_t num_monthly = 0;
size_t num_yearly = 0;
++num_daily;
keep = true;
}
+ if (num_weekly < limit_weekly && is_first_weekly(it, tmp.end(), *it))
+ {
+ ++num_weekly;
+ keep = true;
+ }
if (num_monthly < limit_monthly && is_first_monthly(it, tmp.end(), *it))
{
++num_monthly;
Table.cc Table.h \
text.cc text.h \
console.cc console.h \
+ equal-date.cc equal-date.h \
GetOpts.cc GetOpts.h
libutils_la_LIBADD = ../../snapper/libsnapper.la
--- /dev/null
+/*
+ * Copyright (c) [2011-2014] Novell, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may
+ * find current contact information at www.novell.com.
+ */
+
+
+#include <time.h>
+
+#include "equal-date.h"
+
+
+int
+yday_of_weeks_monday(const struct tm& tmp)
+{
+ return tmp.tm_yday - (tmp.tm_wday != 0 ? tmp.tm_wday : 7);
+}
+
+
+int
+days_in_year(const struct tm& tmp)
+{
+ return __isleap(tmp.tm_year) ? 366 : 365;
+}
+
+
+bool
+equal_year(const struct tm& tmp1, const struct tm& tmp2)
+{
+ return tmp1.tm_year == tmp2.tm_year;
+}
+
+
+bool
+equal_month(const struct tm& tmp1, const struct tm& tmp2)
+{
+ return equal_year(tmp1, tmp2) && tmp1.tm_mon == tmp2.tm_mon;
+}
+
+
+bool
+equal_week(const struct tm& tmp1, const struct tm& tmp2)
+{
+ if (tmp1.tm_year == tmp2.tm_year)
+ return yday_of_weeks_monday(tmp1) == yday_of_weeks_monday(tmp2);
+
+ if (tmp1.tm_year + 1 == tmp2.tm_year)
+ return yday_of_weeks_monday(tmp1) == yday_of_weeks_monday(tmp2) + days_in_year(tmp1);
+
+ if (tmp1.tm_year == tmp2.tm_year + 1)
+ return yday_of_weeks_monday(tmp1) + days_in_year(tmp2) == yday_of_weeks_monday(tmp2);
+
+ return false;
+}
+
+
+bool
+equal_day(const struct tm& tmp1, const struct tm& tmp2)
+{
+ return equal_month(tmp1, tmp2) && tmp1.tm_mday == tmp2.tm_mday;
+}
+
+
+bool
+equal_hour(const struct tm& tmp1, const struct tm& tmp2)
+{
+ return equal_day(tmp1, tmp2) && tmp1.tm_hour == tmp2.tm_hour;
+}
--- /dev/null
+/*
+ * Copyright (c) [2011-2014] Novell, Inc.
+ *
+ * All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2 of the GNU General Public License as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, contact Novell, Inc.
+ *
+ * To contact Novell about this file by physical or electronic mail, you may
+ * find current contact information at www.novell.com.
+ */
+
+
+bool
+equal_year(const struct tm& tmp1, const struct tm& tmp2);
+
+bool
+equal_month(const struct tm& tmp1, const struct tm& tmp2);
+
+bool
+equal_week(const struct tm& tmp1, const struct tm& tmp2);
+
+bool
+equal_day(const struct tm& tmp1, const struct tm& tmp2);
+
+bool
+equal_hour(const struct tm& tmp1, const struct tm& tmp2);
+
TIMELINE_MIN_AGE="1800"
TIMELINE_LIMIT_HOURLY="10"
TIMELINE_LIMIT_DAILY="10"
+TIMELINE_LIMIT_WEEKLY="0"
TIMELINE_LIMIT_MONTHLY="10"
TIMELINE_LIMIT_YEARLY="10"
</listitem>
</varlistentry>
+ <varlistentry>
+ <term><option>TIMELINE_LIMIT_WEEKLY=<replaceable>number</replaceable></option></term>
+ <listitem>
+ <para>Defines how many weekly snapshots the timeline cleanup
+ algorithm should keep. A weekly snapshot is the first snapshot in a week. The
+ youngest weekly snapshots will be kept.</para>
+ <para>Default value is "0".</para>
+ </listitem>
+ </varlistentry>
+
<varlistentry>
<term><option>TIMELINE_LIMIT_MONTHLY=<replaceable>number</replaceable></option></term>
<listitem>
<glossterm>timeline</glossterm>
<glossdef>
<para>Deletes old snapshots but keeps a number of hourly, daily,
- monthly and yearly snapshots.</para>
+ weekly, monthly and yearly snapshots.</para>
</glossdef>
</glossentry>
<glossentry>
+-------------------------------------------------------------------
+Thu Dec 11 17:58:14 CET 2014 - aschnell@suse.de
+
+- support weekly snapshots in cleanup algorithm (see
+ gh#openSUSE/snapper#135)
+
-------------------------------------------------------------------
Thu Oct 23 12:05:12 CEST 2014 - aschnell@suse.de
*.log
*.o
+*.test
*.trs
-basename1
-dirname1
-sysconfig-get1
test-suite.log
LDADD = ../snapper/libsnapper.la -lboost_unit_test_framework
-check_PROGRAMS = sysconfig-get1 dirname1 basename1
+check_PROGRAMS = sysconfig-get1.test dirname1.test basename1.test equal-date.test
TESTS = $(check_PROGRAMS)
EXTRA_DIST = $(noinst_SCRIPTS) sysconfig-get1.txt
+equal_date_test_LDADD = -lboost_unit_test_framework ../client/utils/libutils.la
+
--- /dev/null
+
+#define BOOST_TEST_DYN_LINK
+#define BOOST_TEST_MODULE snapper
+
+#include <boost/test/unit_test.hpp>
+
+#include "../client/utils/equal-date.h"
+
+
+bool
+equal_week(const char* s1, const char* s2)
+{
+ struct tm tmp1;
+ memset(&tmp1, 0, sizeof(tmp1));
+ strptime(s1, "%Y-%m-%d", &tmp1);
+
+ struct tm tmp2;
+ memset(&tmp2, 0, sizeof(tmp2));
+ strptime(s2, "%Y-%m-%d", &tmp2);
+
+ return equal_week(tmp1, tmp2);
+}
+
+
+BOOST_AUTO_TEST_CASE(test1)
+{
+ // 2012 is a leap year
+ BOOST_CHECK(equal_week("2011-12-31", "2012-01-01"));
+ BOOST_CHECK(equal_week("2012-01-01", "2011-12-31"));
+}
+
+
+BOOST_AUTO_TEST_CASE(test2)
+{
+ // 2012 is a leap year
+ BOOST_CHECK(equal_week("2012-12-31", "2013-01-01"));
+ BOOST_CHECK(equal_week("2013-01-01", "2012-12-31"));
+}
+
+
+BOOST_AUTO_TEST_CASE(test3)
+{
+ // Saturday and Sunday
+ BOOST_CHECK(equal_week("2014-01-04", "2014-01-05"));
+ BOOST_CHECK(equal_week("2014-01-05", "2014-01-04"));
+
+ // Sunday and Monday
+ BOOST_CHECK(!equal_week("2014-01-05", "2014-01-06"));
+ BOOST_CHECK(!equal_week("2014-01-06", "2014-01-05"));
+
+ // Monday and Tuesday
+ BOOST_CHECK(equal_week("2014-01-06", "2014-01-07"));
+ BOOST_CHECK(equal_week("2014-01-07", "2014-01-06"));
+}
+
+
+BOOST_AUTO_TEST_CASE(test4)
+{
+ // 2014-12-31 is a Wednesday, 2015-01-01 is a Thursday
+ BOOST_CHECK(equal_week("2014-12-31", "2015-01-01"));
+ BOOST_CHECK(equal_week("2015-01-01", "2014-12-31"));
+}
+
+
+BOOST_AUTO_TEST_CASE(test5)
+{
+ // 2017-12-31 is a Sunday, 2018-01-01 is a Monday
+ BOOST_CHECK(!equal_week("2017-12-31", "2018-01-01"));
+ BOOST_CHECK(!equal_week("2018-01-01", "2017-12-31"));
+}