]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- use getFiles in cli for diff
authorArvin Schnell <aschnell@suse.de>
Thu, 13 Jan 2011 13:57:46 +0000 (14:57 +0100)
committerArvin Schnell <aschnell@suse.de>
Thu, 13 Jan 2011 13:57:46 +0000 (14:57 +0100)
cli/cli.cc
snapper/Files.cc
snapper/Snapper.cc
snapper/Snapper.h

index a28031864743fe2afcf1a92855711eed72bf658d..f186e15bea4d44951c4949024414ee2c99559b87 100644 (file)
@@ -6,6 +6,7 @@
 #include <snapper/Snapper.h>
 #include <snapper/AppUtil.h>
 #include <snapper/SnapperTmpl.h>
+#include <snapper/Files.h>
 
 using namespace snapper;
 using namespace std;
@@ -81,24 +82,11 @@ void showDifference( const list<string>& args )
        ++s;
        }
     y2mil( "n1:" << n1 << " n2:" << n2 );
-    Snapshot sn;
-    bool ok = true;
-    if( n1>0 && !getSnapshot( n1, sn ))
-       {
-       cerr << "No snapshot with number " << n1 << endl;
-       ok = false;
-       }
-    if( n2>0 && !getSnapshot( n2, sn ))
-       {
-       cerr << "No snapshot with number " << n2 << endl;
-       ok = false;
-       }
-    if( ok )
-       {
-       string p1 = (n1==0) ? "/" : "/snapshots/" + decString(n1);
-       string p2 = (n2==0) ? "/" : "/snapshots/" + decString(n2);
-       y2mil( "p1:" << p1 << " p2:" << p2 );
-       }
+
+    setComparisonNums(n1, n2);
+    const list<string>& files = getFiles();
+    for (list<string>::const_iterator it = files.begin(); it != files.end(); ++it)
+       cout << statusToString(getStatus(*it, CMP_PRE_TO_POST)) << " " << *it << endl;
     }
 
 int
index d426249faa30160c73e153667fd241cbf2ad9f55..abca601050aaca8a3a9379f29b5ffbf393dcf66d 100644 (file)
@@ -361,6 +361,7 @@ namespace snapper
     cmpDirs(const string& path1, const string& path2, void(*cb)(const string& name,
                                                                unsigned int status))
     {
+       y2mil("path1:" << path1 << " path2:" << path2);
        cmpDirsWorker(path1, path2, "", cb);
     }
 
index 25af17e83a47273f4a0e91865d15c9d14bcbe947..dfad274a32f287ecf2877903e05ace56a3313e9e 100644 (file)
@@ -31,6 +31,7 @@
 #include "snapper/SnapperTmpl.h"
 #include "snapper/SystemCmd.h"
 #include "snapper/SnapperDefines.h"
+#include "snapper/Files.h"
 
 
 namespace snapper
@@ -43,8 +44,17 @@ namespace snapper
     list<Snapshot> snapshots;
 
 
-    Snapshot& snapshot1;
-    Snapshot& snapshot2;
+    Snapshot snapshot1;
+    Snapshot snapshot2;
+
+
+    bool files_loaded = false;
+
+    list<string> files;
+
+    map<string, unsigned int> pre_to_post_status;
+    map<string, unsigned int> pre_to_system_status;
+    map<string, unsigned int> post_to_system_status;
 
 
     std::ostream& operator<<(std::ostream& s, const Snapshot& x)
@@ -269,7 +279,6 @@ namespace snapper
     }
 
 
-
     bool
     setComparisonNums(unsigned int num1, unsigned int num2)
     {
@@ -282,9 +291,49 @@ namespace snapper
        if (snapshot1.num != snapshot2.pre_num)
            return false;
 
-       // load or generate file list
-
        return true;
     }
 
+
+    void
+    log(const string& file, unsigned int status)
+    {
+       files.push_back(file);
+       pre_to_post_status[file] = status;
+    }
+
+
+    void
+    compareBtrfsSnapshots()
+    {
+       string dir1 = SNAPSHOTSDIR "/" + decString(snapshot1.num) + "/snapshot";
+       string dir2 = SNAPSHOTSDIR "/" + decString(snapshot2.num) + "/snapshot";
+
+       files.clear();
+       pre_to_post_status.clear();
+
+       cmpDirs(dir1, dir2, log);
+    }
+
+
+    const list<string>&
+    getFiles()
+    {
+       if (!files_loaded)
+       {
+           compareBtrfsSnapshots();
+
+           files_loaded = true;
+       }
+
+       return files;
+    }
+
+
+    unsigned int
+    getStatus(const string& file, Cmp cmp)
+    {
+       return pre_to_post_status[file];
+    }
+
 }
index 8d3f3ea74fdf1f31de6fede825df8f4c04330305..d0b7bcbb797c966a11443d02a83bdbd14adc5957 100644 (file)
@@ -38,20 +38,14 @@ namespace snapper
     extern list<Snapshot> snapshots;
 
 
-    extern Snapshot& snapshot1;
-    extern Snapshot& snapshot2;
+    extern Snapshot snapshot1;
+    extern Snapshot snapshot2;
 
     extern list<string> files;
 
-
-    struct Statuses
-    {
-       unsigned int pre_to_post;
-       unsigned int pre_to_system;
-       unsigned int post_to_system;
-    };
-
-    extern map<string, Statuses> statuses;
+    extern map<string, unsigned int> pre_to_post_status;
+    extern map<string, unsigned int> pre_to_system_status;
+    extern map<string, unsigned int> post_to_system_status;
 
     extern list<string> files_to_rollback;