From: Arvin Schnell Date: Thu, 20 Jan 2011 11:06:02 +0000 (+0100) Subject: - started work on rollback X-Git-Tag: v0.1.3~533 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c48250050c6f6087c13354fbbdd331e4e73fce28;p=thirdparty%2Fsnapper.git - started work on rollback --- diff --git a/snapper/File.cc b/snapper/File.cc index 44dd4e55..fa0f8681 100644 --- a/snapper/File.cc +++ b/snapper/File.cc @@ -214,4 +214,53 @@ namespace snapper return -1; } + + bool + File::doRollback() + { + if (getPreToPostStatus() == CREATED) + { + cout << "delete " << name << endl; + } + else if (getPreToPostStatus() == DELETED) + { + cout << "create " << name << endl; + } + else + { + cout << "modify " << name << endl; + } + + return true; + } + + + bool + Filelist::doRollback() + { + for (vector::reverse_iterator it = files.rbegin(); it != files.rend(); ++it) + { + if (it->getRollback()) + { + if (it->getPreToPostStatus() == CREATED) + { + it->doRollback(); + } + } + } + + for (vector::iterator it = files.begin(); it != files.end(); ++it) + { + if (it->getRollback()) + { + if (it->getPreToPostStatus() != CREATED) + { + it->doRollback(); + } + } + } + + return true; + } + } diff --git a/snapper/File.h b/snapper/File.h index 97f90c2a..7aa1b607 100644 --- a/snapper/File.h +++ b/snapper/File.h @@ -53,6 +53,8 @@ namespace snapper bool getRollback() const { return rollback; } void setRollback(bool value) { rollback = value; } + bool doRollback(); + private: string name; @@ -80,7 +82,12 @@ namespace snapper void assertInit(); + bool doRollback(); + + vector::iterator begin() { return files.begin(); } vector::const_iterator begin() const { return files.begin(); } + + vector::iterator end() { return files.end(); } vector::const_iterator end() const { return files.end(); } vector::iterator find(const string& name); diff --git a/snapper/Snapshot.cc b/snapper/Snapshot.cc index bfb33205..5cbeac68 100644 --- a/snapper/Snapshot.cc +++ b/snapper/Snapshot.cc @@ -188,7 +188,7 @@ namespace snapper bool - Snapshot::createBtrfsSnapshot() const + Snapshot::createFilesystemSnapshot() const { SystemCmd cmd(BTRFSBIN " subvolume snapshot / " + snapshotDir()); return cmd.retcode() == 0; @@ -207,7 +207,7 @@ namespace snapper snapshots.push_back(snapshot); snapshot.writeInfo(); - snapshot.createBtrfsSnapshot(); + snapshot.createFilesystemSnapshot(); return snapshot.num; } @@ -225,7 +225,7 @@ namespace snapper snapshots.push_back(snapshot); snapshot.writeInfo(); - snapshot.createBtrfsSnapshot(); + snapshot.createFilesystemSnapshot(); return snapshot.num; } @@ -243,7 +243,7 @@ namespace snapper snapshots.push_back(snapshot); snapshot.writeInfo(); - snapshot.createBtrfsSnapshot(); + snapshot.createFilesystemSnapshot(); return snapshot.num; } diff --git a/snapper/Snapshot.h b/snapper/Snapshot.h index dfa7e0b9..b32de636 100644 --- a/snapper/Snapshot.h +++ b/snapper/Snapshot.h @@ -56,7 +56,7 @@ namespace snapper string snapshotDir() const; bool writeInfo() const; - bool createBtrfsSnapshot() const; + bool createFilesystemSnapshot() const; }; diff --git a/tools/snapper.cc b/tools/snapper.cc index d2179c9f..630cf9be 100644 --- a/tools/snapper.cc +++ b/tools/snapper.cc @@ -87,31 +87,56 @@ void createSnap( const list& args ) y2war( "unknown type:\"" << type << "\"" ); } -void showDifference( const list& args ) - { - unsigned n1 = 0; - unsigned n2 = 0; + +void readNums(const list& args, unsigned int& num1, unsigned int& num2) +{ list::const_iterator s = args.begin(); if( s!=args.end() ) { - if( *s != "CURRENT" ) - *s >> n1; + if( *s != "current" ) + *s >> num1; ++s; } if( s!=args.end() ) { - if( *s != "CURRENT" ) - *s >> n2; + if( *s != "current" ) + *s >> num2; ++s; } - y2mil( "n1:" << n1 << " n2:" << n2 ); + y2mil("num1:" << num1 << " num2:" << num2); +} + + +void showDifference( const list& args ) + { + unsigned int num1 = 0; + unsigned int num2 = 0; + + readNums(args, num1, num2); - setComparisonNums(n1, n2); + setComparisonNums(num1, num2); for (vector::const_iterator it = filelist.begin(); it != filelist.end(); ++it) cout << statusToString(it->getPreToPostStatus()) << " " << it->getName() << endl; } + +void doRollback( const list& args ) + { + unsigned int num1 = 0; + unsigned int num2 = 0; + + readNums(args, num1, num2); + + setComparisonNums(num1, num2); + + for (vector::iterator it = filelist.begin(); it != filelist.end(); ++it) + it->setRollback(true); + + filelist.doRollback(); + } + + int main(int argc, char** argv) { @@ -142,6 +167,7 @@ main(int argc, char** argv) cmds["help"] = showHelp; cmds["create"] = createSnap; cmds["diff"] = showDifference; + cmds["rollback"] = doRollback; int cnt = optind; while( cnt