]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- always save filelist with num1 < num2
authorArvin Schnell <aschnell@suse.de>
Tue, 15 Feb 2011 16:20:45 +0000 (17:20 +0100)
committerArvin Schnell <aschnell@suse.de>
Tue, 15 Feb 2011 16:20:45 +0000 (17:20 +0100)
snapper/Compare.cc
snapper/Compare.h
snapper/File.cc
snapper/Snapper.cc

index 5cb3edb5b686c5f18b0e4d937e3cb4fac44f8f97..9b2f6fed37d42aa1c8b94761c34bfefef939432e 100644 (file)
@@ -461,4 +461,13 @@ namespace snapper
        return ret;
     }
 
+
+    unsigned int
+    invertStatus(unsigned int status)
+    {
+       if (status & (CREATED | DELETED))
+           return status ^ (CREATED | DELETED);
+       return status;
+    }
+
 }
index adb505f989fc722b9be7fa94a708936ac0a14afc..b17fa75601a28c56d501d06c3453b7f2107ca33c 100644 (file)
@@ -48,6 +48,9 @@ namespace snapper
     unsigned int
     stringToStatus(const string& str);
 
+    unsigned int
+    invertStatus(unsigned int status);
+
 }
 
 
index ce3ab31aeb61a4a621f9c1ba52f896bccf2d8de0..202ecd2dab2a8c7e043c53c30099f69e0f990c7a 100644 (file)
@@ -126,8 +126,16 @@ namespace snapper
 
        assert(!snapper->getSnapshot1()->isCurrent() && !snapper->getSnapshot2()->isCurrent());
 
-       string input = snapper->getSnapshot2()->baseDir() + "/filelist-" +
-           decString(snapper->getSnapshot1()->getNum()) + ".txt";
+       unsigned int num1 = snapper->getSnapshot1()->getNum();
+       unsigned int num2 = snapper->getSnapshot2()->getNum();
+
+       bool invert = num1 > num2;
+
+       if (invert)
+           swap(num1, num2);
+
+       string input = snapper->snapshotsDir() + "/" + decString(num2) + "/filelist-" +
+           decString(num1) + ".txt";
 
        FILE* file = fopen(input.c_str(), "r");
        if (file == NULL)
@@ -145,7 +153,12 @@ namespace snapper
 
            string name = string(line, 5, strlen(line) - 6);
 
-           File file(snapper, name, stringToStatus(string(line, 0, 4)));
+           unsigned int status = stringToStatus(string(line, 0, 4));
+
+           if (invert)
+               status = invertStatus(status);
+
+           File file(snapper, name, status);
            entries.push_back(file);
        }
 
@@ -168,8 +181,16 @@ namespace snapper
 
        assert(!snapper->getSnapshot1()->isCurrent() && !snapper->getSnapshot2()->isCurrent());
 
-       string output = snapper->getSnapshot2()->baseDir() + "/filelist-" +
-           decString(snapper->getSnapshot1()->getNum()) + ".txt";
+       unsigned int num1 = snapper->getSnapshot1()->getNum();
+       unsigned int num2 = snapper->getSnapshot2()->getNum();
+
+       bool invert = num1 > num2;
+
+       if (invert)
+           swap(num1, num2);
+
+       string output = snapper->snapshotsDir() + "/" + decString(num2) + "/filelist-" +
+           decString(num1) + ".txt";
 
        char* tmp_name = (char*) malloc(output.length() + 12);
        strcpy(tmp_name, output.c_str());
@@ -180,8 +201,14 @@ namespace snapper
        FILE* file = fdopen(fd, "w");
 
        for (const_iterator it = entries.begin(); it != entries.end(); ++it)
-           fprintf(file, "%s %s\n", statusToString(it->getPreToPostStatus()).c_str(),
-                   it->getName().c_str());
+       {
+           unsigned int status = it->getPreToPostStatus();
+
+           if (invert)
+               status = invertStatus(status);
+
+           fprintf(file, "%s %s\n", statusToString(status).c_str(), it->getName().c_str());
+       }
 
        fclose(file);
 
index 3420644054951024db10c743ca3f1e7b13285f50..15b33ce44471da900233b530099eb214e6e0cee1 100644 (file)
@@ -118,6 +118,11 @@ namespace snapper
 
        y2mil("num1:" << snapshot1->getNum() << " num2:" << snapshot2->getNum());
 
+       bool invert = snapshot1->getNum() > snapshot2->getNum();
+
+       if (invert)
+           swap(snapshot1, snapshot1);
+
        string dir1 = snapshot1->snapshotDir();
        string dir2 = snapshot2->snapshotDir();
 
@@ -133,6 +138,7 @@ namespace snapper
                           Snapshots::const_iterator new_snapshot2)
     {
        assert(new_snapshot1 != snapshots.end() && new_snapshot2 != snapshots.end());
+       assert(new_snapshot1 != new_snapshot2);
 
        y2mil("num1:" << new_snapshot1->getNum() << " num2:" << new_snapshot2->getNum());