]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- added loading and saving of filelists
authorArvin Schnell <aschnell@suse.de>
Fri, 14 Jan 2011 10:42:39 +0000 (11:42 +0100)
committerArvin Schnell <aschnell@suse.de>
Fri, 14 Jan 2011 10:42:39 +0000 (11:42 +0100)
snapper/Snapper.cc
tools/compare-dirs.cc

index 9cb785d57b78bd8106c72beef708a0a0267cc5da..85406871fbbccf9c3322bc10d47c1a9b1a7313ba 100644 (file)
@@ -21,6 +21,7 @@
 
 
 #include <glob.h>
+#include <string.h>
 #include <map>
 #include <iostream>
 
@@ -297,7 +298,7 @@ namespace snapper
        string dir1 = SNAPSHOTSDIR "/" + decString(num1) + "/snapshot";
        string dir2 = SNAPSHOTSDIR "/" + decString(num2) + "/snapshot";
 
-       string output = SNAPSHOTSDIR "/" + decString(num2) + "/files-" + decString(num1) + ".txt";
+       string output = SNAPSHOTSDIR "/" + decString(num2) + "/filelist-" + decString(num1) + ".txt";
 
        SystemCmd(COMPAREDIRSBIN " " + quote(dir1) + " " + quote(dir2) + " " + quote(output));
     }
@@ -328,8 +329,10 @@ namespace snapper
 
 
     void
-    compareBtrfsSnapshots()
+    createFilelist()
     {
+       y2mil("num1:" << snapshot1.num << " num2:" << snapshot2.num);
+
        files.clear();
        pre_to_post_status.clear();
 
@@ -337,12 +340,79 @@ namespace snapper
     }
 
 
+    bool
+    loadFilelist()
+    {
+       y2mil("num1:" << snapshot1.num << " num2:" << snapshot2.num);
+
+       files.clear();
+       pre_to_post_status.clear();
+
+       string input = SNAPSHOTSDIR "/" + decString(snapshot2.num) + "/filelist-" +
+           decString(snapshot1.num) + ".txt";
+
+       FILE* file = fopen(input.c_str(), "r");
+       if (file == NULL)
+           return false;
+
+       char* line = NULL;
+       size_t len = 0;
+
+       while (getline(&line, &len, file) != -1)
+       {
+           string file = string(line, 5, strlen(line) - 6);
+
+           files.push_back(file);
+           pre_to_post_status[file] = stringToStatus(string(line, 0, 4));
+       }
+
+       free(line);
+
+       fclose(file);
+
+       return true;
+    }
+
+
+    bool
+    saveFilelist()
+    {
+       y2mil("num1:" << snapshot1.num << " num2:" << snapshot2.num);
+
+       string output = SNAPSHOTSDIR "/" + decString(snapshot2.num) + "/filelist-" +
+           decString(snapshot1.num) + ".txt";
+
+       char* tmp_name = (char*) malloc(output.length() + 12);
+       strcpy(tmp_name, output.c_str());
+       strcat(tmp_name, ".tmp-XXXXXX");
+
+       int fd = mkstemp(tmp_name);
+
+       FILE* file = fdopen(fd, "w");
+
+       for (list<string>::const_iterator it = files.begin(); it != files.end(); ++it)
+           fprintf(file, "%s %s\n", statusToString(getStatus(*it, CMP_PRE_TO_POST)).c_str(), it->c_str());
+
+       fclose(file);
+
+       rename(tmp_name, output.c_str());
+
+       free(tmp_name);
+
+       return true;
+    }
+
+
     const list<string>&
     getFiles()
     {
        if (!files_loaded)
        {
-           compareBtrfsSnapshots();
+           if (!loadFilelist())
+           {
+               createFilelist();
+               saveFilelist();
+           }
 
            files_loaded = true;
        }
index 543cb75d42187bd62c5d0bed58db31e1d43632f3..377cdf6a297527bce0fa8f4f5bb09199672fc01d 100644 (file)
@@ -67,5 +67,7 @@ main(int argc, char** argv)
 
     rename(tmp_name, argv[3]);
 
+    free(tmp_name);
+
     exit(EXIT_SUCCESS);
 }