From: Arvin Schnell Date: Thu, 13 Jan 2011 13:57:46 +0000 (+0100) Subject: - use getFiles in cli for diff X-Git-Tag: v0.1.3~551 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8d3abcb79b0cee55e3eff5c9e2ea540855fb7a0d;p=thirdparty%2Fsnapper.git - use getFiles in cli for diff --- diff --git a/cli/cli.cc b/cli/cli.cc index a2803186..f186e15b 100644 --- a/cli/cli.cc +++ b/cli/cli.cc @@ -6,6 +6,7 @@ #include #include #include +#include using namespace snapper; using namespace std; @@ -81,24 +82,11 @@ void showDifference( const list& args ) ++s; } y2mil( "n1:" << n1 << " n2:" << n2 ); - Snapshot sn; - bool ok = true; - if( n1>0 && !getSnapshot( n1, sn )) - { - cerr << "No snapshot with number " << n1 << endl; - ok = false; - } - if( n2>0 && !getSnapshot( n2, sn )) - { - cerr << "No snapshot with number " << n2 << endl; - ok = false; - } - if( ok ) - { - string p1 = (n1==0) ? "/" : "/snapshots/" + decString(n1); - string p2 = (n2==0) ? "/" : "/snapshots/" + decString(n2); - y2mil( "p1:" << p1 << " p2:" << p2 ); - } + + setComparisonNums(n1, n2); + const list& files = getFiles(); + for (list::const_iterator it = files.begin(); it != files.end(); ++it) + cout << statusToString(getStatus(*it, CMP_PRE_TO_POST)) << " " << *it << endl; } int diff --git a/snapper/Files.cc b/snapper/Files.cc index d426249f..abca6010 100644 --- a/snapper/Files.cc +++ b/snapper/Files.cc @@ -361,6 +361,7 @@ namespace snapper cmpDirs(const string& path1, const string& path2, void(*cb)(const string& name, unsigned int status)) { + y2mil("path1:" << path1 << " path2:" << path2); cmpDirsWorker(path1, path2, "", cb); } diff --git a/snapper/Snapper.cc b/snapper/Snapper.cc index 25af17e8..dfad274a 100644 --- a/snapper/Snapper.cc +++ b/snapper/Snapper.cc @@ -31,6 +31,7 @@ #include "snapper/SnapperTmpl.h" #include "snapper/SystemCmd.h" #include "snapper/SnapperDefines.h" +#include "snapper/Files.h" namespace snapper @@ -43,8 +44,17 @@ namespace snapper list snapshots; - Snapshot& snapshot1; - Snapshot& snapshot2; + Snapshot snapshot1; + Snapshot snapshot2; + + + bool files_loaded = false; + + list files; + + map pre_to_post_status; + map pre_to_system_status; + map post_to_system_status; std::ostream& operator<<(std::ostream& s, const Snapshot& x) @@ -269,7 +279,6 @@ namespace snapper } - bool setComparisonNums(unsigned int num1, unsigned int num2) { @@ -282,9 +291,49 @@ namespace snapper if (snapshot1.num != snapshot2.pre_num) return false; - // load or generate file list - return true; } + + void + log(const string& file, unsigned int status) + { + files.push_back(file); + pre_to_post_status[file] = status; + } + + + void + compareBtrfsSnapshots() + { + string dir1 = SNAPSHOTSDIR "/" + decString(snapshot1.num) + "/snapshot"; + string dir2 = SNAPSHOTSDIR "/" + decString(snapshot2.num) + "/snapshot"; + + files.clear(); + pre_to_post_status.clear(); + + cmpDirs(dir1, dir2, log); + } + + + const list& + getFiles() + { + if (!files_loaded) + { + compareBtrfsSnapshots(); + + files_loaded = true; + } + + return files; + } + + + unsigned int + getStatus(const string& file, Cmp cmp) + { + return pre_to_post_status[file]; + } + } diff --git a/snapper/Snapper.h b/snapper/Snapper.h index 8d3f3ea7..d0b7bcbb 100644 --- a/snapper/Snapper.h +++ b/snapper/Snapper.h @@ -38,20 +38,14 @@ namespace snapper extern list snapshots; - extern Snapshot& snapshot1; - extern Snapshot& snapshot2; + 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 map pre_to_post_status; + extern map pre_to_system_status; + extern map post_to_system_status; extern list files_to_rollback;