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()
{
}
}
+ 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();
}
}
- 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();
{
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;
}
}
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");
setChildValue(node, "type", toString(snapshot.type));
+ setChildValue(node, "num", snapshot.num);
+
setChildValue(node, "date", snapshot.date);
if (snapshot.type == SINGLE || snapshot.type == PRE)
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;
}
{
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;
}
{
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;
}
{
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;
}
}
{
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
};
- const map<unsigned int, Snapshot>& getSnapshots();
+ bool getSnapshot(unsigned int num, Snapshot& snapshot);
+
+ const list<Snapshot>& getSnapshots();
void listSnapshots(); // only for testing
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
+
}