From: Arvin Schnell Date: Mon, 17 Jan 2011 15:10:39 +0000 (+0100) Subject: - work on getAbsolutePath and getStatus X-Git-Tag: v0.1.3~539 X-Git-Url: http://git.ipfire.org/gitweb/?a=commitdiff_plain;h=c33e14a604ac825209dabbbd250f3acbee478923;p=thirdparty%2Fsnapper.git - work on getAbsolutePath and getStatus --- diff --git a/snapper/Snapper.cc b/snapper/Snapper.cc index 6dbdde46..be5d357e 100644 --- a/snapper/Snapper.cc +++ b/snapper/Snapper.cc @@ -78,6 +78,25 @@ namespace snapper } + string + getAbsolutePath(const string& name, Location loc) + { + switch (loc) + { + case LOC_PRE: + return snapshotDir(snapshot1) + name; + + case LOC_POST: + return snapshotDir(snapshot2) + name; + + case LOC_SYSTEM: + return name; + } + + return "error"; + } + + void readSnapshots() { @@ -459,22 +478,59 @@ namespace snapper unsigned int - getStatus(const string& name, Cmp cmp) + File::getPreToPostStatus() { - vector::const_iterator it = filelist.find(name); - if (it != filelist.end()) + return pre_to_post_status; + } + + + unsigned int + File::getPreToSystemStatus() + { + if (pre_to_system_status == (unsigned int)(-1)) + pre_to_system_status = cmpFiles(getAbsolutePath(name, LOC_PRE), + getAbsolutePath(name, LOC_SYSTEM)); + return pre_to_system_status; + } + + + unsigned int + File::getPostToSystemStatus() + { + if (post_to_system_status == (unsigned int)(-1)) + post_to_system_status = cmpFiles(getAbsolutePath(name, LOC_POST), + getAbsolutePath(name, LOC_SYSTEM)); + return post_to_system_status; + } + + + unsigned int + File::getStatus(Cmp cmp) + { + switch (cmp) { - switch (cmp) - { - case CMP_PRE_TO_POST: - return it->pre_to_post_status; - case CMP_PRE_TO_SYSTEM: - return it->pre_to_system_status; - case CMP_POST_TO_SYSTEM: - return it->post_to_system_status; - } + case CMP_PRE_TO_POST: + return getPreToPostStatus(); + + case CMP_PRE_TO_SYSTEM: + return getPreToSystemStatus(); + + case CMP_POST_TO_SYSTEM: + return getPostToSystemStatus(); } return -1; } + + + unsigned int + getStatus(const string& name, Cmp cmp) + { + vector::iterator it = filelist.find(name); + if (it != filelist.end()) + return it->getStatus(cmp); + + return -1; + } + } diff --git a/snapper/Snapper.h b/snapper/Snapper.h index 6b947d90..9425d9db 100644 --- a/snapper/Snapper.h +++ b/snapper/Snapper.h @@ -58,6 +58,12 @@ namespace snapper post_to_system_status(-1), rollback(false) {} + unsigned int getPreToPostStatus(); + unsigned int getPreToSystemStatus(); + unsigned int getPostToSystemStatus(); + + unsigned int getStatus(Cmp cmp); + string name; unsigned int pre_to_post_status; // -1 if invalid diff --git a/snapper/SnapperInterface.h b/snapper/SnapperInterface.h index 3b996f11..2afe91de 100644 --- a/snapper/SnapperInterface.h +++ b/snapper/SnapperInterface.h @@ -102,12 +102,12 @@ namespace snapper list getFiles(); // return bitfield of StatusFlags - unsigned int getStatus(const string& file, Cmp cmp); + unsigned int getStatus(const string& name, Cmp cmp); - string getAbsolutePath(const string& file, Location loc); + string getAbsolutePath(const string& name, Location loc); - void setRollback(const string& file, bool rollback); - bool getRollback(const string& file); + 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();