From: Arvin Schnell Date: Tue, 11 Jan 2011 15:54:02 +0000 (+0100) Subject: - work on interface X-Git-Tag: v0.1.3~558 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=68d9e3d8e2233880fd2eb9ed4cc01916cb7a6ad2;p=thirdparty%2Fsnapper.git - work on interface --- diff --git a/snapper/Snapper.cc b/snapper/Snapper.cc index 8e2c95ca..bb3ffb5d 100644 --- a/snapper/Snapper.cc +++ b/snapper/Snapper.cc @@ -38,23 +38,35 @@ namespace snapper bool initialized = false; - map snapshots; + list 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& + bool + getSnapshot(unsigned int num, Snapshot& snapshot) + { + assertInit(); + + for (list::const_iterator it = snapshots.begin(); + it != snapshots.end(); ++it) + { + if (it->num == num) + { + snapshot = *it; + return true; + } + } + + return false; + } + + + const list& getSnapshots() { assertInit(); @@ -121,10 +157,10 @@ namespace snapper { assertInit(); - for (map::const_iterator it = snapshots.begin(); + for (list::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; } } diff --git a/snapper/Snapper.h b/snapper/Snapper.h index 2653bb37..8d3f3ea7 100644 --- a/snapper/Snapper.h +++ b/snapper/Snapper.h @@ -34,7 +34,26 @@ namespace snapper extern bool initialized; - extern map snapshots; + + extern list snapshots; + + + extern Snapshot& snapshot1; + extern Snapshot& snapshot2; + + extern list files; + + + struct Statuses + { + unsigned int pre_to_post; + unsigned int pre_to_system; + unsigned int post_to_system; + }; + + extern map statuses; + + extern list files_to_rollback; }; diff --git a/snapper/SnapperInterface.h b/snapper/SnapperInterface.h index a1bd5b08..94b9ec5c 100644 --- a/snapper/SnapperInterface.h +++ b/snapper/SnapperInterface.h @@ -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& getSnapshots(); + bool getSnapshot(unsigned int num, Snapshot& snapshot); + + const list& 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& 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 + }