]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- allow to ignore files during snapshot comparison
authorArvin Schnell <aschnell@suse.de>
Mon, 4 Apr 2011 12:22:05 +0000 (14:22 +0200)
committerArvin Schnell <aschnell@suse.de>
Mon, 4 Apr 2011 12:22:05 +0000 (14:22 +0200)
data/Makefile.am
data/base.txt [new file with mode: 0644]
package/snapper.changes
snapper.spec.in
snapper/File.cc
snapper/File.h
snapper/Snapper.cc
snapper/Snapper.h
snapper/SnapperDefines.h

index 8367e83dec58f1374d5b60d635d0b5fa98103cf1..ae345c5859401f669e6e927de7c0553d19f5ecaf 100644 (file)
@@ -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 (file)
index 0000000..07a40a0
--- /dev/null
@@ -0,0 +1,2 @@
+/etc/mtab
+/etc/adjtime
index 07ec0fa766d10701c4e926b354e08555b15f2baa..6f7e64ea43517eb1c82a937605b0a28966d4f27a 100644 (file)
@@ -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
 
index ab7dcaa3f5f23c4cb35e49ca2197eab3019b32ba..f5866bf7e6929007b2aa419e4655eadffba95b4c 100644 (file)
@@ -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
index 62d622cc6eafc37745c70065fc16a264898cda61..52debd32ce0d714973f86fcbf537293daf6249e2 100644 (file)
@@ -22,9 +22,9 @@
 
 #include <sys/stat.h>
 #include <sys/types.h>
-#include <glob.h>
 #include <string.h>
 #include <unistd.h>
+#include <fnmatch.h>
 
 #include "snapper/File.h"
 #include "snapper/Snapper.h"
@@ -231,6 +231,30 @@ namespace snapper
     }
 
 
+    struct FilterHelper
+    {
+       FilterHelper(const vector<string>& patterns)
+           : patterns(patterns) {}
+       bool operator()(const File& file)
+           {
+               for (vector<string>::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<string>& patterns;
+    };
+
+
+    void
+    Files::filter()
+    {
+       const vector<string>& 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();
     }
 
 
index 4434c7743f8642625bdc96895c151a2830df2dce..cc04708699669c225a52978aa3dd2cd4be081b51 100644 (file)
@@ -153,6 +153,7 @@ namespace snapper
        void create();
        bool load();
        bool save();
+       void filter();
 
        RollbackStatistic getRollbackStatistic() const;
 
index 308e95ba8fcfaebcaa3d2eb37496aa884f71e4f9..e0ea5996474a0a70cb42256a53849b13f24e168d 100644 (file)
@@ -60,6 +60,8 @@ namespace snapper
 
        y2mil("subvolume:" << subvolume);
 
+       loadPatterns();
+
        snapshots.initialize();
     }
 
@@ -72,6 +74,40 @@ namespace snapper
     }
 
 
+    void
+    Snapper::loadPatterns()
+    {
+       const list<string> files = glob(FILTERSDIR "/*.txt", GLOB_NOSORT);
+       for (list<string>::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
index 4b169c771d354444662e23de7bc46fe2b1307083..54c80da4589594e1789c5960a444c27419ee64b0 100644 (file)
 #define SNAPPER_H
 
 
+#include <vector>
+
 #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<string>& getFilterPatterns() const { return filter_patterns; }
+
     private:
 
        void filter1(list<Snapshots::iterator>& tmp, time_t min_age);
        void filter2(list<Snapshots::iterator>& tmp);
 
+       void loadPatterns();
+
        const string config_name;
 
        SysconfigFile* config;
 
        string subvolume;
 
+       vector<string> filter_patterns;
+
        Snapshots snapshots;
 
        CompareCallback* compare_callback;
index da81b465d287abacf72dea8f152d2243cae5e71c..cecda9a286172c152b0c6a2d095e94c7abd45d9a 100644 (file)
@@ -25,6 +25,7 @@
 
 
 #define CONFIGSDIR "/etc/snapper/configs"
+#define FILTERSDIR "/etc/snapper/filters"
 
 #define SNAPSHOTDIR "/snapshot"
 #define SNAPSHOTSDIR "/snapshots"