From: Arvin Schnell Date: Mon, 4 Apr 2011 12:22:05 +0000 (+0200) Subject: - allow to ignore files during snapshot comparison X-Git-Tag: v0.1.3~426 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a2e75363ee4911e8f79e03d0e76c4fd2f3219fa9;p=thirdparty%2Fsnapper.git - allow to ignore files during snapshot comparison --- diff --git a/data/Makefile.am b/data/Makefile.am index 8367e83d..ae345c58 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -4,10 +4,12 @@ fillup_DATA = sysconfig.snapper -EXTRA_DIST = $(fillup_DATA) snapper.logrotate example-config +EXTRA_DIST = $(fillup_DATA) base.txt snapper.logrotate example-config install-data-local: install -D -m 644 snapper.logrotate $(DESTDIR)/etc/logrotate.d/snapper install -d -m 755 $(DESTDIR)/etc/snapper/configs + install -d -m 755 $(DESTDIR)/etc/snapper/filters + install -D -m 644 base.txt $(DESTDIR)/etc/snapper/filters/base.txt install -D -m 644 example-config $(DESTDIR)/usr/share/doc/packages/snapper/example-config diff --git a/data/base.txt b/data/base.txt new file mode 100644 index 00000000..07a40a0d --- /dev/null +++ b/data/base.txt @@ -0,0 +1,2 @@ +/etc/mtab +/etc/adjtime diff --git a/package/snapper.changes b/package/snapper.changes index 07ec0fa7..6f7e64ea 100644 --- a/package/snapper.changes +++ b/package/snapper.changes @@ -1,3 +1,8 @@ +------------------------------------------------------------------- +Mon Apr 04 14:20:43 CEST 2011 - aschnell@suse.de + +- allow to ignore files during snapshot comparison + ------------------------------------------------------------------- Mon Jan 10 14:55:25 CET 2011 - aschnell@suse.de diff --git a/snapper.spec.in b/snapper.spec.in index ab7dcaa3..f5866bf7 100644 --- a/snapper.spec.in +++ b/snapper.spec.in @@ -72,6 +72,8 @@ Authors: %{_libdir}/libsnapper.so.* %dir %{_sysconfdir}/snapper %dir %{_sysconfdir}/snapper/configs +%dir %{_sysconfdir}/snapper/filters +%config(noreplace) %{_sysconfdir}/snapper/filters/base.txt %doc %dir %{prefix}/share/doc/packages/snapper %doc %{prefix}/share/doc/packages/snapper/AUTHORS %doc %{prefix}/share/doc/packages/snapper/COPYING diff --git a/snapper/File.cc b/snapper/File.cc index 62d622cc..52debd32 100644 --- a/snapper/File.cc +++ b/snapper/File.cc @@ -22,9 +22,9 @@ #include #include -#include #include #include +#include #include "snapper/File.h" #include "snapper/Snapper.h" @@ -231,6 +231,30 @@ namespace snapper } + struct FilterHelper + { + FilterHelper(const vector& patterns) + : patterns(patterns) {} + bool operator()(const File& file) + { + for (vector::const_iterator it = patterns.begin(); it != patterns.end(); ++it) + if (fnmatch(it->c_str(), file.getName().c_str(), 0) == 0) + return true; + return false; + } + const vector& patterns; + }; + + + void + Files::filter() + { + const vector& filter_patterns = getSnapper()->getFilterPatterns(); + entries.erase(remove_if(entries.begin(), entries.end(), FilterHelper(filter_patterns)), + entries.end()); + } + + void Files::initialize() { @@ -248,6 +272,8 @@ namespace snapper save(); } } + + filter(); } diff --git a/snapper/File.h b/snapper/File.h index 4434c774..cc047086 100644 --- a/snapper/File.h +++ b/snapper/File.h @@ -153,6 +153,7 @@ namespace snapper void create(); bool load(); bool save(); + void filter(); RollbackStatistic getRollbackStatistic() const; diff --git a/snapper/Snapper.cc b/snapper/Snapper.cc index 308e95ba..e0ea5996 100644 --- a/snapper/Snapper.cc +++ b/snapper/Snapper.cc @@ -60,6 +60,8 @@ namespace snapper y2mil("subvolume:" << subvolume); + loadPatterns(); + snapshots.initialize(); } @@ -72,6 +74,40 @@ namespace snapper } + void + Snapper::loadPatterns() + { + const list files = glob(FILTERSDIR "/*.txt", GLOB_NOSORT); + for (list::const_iterator it = files.begin(); it != files.end(); ++it) + { + FILE* file = fopen(it->c_str(), "r"); + if (file == NULL) + { + y2err("file not found"); + continue; + } + + char* line = NULL; + size_t len = 0; + + while (getline(&line, &len, file) != -1) + { + // TODO: more robust + + string filter_pattern = string(line, 0, strlen(line) - 1); + + filter_patterns.push_back(filter_pattern); + } + + free(line); + + fclose(file); + } + + y2mil("number of filter patterns:" << filter_patterns.size()); + } + + // Directory of which snapshots are made, e.g. "/" or "/home". string Snapper::subvolumeDir() const diff --git a/snapper/Snapper.h b/snapper/Snapper.h index 4b169c77..54c80da4 100644 --- a/snapper/Snapper.h +++ b/snapper/Snapper.h @@ -24,11 +24,16 @@ #define SNAPPER_H +#include + #include "snapper/Snapshot.h" namespace snapper { + using std::vector; + + class SysconfigFile; @@ -73,17 +78,23 @@ namespace snapper void setCompareCallback(CompareCallback* p) { compare_callback = p; } CompareCallback* getCompareCallback() const { return compare_callback; } + const vector& getFilterPatterns() const { return filter_patterns; } + private: void filter1(list& tmp, time_t min_age); void filter2(list& tmp); + void loadPatterns(); + const string config_name; SysconfigFile* config; string subvolume; + vector filter_patterns; + Snapshots snapshots; CompareCallback* compare_callback; diff --git a/snapper/SnapperDefines.h b/snapper/SnapperDefines.h index da81b465..cecda9a2 100644 --- a/snapper/SnapperDefines.h +++ b/snapper/SnapperDefines.h @@ -25,6 +25,7 @@ #define CONFIGSDIR "/etc/snapper/configs" +#define FILTERSDIR "/etc/snapper/filters" #define SNAPSHOTDIR "/snapshot" #define SNAPSHOTSDIR "/snapshots"