]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- added consistency checks
authorArvin Schnell <aschnell@suse.de>
Mon, 7 Feb 2011 15:45:35 +0000 (16:45 +0100)
committerArvin Schnell <aschnell@suse.de>
Mon, 7 Feb 2011 15:45:35 +0000 (16:45 +0100)
snapper/Snapshot.cc
snapper/Snapshot.h

index 871665c595ac207b8a22b9be797baebdfda654ac..d3c694cd75a91c39aa60011dfab669d97b1cd5a4 100644 (file)
@@ -132,6 +132,44 @@ namespace snapper
     }
 
 
+    void
+    Snapshots::check() const
+    {
+       for (const_iterator i1 = begin(); i1 != end(); ++i1)
+       {
+           switch (i1->type)
+           {
+               case SINGLE:
+               {
+               }
+               break;
+
+               case PRE:
+               {
+                   int n = 0;
+                   for (const_iterator i2 = begin(); i2 != end(); ++i2)
+                       if (i2->pre_num == i1->num)
+                           n++;
+                   if (n > 1)
+                       y2err("num " << i1->num << " has " << n << " post-nums");
+               }
+               break;
+
+               case POST:
+               {
+                   if (i1->pre_num > i1->num)
+                       y2err("pre-num " << i1->pre_num << " larger than num " << i1->num);
+
+                   const_iterator i2 = find(i1->pre_num);
+                   if (i2 == end())
+                       y2err("pre-num " << i1->pre_num << " for num " << i1->num << " does not exist");
+               }
+               break;
+           }
+       }
+    }
+
+
     void
     Snapshots::initialize()
     {
@@ -145,6 +183,8 @@ namespace snapper
        entries.push_back(snapshot);
 
        read();
+
+       check();
     }
 
 
index 3b2e10e35b8c02d3153a48b8e359c1fdcd50d454..0684988ea33e09d4ff857a9c035d04e4deeedafe 100644 (file)
@@ -112,6 +112,8 @@ namespace snapper
 
        void read();
 
+       void check() const;
+
        iterator createSingleSnapshot(string description);
        iterator createPreSnapshot(string description);
        iterator createPostSnapshot(const_iterator pre);