From: Arvin Schnell Date: Fri, 4 Feb 2011 09:42:33 +0000 (+0100) Subject: - moved some functions X-Git-Tag: v0.1.3~518 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=565b5a56b41459ce4bb7b78c366fe1b6f3329a78;p=thirdparty%2Fsnapper.git - moved some functions --- diff --git a/snapper/File.h b/snapper/File.h index 2aeb2f24..5c0d3e98 100644 --- a/snapper/File.h +++ b/snapper/File.h @@ -98,11 +98,9 @@ namespace snapper { public: - Files() : initialized(false) {} - - void assertInit(); + friend class Snapper; - bool doRollback(); + Files() : initialized(false) {} typedef vector::iterator iterator; typedef vector::const_iterator const_iterator; @@ -118,12 +116,16 @@ namespace snapper private: + void assertInit(); + void initialize(); void create(); bool load(); bool save(); + bool doRollback(); + bool initialized; vector entries; diff --git a/snapper/Snapper.cc b/snapper/Snapper.cc index 308e343f..1fbed5a9 100644 --- a/snapper/Snapper.cc +++ b/snapper/Snapper.cc @@ -106,4 +106,11 @@ namespace snapper return true; } + + bool + Snapper::doRollback() + { + return files.doRollback(); + } + } diff --git a/snapper/Snapper.h b/snapper/Snapper.h index 52e2b314..bfa2603f 100644 --- a/snapper/Snapper.h +++ b/snapper/Snapper.h @@ -57,8 +57,8 @@ namespace snapper void startBackgroundComparsion(Snapshots::const_iterator snapshot1, Snapshots::const_iterator snapshot2); - bool setComparisonNums(Snapshots::const_iterator new_snapshot1, - Snapshots::const_iterator new_snapshot2); + bool setComparisonNums(Snapshots::const_iterator snapshot1, + Snapshots::const_iterator snapshot2); Snapshots::const_iterator getSnapshot1() const { return snapshot1; } Snapshots::const_iterator getSnapshot2() const { return snapshot2; } @@ -66,6 +66,8 @@ namespace snapper Files& getFiles() { return files; } const Files& getFiles() const { return files; } + bool doRollback(); + void setCompareCallback(CompareCallback* p) { compare_callback = p; } CompareCallback* getCompareCallback() const { return compare_callback; } diff --git a/snapper/Snapshot.cc b/snapper/Snapshot.cc index c0361216..0fac4307 100644 --- a/snapper/Snapshot.cc +++ b/snapper/Snapshot.cc @@ -239,24 +239,25 @@ namespace snapper } - inline bool - snapshot_num_less(const Snapshot& snapshot, unsigned int num) + struct num_is { - return snapshot.getNum() < num; - } + num_is(unsigned int num) : num(num) {} + bool operator()(const Snapshot& s) const { return s.getNum() == num; } + const unsigned int num; + }; Snapshots::iterator Snapshots::find(unsigned int num) { - return lower_bound(entries.begin(), entries.end(), num, snapshot_num_less); + return find_if(entries.begin(), entries.end(), num_is(num)); } Snapshots::const_iterator Snapshots::find(unsigned int num) const { - return lower_bound(entries.begin(), entries.end(), num, snapshot_num_less); + return find_if(entries.begin(), entries.end(), num_is(num)); } } diff --git a/snapper/Snapshot.h b/snapper/Snapshot.h index 9b7b0198..9891acb3 100644 --- a/snapper/Snapshot.h +++ b/snapper/Snapshot.h @@ -88,9 +88,9 @@ namespace snapper { public: - Snapshots() : initialized(false) {} + friend class Snapper; - void assertInit(); + Snapshots() : initialized(false) {} typedef list::iterator iterator; typedef list::const_iterator const_iterator; @@ -101,16 +101,18 @@ namespace snapper iterator find(unsigned int num); const_iterator find(unsigned int num) const; - iterator createSingleSnapshot(string description); - iterator createPreSnapshot(string description); - iterator createPostSnapshot(const_iterator pre); - private: + void assertInit(); + void initialize(); void read(); + iterator createSingleSnapshot(string description); + iterator createPreSnapshot(string description); + iterator createPostSnapshot(const_iterator pre); + unsigned int nextNumber(); bool initialized; diff --git a/tools/snapper.cc b/tools/snapper.cc index 491f8f3e..d6dc6eb9 100644 --- a/tools/snapper.cc +++ b/tools/snapper.cc @@ -132,38 +132,77 @@ void readNums(const list& args, unsigned int& num1, unsigned int& num2) } -void showDifference( const list& args ) +void +readNums(const list& args, Snapshots::const_iterator& snap1, Snapshots::const_iterator& snap2) +{ + const Snapshots& snapshots = sh->getSnapshots(); + + list::const_iterator s = args.begin(); + if (s != args.end()) { - unsigned int num1 = 0; - unsigned int num2 = 0; + unsigned int num1 = 0; + if (*s != "current") + *s >> num1; + s++; - readNums(args, num1, num2); + snap1 = snapshots.find(num1); + if (snap1 == snapshots.end()) + { + cerr << "snapshots not found" << endl; + exit(EXIT_FAILURE); + } + } + if (s != args.end()) + { + unsigned int num2 = 0; + if (*s != "current") + *s >> num2; + s++; - const Snapshots& snapshots = sh->getSnapshots(); - sh->setComparisonNums(snapshots.find(num1), snapshots.find(num2)); + snap2 = snapshots.find(num2); + if (snap2 == snapshots.end()) + { + cerr << "snapshots not found" << endl; + exit(EXIT_FAILURE); + } + } + + y2mil("num1:" << snap1->getNum() << " num2:" << snap2->getNum()); +} + + +void +showDifference( const list& args ) +{ + Snapshots::const_iterator snap1; + Snapshots::const_iterator snap2; + + readNums(args, snap1, snap2); + + sh->setComparisonNums(snap1, snap2); const Files& files = sh->getFiles(); for (Files::const_iterator it = files.begin(); it != files.end(); ++it) cout << statusToString(it->getPreToPostStatus()) << " " << it->getName() << endl; - } +} -void doRollback( const list& args ) - { - unsigned int num1 = 0; - unsigned int num2 = 0; +void +doRollback( const list& args ) +{ + Snapshots::const_iterator snap1; + Snapshots::const_iterator snap2; - readNums(args, num1, num2); + readNums(args, snap1, snap2); - const Snapshots& snapshots = sh->getSnapshots(); - sh->setComparisonNums(snapshots.find(num1), snapshots.find(num2)); + sh->setComparisonNums(snap1, snap2); Files& files = sh->getFiles(); for (Files::iterator it = files.begin(); it != files.end(); ++it) it->setRollback(true); - files.doRollback(); - } + sh->doRollback(); +} int