From: Arvin Schnell Date: Tue, 15 Feb 2011 16:20:45 +0000 (+0100) Subject: - always save filelist with num1 < num2 X-Git-Tag: v0.1.3~483 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0b1501df716d3bf373a1b6f2ba56d6004df61b19;p=thirdparty%2Fsnapper.git - always save filelist with num1 < num2 --- diff --git a/snapper/Compare.cc b/snapper/Compare.cc index 5cb3edb5..9b2f6fed 100644 --- a/snapper/Compare.cc +++ b/snapper/Compare.cc @@ -461,4 +461,13 @@ namespace snapper return ret; } + + unsigned int + invertStatus(unsigned int status) + { + if (status & (CREATED | DELETED)) + return status ^ (CREATED | DELETED); + return status; + } + } diff --git a/snapper/Compare.h b/snapper/Compare.h index adb505f9..b17fa756 100644 --- a/snapper/Compare.h +++ b/snapper/Compare.h @@ -48,6 +48,9 @@ namespace snapper unsigned int stringToStatus(const string& str); + unsigned int + invertStatus(unsigned int status); + } diff --git a/snapper/File.cc b/snapper/File.cc index ce3ab31a..202ecd2d 100644 --- a/snapper/File.cc +++ b/snapper/File.cc @@ -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); diff --git a/snapper/Snapper.cc b/snapper/Snapper.cc index 34206440..15b33ce4 100644 --- a/snapper/Snapper.cc +++ b/snapper/Snapper.cc @@ -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());