]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- started work on rollback
authorArvin Schnell <aschnell@suse.de>
Thu, 20 Jan 2011 11:06:02 +0000 (12:06 +0100)
committerArvin Schnell <aschnell@suse.de>
Thu, 20 Jan 2011 11:06:02 +0000 (12:06 +0100)
snapper/File.cc
snapper/File.h
snapper/Snapshot.cc
snapper/Snapshot.h
tools/snapper.cc

index 44dd4e55ee9e2bbd3892b0681a222bce3119a92a..fa0f8681e885c82597a5e902e3470d85bea288f3 100644 (file)
@@ -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<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;
+    }
+
 }
index 97f90c2ad4558c02edafffa656ad9f58526887c5..7aa1b6074d877c69a266fe6798924ca81d87eed7 100644 (file)
@@ -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<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);
index bfb3320577d82c68114580119c765dcd51eff90b..5cbeac68ddecd87ba07cfdbba93b0fe4c23b5828 100644 (file)
@@ -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;
     }
index dfa7e0b9014e5147dc033e8f9603423270024339..b32de63698a1540c1feb714100c36d667726f18e 100644 (file)
@@ -56,7 +56,7 @@ namespace snapper
        string snapshotDir() const;
 
        bool writeInfo() const;
-       bool createBtrfsSnapshot() const;
+       bool createFilesystemSnapshot() const;
 
     };
 
index d2179c9f91f65be995956a29bcb9c7f8ec3e7bce..630cf9be98071174fbf601e49937d81c0b5beff6 100644 (file)
@@ -87,31 +87,56 @@ void createSnap( const list<string>& args )
        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)
     {
@@ -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<argc )