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<File>::reverse_iterator it = files.rbegin(); it != files.rend(); ++it)
+ {
+ if (it->getRollback())
+ {
+ if (it->getPreToPostStatus() == CREATED)
+ {
+ it->doRollback();
+ }
+ }
+ }
+
+ for (vector<File>::iterator it = files.begin(); it != files.end(); ++it)
+ {
+ if (it->getRollback())
+ {
+ if (it->getPreToPostStatus() != CREATED)
+ {
+ it->doRollback();
+ }
+ }
+ }
+
+ return true;
+ }
+
}
bool getRollback() const { return rollback; }
void setRollback(bool value) { rollback = value; }
+ bool doRollback();
+
private:
string name;
void assertInit();
+ bool doRollback();
+
+ vector<File>::iterator begin() { return files.begin(); }
vector<File>::const_iterator begin() const { return files.begin(); }
+
+ vector<File>::iterator end() { return files.end(); }
vector<File>::const_iterator end() const { return files.end(); }
vector<File>::iterator find(const string& name);
bool
- Snapshot::createBtrfsSnapshot() const
+ Snapshot::createFilesystemSnapshot() const
{
SystemCmd cmd(BTRFSBIN " subvolume snapshot / " + snapshotDir());
return cmd.retcode() == 0;
snapshots.push_back(snapshot);
snapshot.writeInfo();
- snapshot.createBtrfsSnapshot();
+ snapshot.createFilesystemSnapshot();
return snapshot.num;
}
snapshots.push_back(snapshot);
snapshot.writeInfo();
- snapshot.createBtrfsSnapshot();
+ snapshot.createFilesystemSnapshot();
return snapshot.num;
}
snapshots.push_back(snapshot);
snapshot.writeInfo();
- snapshot.createBtrfsSnapshot();
+ snapshot.createFilesystemSnapshot();
return snapshot.num;
}
string snapshotDir() const;
bool writeInfo() const;
- bool createBtrfsSnapshot() const;
+ bool createFilesystemSnapshot() const;
};
y2war( "unknown type:\"" << type << "\"" );
}
-void showDifference( const list<string>& args )
- {
- unsigned n1 = 0;
- unsigned n2 = 0;
+
+void readNums(const list<string>& args, unsigned int& num1, unsigned int& num2)
+{
list<string>::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<string>& args )
+ {
+ unsigned int num1 = 0;
+ unsigned int num2 = 0;
+
+ readNums(args, num1, num2);
- setComparisonNums(n1, n2);
+ setComparisonNums(num1, num2);
for (vector<File>::const_iterator it = filelist.begin(); it != filelist.end(); ++it)
cout << statusToString(it->getPreToPostStatus()) << " " << it->getName() << endl;
}
+
+void doRollback( const list<string>& args )
+ {
+ unsigned int num1 = 0;
+ unsigned int num2 = 0;
+
+ readNums(args, num1, num2);
+
+ setComparisonNums(num1, num2);
+
+ for (vector<File>::iterator it = filelist.begin(); it != filelist.end(); ++it)
+ it->setRollback(true);
+
+ filelist.doRollback();
+ }
+
+
int
main(int argc, char** argv)
{
cmds["help"] = showHelp;
cmds["create"] = createSnap;
cmds["diff"] = showDifference;
+ cmds["rollback"] = doRollback;
int cnt = optind;
while( cnt<argc )