]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- moved some functions
authorArvin Schnell <aschnell@suse.de>
Fri, 4 Feb 2011 09:42:33 +0000 (10:42 +0100)
committerArvin Schnell <aschnell@suse.de>
Fri, 4 Feb 2011 09:42:33 +0000 (10:42 +0100)
snapper/File.h
snapper/Snapper.cc
snapper/Snapper.h
snapper/Snapshot.cc
snapper/Snapshot.h
tools/snapper.cc

index 2aeb2f240677f70e300aae0db8223f1b635bc54e..5c0d3e98c594c64afa7f29a709313bd4d3d2943e 100644 (file)
@@ -98,11 +98,9 @@ namespace snapper
     {
     public:
 
-       Files() : initialized(false) {}
-
-       void assertInit();
+       friend class Snapper;
 
-       bool doRollback();
+       Files() : initialized(false) {}
 
        typedef vector<File>::iterator iterator;
        typedef vector<File>::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<File> entries;
index 308e343ff13ae7fd336889b045e0ddf35271ca58..1fbed5a966469bcf844c0e99c8eeea23efdf695f 100644 (file)
@@ -106,4 +106,11 @@ namespace snapper
        return true;
     }
 
+
+    bool
+    Snapper::doRollback()
+    {
+       return files.doRollback();
+    }
+
 }
index 52e2b314b8ae500f3b3c93a7737ed70635be5866..bfa2603f001cdba722efc361df66a375c9e19cf9 100644 (file)
@@ -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; }
 
index c0361216b63a89beb4bc0637eb0e0702de7feaf5..0fac43075a11c3c8d48a647a9d218441c4e7ea94 100644 (file)
@@ -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));
     }
 
 }
index 9b7b019812813ae9a0758836f6a168fb14d74e85..9891acb39c0504a4cff26ca8846605a866ec2664 100644 (file)
@@ -88,9 +88,9 @@ namespace snapper
     {
     public:
 
-       Snapshots() : initialized(false) {}
+       friend class Snapper;
 
-       void assertInit();
+       Snapshots() : initialized(false) {}
 
        typedef list<Snapshot>::iterator iterator;
        typedef list<Snapshot>::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;
index 491f8f3ef9c153fa30ae5975e813f56c4f5eccc1..d6dc6eb9242d40e1f5907974d743fda596c2ef59 100644 (file)
@@ -132,38 +132,77 @@ void readNums(const list<string>& args, unsigned int& num1, unsigned int& num2)
 }
 
 
-void showDifference( const list<string>& args )
+void
+readNums(const list<string>& args, Snapshots::const_iterator& snap1, Snapshots::const_iterator& snap2)
+{
+    const Snapshots& snapshots = sh->getSnapshots();
+
+    list<string>::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<string>& 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<string>& args )
-    {
-    unsigned int num1 = 0;
-    unsigned int num2 = 0;
+void
+doRollback( const list<string>& 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