]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- work on interface
authorArvin Schnell <aschnell@suse.de>
Tue, 11 Jan 2011 15:54:02 +0000 (16:54 +0100)
committerArvin Schnell <aschnell@suse.de>
Tue, 11 Jan 2011 15:54:02 +0000 (16:54 +0100)
snapper/Snapper.cc
snapper/Snapper.h
snapper/SnapperInterface.h

index 8e2c95ca7a3f75a6e5c986abd746574fcaf954e2..bb3ffb5d00a28ef692f25f544a9f520fde09043e 100644 (file)
@@ -38,23 +38,35 @@ namespace snapper
 
     bool initialized = false;
 
-    map<unsigned int, Snapshot> snapshots;
+    list<Snapshot> snapshots;
+
+
+    Snapshot& snapshot1;
+    Snapshot& snapshot2;
 
 
     std::ostream& operator<<(std::ostream& s, const Snapshot& x)
     {
-       s << "type:" << toString(x.type) << " date:" << x.date;
-
-       if (!x.description.empty())
-           s << " description:" << x.description;
+       s << "type:" << toString(x.type) << " num:" << x.num;
 
        if (x.pre_num != 0)
            s << " pre-num:" << x.pre_num;
 
+       s << " date:" << x.date;
+
+       if (!x.description.empty())
+           s << " description:" << x.description;
+
        return s;
     }
 
 
+    bool operator<(Snapshot a, Snapshot b)
+    {
+       return a.num < b.num;
+    }
+
+
     void
     readSnapshots()
     {
@@ -79,14 +91,19 @@ namespace snapper
                }
            }
 
+           getChildValue(node, "num", snapshot.num);
+           assert(num == snapshot.num);
+
            getChildValue(node, "date", snapshot.date);
 
            getChildValue(node, "description", snapshot.description);
 
            getChildValue(node, "pre_num", snapshot.pre_num);
 
-           snapshots[num] = snapshot;
+           snapshots.push_back(snapshot);
        }
+
+       snapshots.sort();
     }
 
 
@@ -107,7 +124,26 @@ namespace snapper
     }
 
 
-    const map<unsigned int, Snapshot>&
+    bool
+    getSnapshot(unsigned int num, Snapshot& snapshot)
+    {
+       assertInit();
+
+       for (list<Snapshot>::const_iterator it = snapshots.begin();
+            it != snapshots.end(); ++it)
+       {
+           if (it->num == num)
+           {
+               snapshot = *it;
+               return true;
+           }
+       }
+
+       return false;
+    }
+
+
+    const list<Snapshot>&
     getSnapshots()
     {
        assertInit();
@@ -121,10 +157,10 @@ namespace snapper
     {
        assertInit();
 
-       for (map<unsigned int, Snapshot>::const_iterator it = snapshots.begin();
+       for (list<Snapshot>::const_iterator it = snapshots.begin();
             it != snapshots.end(); ++it)
        {
-           cout << it->first << " " << it->second << endl;
+           cout << *it << endl;
        }
     }
 
@@ -137,16 +173,16 @@ namespace snapper
        unsigned int num = 1;
 
        if (!snapshots.empty())
-           num = snapshots.rbegin()->first + 1;
+           num = snapshots.rbegin()->num + 1;
 
        return num;
     }
 
 
     bool
-    writeInfo(unsigned int num, const Snapshot& snapshot)
+    writeInfo(const Snapshot& snapshot)
     {
-       createPath("/snapshots/" + decString(num));
+       createPath("/snapshots/" + decString(snapshot.num));
 
        XmlFile xml;
        xmlNode* node = xmlNewNode("snapshot");
@@ -154,6 +190,8 @@ namespace snapper
 
        setChildValue(node, "type", toString(snapshot.type));
 
+       setChildValue(node, "num", snapshot.num);
+
        setChildValue(node, "date", snapshot.date);
 
        if (snapshot.type == SINGLE || snapshot.type == PRE)
@@ -162,7 +200,7 @@ namespace snapper
        if (snapshot.type == POST)
            setChildValue(node, "pre_num", snapshot.pre_num);
 
-       xml.save("/snapshots/" + decString(num) + "/snapshot.info");
+       xml.save("/snapshots/" + decString(snapshot.num) + "/snapshot.info");
 
        return true;
     }
@@ -173,13 +211,14 @@ namespace snapper
     {
        Snapshot snapshot;
        snapshot.type = SINGLE;
+       snapshot.num = nextSnapshotNumber();
        snapshot.date = datetime();
        snapshot.description = description;
 
-       unsigned int num = nextSnapshotNumber();
-       snapshots[num] = snapshot;
-       writeInfo(num, snapshot);
-       return num;
+       snapshots.push_back(snapshot);
+       writeInfo(snapshot);
+
+       return snapshot.num;
     }
 
 
@@ -188,13 +227,14 @@ namespace snapper
     {
        Snapshot snapshot;
        snapshot.type = PRE;
+       snapshot.num = nextSnapshotNumber();
        snapshot.date = datetime();
        snapshot.description = description;
 
-       unsigned int num = nextSnapshotNumber();
-       snapshots[num] = snapshot;
-       writeInfo(num, snapshot);
-       return num;
+       snapshots.push_back(snapshot);
+       writeInfo(snapshot);
+
+       return snapshot.num;
     }
 
 
@@ -203,13 +243,33 @@ namespace snapper
     {
        Snapshot snapshot;
        snapshot.type = POST;
+       snapshot.num = nextSnapshotNumber();
        snapshot.date = datetime();
        snapshot.pre_num = pre_num;
 
-       unsigned int num = nextSnapshotNumber();
-       snapshots[num] = snapshot;
-       writeInfo(num, snapshot);
-       return num;
+       snapshots.push_back(snapshot);
+       writeInfo(snapshot);
+
+       return snapshot.num;
+    }
+
+
+
+    bool
+    setComparisonNums(unsigned int num1, unsigned int num2)
+    {
+       if (num1 == 0 || !getSnapshot(num1, snapshot1))
+           return false;
+
+       if (num2 != 0 && !getSnapshot(num2, snapshot2))
+           return false;
+
+       if (snapshot1.num != snapshot2.pre_num)
+           return false;
+
+       // load or generate file list
+
+       return true;
     }
 
 }
index 2653bb37d3dd5593536017ef3aa21fcc3e87f399..8d3f3ea74fdf1f31de6fede825df8f4c04330305 100644 (file)
@@ -34,7 +34,26 @@ namespace snapper
 
     extern bool initialized;
 
-    extern map<unsigned int, Snapshot> snapshots;
+
+    extern list<Snapshot> snapshots;
+
+
+    extern Snapshot& snapshot1;
+    extern Snapshot& snapshot2;
+
+    extern list<string> files;
+
+
+    struct Statuses
+    {
+       unsigned int pre_to_post;
+       unsigned int pre_to_system;
+       unsigned int post_to_system;
+    };
+
+    extern map<string, Statuses> statuses;
+
+    extern list<string> files_to_rollback;
 
 };
 
index a1bd5b0854593b86be4edf1474a35a1ca554c615..94b9ec5c6c62d48fc515b17afad4f0659e6115c7 100644 (file)
@@ -43,10 +43,12 @@ namespace snapper
     {
     public:
 
-       Snapshot() : type(SINGLE), pre_num(0) {}
+       Snapshot() : type(SINGLE), num(0), pre_num(0) {}
 
        SnapshotType type;
 
+       unsigned int num;
+
        string date;
 
        string description;     // empty for type=POST
@@ -56,7 +58,9 @@ namespace snapper
     };
 
 
-    const map<unsigned int, Snapshot>& getSnapshots();
+    bool getSnapshot(unsigned int num, Snapshot& snapshot);
+
+    const list<Snapshot>& getSnapshots();
 
     void listSnapshots();      // only for testing
 
@@ -67,6 +71,49 @@ namespace snapper
 
     unsigned int createPostSnapshot(unsigned int pre_num);
 
+
+
+    enum StatusFlags
+    {
+       CREATED = 1, DELETED = 2, TYPE = 4, CONTENT = 8, PERMISSIONS = 16, OWNER = 32
+    };
+
+    enum Cmp
+    {
+       CMP_PRE_TO_POST, CMP_PRE_TO_SYSTEM, CMP_POST_TO_SYSTEM
+    };
+
+    enum Location
+    {
+       LOC_PRE, LOC_POST, LOC_SYSTEM
+    };
+
+
+    // use num = 0 for system
+
+    bool setComparisonNums(unsigned int num1, unsigned int num2);
+
+    unsigned int getComparisonNum1();
+    unsigned int getComparisonNum2();
+
+    const list<string>& getFiles();
+
+    // return bitfield of StatusFlags
+    unsigned int getStatus(const string& file, Cmp cmp);
+
+    string getAbsolutePath(const string& file, Location loc);
+
+    void setRollback(const string& file, bool rollback);
+    bool getRollback(const string& file);
+
+    // check rollback? (e.g. to be deleted dirs are empty, required type changes)
+    bool checkRollback();
+
+    bool doRollback();
+
+
+    // progress callbacks, e.g. during snapshot comparision
+
 }