]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- use list for snapshots since iterators are not invalidated on add/remove
authorArvin Schnell <aschnell@suse.de>
Thu, 3 Feb 2011 13:10:31 +0000 (14:10 +0100)
committerArvin Schnell <aschnell@suse.de>
Thu, 3 Feb 2011 13:10:31 +0000 (14:10 +0100)
examples/List.cc
snapper/Snapper.cc
snapper/SnapperInterface.h
snapper/Snapshot.cc
snapper/Snapshot.h
tools/snapper.cc

index d23e9dcb7c3d03b391fe3841d05bda3b6948acba..ad6688173c0d0434054c81d356911300fbf5985a 100644 (file)
@@ -12,7 +12,7 @@ main(int argc, char** argv)
 {
     snapshots.assertInit();
 
-    for (vector<Snapshot>::const_iterator it = snapshots.begin(); it != snapshots.end(); ++it)
+    for (list<Snapshot>::const_iterator it = snapshots.begin(); it != snapshots.end(); ++it)
     {
        cout << *it << endl;
     }
index 073ddf8372dad4d80d5e92e25f434169a2ffcae3..7f9339f22fee1e961d441f14ea80fedf9d362e1a 100644 (file)
@@ -40,49 +40,30 @@ namespace snapper
     using namespace std;
 
 
-/*
-    void
-    listSnapshots()
-    {
-       assertInit();
-
-       for (list<Snapshot>::const_iterator it = snapshots.begin();
-            it != snapshots.end(); ++it)
-       {
-           cout << *it << endl;
-       }
-    }
-*/
-
-
     void
-    startBackgroundComparsion(unsigned int num1, unsigned int num2)
+    startBackgroundComparsion(list<Snapshot>::const_iterator snapshot1,
+                             list<Snapshot>::const_iterator snapshot2)
     {
-       y2mil("num1:" << num1 << " num2:" << num2);
+       y2mil("num1:" << snapshot1->getNum() << " num2:" << snapshot2->getNum());
 
-       string dir1 = SNAPSHOTSDIR "/" + decString(num1) + "/snapshot";
-       string dir2 = SNAPSHOTSDIR "/" + decString(num2) + "/snapshot";
+       string dir1 = snapshot1->snapshotDir();
+       string dir2 = snapshot2->snapshotDir();
 
-       string output = SNAPSHOTSDIR "/" + decString(num2) + "/filelist-" + decString(num1) + ".txt";
+       string output = snapshot2->baseDir() + "/filelist-" + decString(snapshot1->getNum()) +
+           ".txt";
 
        SystemCmd(COMPAREDIRSBIN " " + quote(dir1) + " " + quote(dir2) + " " + quote(output));
     }
 
 
     bool
-    setComparisonNums(unsigned int num1, unsigned int num2)
+    setComparisonNums(list<Snapshot>::const_iterator new_snapshot1,
+                     list<Snapshot>::const_iterator new_snapshot2)
     {
-       y2mil("num1:" << num1 << " num2:" << num2);
-
-       snapshots.assertInit();
+       y2mil("num1:" << new_snapshot1->getNum() << " num2:" << new_snapshot2->getNum());
 
-       snapshot1 = snapshots.find(num1);
-       if (snapshot1 == snapshots.end())
-           return false;
-
-       snapshot2 = snapshots.find(num2);
-       if (snapshot2 == snapshots.end())
-           return false;
+       snapshot1 = new_snapshot1;
+       snapshot2 = new_snapshot2;
 
        files.assertInit();
 
@@ -90,51 +71,6 @@ namespace snapper
     }
 
 
-/*
-    list<string>
-    getFiles()
-    {
-       filelist.assertInit();
-
-       list<string> ret;
-       for (vector<File>::const_iterator it = filelist.begin(); it != filelist.end(); ++it)
-           ret.push_back(it->name);
-
-       return ret;
-    }
-*/
-
-
-    unsigned int
-    getStatus(const string& name, Cmp cmp)
-    {
-       vector<File>::iterator it = files.find(name);
-       if (it != files.end())
-           return it->getStatus(cmp);
-
-       return -1;
-    }
-
-
-    void
-    setRollback(const string& name, bool rollback)
-    {
-       vector<File>::iterator it = files.find(name);
-       if (it != files.end())
-           it->setRollback(rollback);
-    }
-
-
-    bool
-    getRollback(const string& name, bool rollback)
-    {
-       vector<File>::const_iterator it = files.find(name);
-       if (it != files.end())
-           return it->getRollback();
-       return false;
-    }
-
-
     CompareCallback* compare_callback = NULL;
 
     void
index 978ab22b2bf8fb151daaf8b238376c3ef0eff596..0939ee4463f1cb0063ac1bfe0a2ffbdf02a381db 100644 (file)
 
 
 #include <string>
+#include <list>
 
 
 namespace snapper
 {
-    using std::string;
+    using namespace std;
 
 
     enum StatusFlags
@@ -49,28 +50,13 @@ namespace snapper
     };
 
 
-    // use num = 0 for current system
+    class Snapshot;
 
-    void startBackgroundComparsion(unsigned int num1, unsigned int num2);
+    void startBackgroundComparsion(list<Snapshot>::const_iterator snapshot1,
+                                  list<Snapshot>::const_iterator snapshot2);
 
-    bool setComparisonNums(unsigned int num1, unsigned int num2);
-
-    unsigned int getComparisonNum1();
-    unsigned int getComparisonNum2();
-
-
-    // return bitfield of StatusFlags
-    unsigned int getStatus(const string& name, Cmp cmp);
-
-    string getAbsolutePath(const string& name, Location loc);
-
-    void setRollback(const string& name, bool rollback);
-    bool getRollback(const string& name);
-
-    // check rollback? (e.g. to be deleted dirs are empty, required type changes)
-    bool checkRollback();
-
-    bool doRollback();
+    bool setComparisonNums(list<Snapshot>::const_iterator snapshot1,
+                          list<Snapshot>::const_iterator snapshot2);
 
 
     // progress callbacks, e.g. during snapshot comparision, during rollback,
index 928c4103ea49799d76e0506b1e47c1cf334970f2..2cce33f5e11566741cb705822a609e2095930d64 100644 (file)
@@ -39,8 +39,8 @@ namespace snapper
     using std::list;
 
 
-    vector<Snapshot>::const_iterator snapshot1;
-    vector<Snapshot>::const_iterator snapshot2;
+    list<Snapshot>::const_iterator snapshot1;
+    list<Snapshot>::const_iterator snapshot2;
 
     Snapshots snapshots;
 
@@ -116,7 +116,7 @@ namespace snapper
            entries.push_back(snapshot);
        }
 
-       sort(entries.begin(), entries.end());
+       entries.sort();
 
        y2mil("found " << entries.size() << " snapshots");
     }
@@ -258,14 +258,14 @@ namespace snapper
     }
 
 
-    vector<Snapshot>::iterator
+    list<Snapshot>::iterator
     Snapshots::find(unsigned int num)
     {
        return lower_bound(entries.begin(), entries.end(), num, snapshot_num_less);
     }
 
 
-    vector<Snapshot>::const_iterator
+    list<Snapshot>::const_iterator
     Snapshots::find(unsigned int num) const
     {
        return lower_bound(entries.begin(), entries.end(), num, snapshot_num_less);
index 2bf08278a308f6215cc55ca98ad142b629ac48eb..4a65ced34930cea5db1f9c29f6e3b0ec1bf2ffde 100644 (file)
@@ -24,7 +24,7 @@
 #define SNAPSHOT_H
 
 
-#include <vector>
+#include <list>
 
 
 namespace snapper
@@ -84,8 +84,8 @@ namespace snapper
     }
 
 
-    extern vector<Snapshot>::const_iterator snapshot1;
-    extern vector<Snapshot>::const_iterator snapshot2;
+    extern list<Snapshot>::const_iterator snapshot1;
+    extern list<Snapshot>::const_iterator snapshot2;
 
 
     class Snapshots
@@ -96,11 +96,11 @@ namespace snapper
 
        void assertInit();
 
-       vector<Snapshot>::const_iterator begin() const { return entries.begin(); }
-       vector<Snapshot>::const_iterator end() const { return entries.end(); }
+       list<Snapshot>::const_iterator begin() const { return entries.begin(); }
+       list<Snapshot>::const_iterator end() const { return entries.end(); }
 
-       vector<Snapshot>::iterator find(unsigned int num);
-       vector<Snapshot>::const_iterator find(unsigned int num) const;
+       list<Snapshot>::iterator find(unsigned int num);
+       list<Snapshot>::const_iterator find(unsigned int num) const;
 
        unsigned int createSingleSnapshot(string description);
        unsigned int createPreSnapshot(string description);
@@ -116,7 +116,7 @@ namespace snapper
 
        bool initialized;
 
-       vector<Snapshot> entries;
+       list<Snapshot> entries;
 
     };
 
index 087584e62bda2fa15668f3a8de7c070da5082d32..efc2d58e590e9654775d235238959bfb71594c8e 100644 (file)
@@ -40,7 +40,7 @@ void listSnap( const list<string>& args )
     {
     snapshots.assertInit();
 
-    for (vector<Snapshot>::const_iterator it = snapshots.begin(); it != snapshots.end(); ++it)
+    for (list<Snapshot>::const_iterator it = snapshots.begin(); it != snapshots.end(); ++it)
        {
        cout << *it << endl;
        }
@@ -90,7 +90,7 @@ void createSnap( const list<string>& args )
        unsigned int number2 = snapshots.createPostSnapshot(number1);
        if (print_number)
            cout << number2 << endl;
-       startBackgroundComparsion(number1, number2);
+       startBackgroundComparsion(snapshots.find(number1), snapshots.find(number2));
     }
     else
        y2war( "unknown type:\"" << type << "\"" );
@@ -123,7 +123,7 @@ void showDifference( const list<string>& args )
 
     readNums(args, num1, num2);
 
-    setComparisonNums(num1, num2);
+    setComparisonNums(snapshots.find(num1), snapshots.find(num2));
 
     for (vector<File>::const_iterator it = files.begin(); it != files.end(); ++it)
        cout << statusToString(it->getPreToPostStatus()) << " " << it->getName() << endl;
@@ -137,7 +137,7 @@ void doRollback( const list<string>& args )
 
     readNums(args, num1, num2);
 
-    setComparisonNums(num1, num2);
+    setComparisonNums(snapshots.find(num1), snapshots.find(num2));
 
     for (vector<File>::iterator it = files.begin(); it != files.end(); ++it)
        it->setRollback(true);
@@ -180,6 +180,8 @@ main(int argc, char** argv)
 
     setCompareCallback(&compare_callback_impl);
 
+    snapshots.assertInit();
+
     int cnt = optind;
     while( cnt<argc )
        {