From: Arvin Schnell Date: Tue, 15 Feb 2011 09:45:56 +0000 (+0100) Subject: - work on rollback X-Git-Tag: v0.1.3~484 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0fc4531a01583f27f43a7e34b9473335fda514e9;p=thirdparty%2Fsnapper.git - work on rollback --- diff --git a/snapper/AppUtil.cc b/snapper/AppUtil.cc index 21a84b73..858fec75 100644 --- a/snapper/AppUtil.cc +++ b/snapper/AppUtil.cc @@ -303,25 +303,22 @@ void initDefaultLogger() createLogger("default", path, file); } -bool -readlink(const string& path, string& buf) -{ - char tmp[1024]; - int count = ::readlink(path.c_str(), tmp, sizeof(tmp)); - if (count >= 0) - buf = string(tmp, count); - return count != -1; -} - - bool - readlinkat(int fd, const string& path, string& buf) + int + readlink(const string& path, string& buf) { char tmp[1024]; - int count = ::readlinkat(fd, path.c_str(), tmp, sizeof(tmp)); - if (count >= 0) - buf = string(tmp, count); - return count != -1; + int ret = ::readlink(path.c_str(), tmp, sizeof(tmp)); + if (ret >= 0) + buf = string(tmp, ret); + return ret; + } + + + int + symlink(const string& oldpath, const string& newpath) + { + return ::symlink(oldpath.c_str(), newpath.c_str()); } diff --git a/snapper/AppUtil.h b/snapper/AppUtil.h index 6b0661ff..95216409 100644 --- a/snapper/AppUtil.h +++ b/snapper/AppUtil.h @@ -50,7 +50,8 @@ bool setStatMode(const string& Path_Cv, mode_t val ); list glob(const string& path, int flags); - bool readlink(const string& path, string& buf); + int readlink(const string& path, string& buf); + int symlink(const string& oldpath, const string& newpath); template void classic(StreamType& stream) diff --git a/snapper/File.cc b/snapper/File.cc index e055d43d..ce3ab31a 100644 --- a/snapper/File.cc +++ b/snapper/File.cc @@ -300,50 +300,88 @@ namespace snapper bool File::doRollback() { - if (getPreToPostStatus() == CREATED) + if (getPreToPostStatus() & CREATED || getPreToPostStatus() & TYPE) { cout << "delete " << name << endl; struct stat fs; getLStat(getAbsolutePath(LOC_POST), fs); - if (S_ISREG(fs.st_mode) || S_ISLNK(fs.st_mode)) + switch (fs.st_mode & S_IFMT) { - unlink(getAbsolutePath(LOC_SYSTEM).c_str()); - } - else if (S_ISDIR(fs.st_mode)) - { - rmdir(getAbsolutePath(LOC_SYSTEM).c_str()); + case S_IFDIR: { + rmdir(getAbsolutePath(LOC_SYSTEM).c_str()); + } break; + + case S_IFREG: { + unlink(getAbsolutePath(LOC_SYSTEM).c_str()); + } break; + + case S_IFLNK: { + unlink(getAbsolutePath(LOC_SYSTEM).c_str()); + } break; } } - else if (getPreToPostStatus() == DELETED) + + if (getPreToPostStatus() & DELETED || getPreToPostStatus() & TYPE) { cout << "create " << name << endl; struct stat fs; getLStat(getAbsolutePath(LOC_PRE), fs); - if (S_ISREG(fs.st_mode) || S_ISLNK(fs.st_mode)) + switch (fs.st_mode & S_IFMT) { - SystemCmd cmd(CPBIN " --no-dereference --preserve=mode,ownership,links " + - getAbsolutePath(LOC_PRE) + " " + getAbsolutePath(LOC_SYSTEM)); - } - else if (S_ISDIR(fs.st_mode)) - { - mkdir(getAbsolutePath(LOC_SYSTEM).c_str(), 0777); + case S_IFDIR: { + mkdir(getAbsolutePath(LOC_SYSTEM).c_str(), 0777); + } break; + + case S_IFREG: { + SystemCmd cmd(CPBIN " --preserve=mode,ownership " + + getAbsolutePath(LOC_PRE) + " " + getAbsolutePath(LOC_SYSTEM)); + } break; + + case S_IFLNK: { + string tmp; + readlink(getAbsolutePath(LOC_PRE), tmp); + symlink(tmp, getAbsolutePath(LOC_SYSTEM)); + } break; } } - else + + if (getPreToPostStatus() & (CONTENT | PERMISSIONS | USER | GROUP)) { cout << "modify " << name << endl; struct stat fs; getLStat(getAbsolutePath(LOC_PRE), fs); - if (S_ISREG(fs.st_mode) || S_ISLNK(fs.st_mode)) + if (getPreToPostStatus() & CONTENT) + { + switch (fs.st_mode & S_IFMT) + { + case S_IFREG: { + SystemCmd cmd(CPBIN " --preserve=mode,ownership " + + getAbsolutePath(LOC_PRE) + " " + getAbsolutePath(LOC_SYSTEM)); + } break; + + case S_IFLNK: { + unlink(getAbsolutePath(LOC_SYSTEM).c_str()); + string tmp; + readlink(getAbsolutePath(LOC_PRE), tmp); + symlink(tmp, getAbsolutePath(LOC_SYSTEM)); + } break; + } + } + + if (getPreToPostStatus() & PERMISSIONS) + { + chmod(getAbsolutePath(LOC_SYSTEM).c_str(), fs.st_mode); + } + + if (getPreToPostStatus() & (USER | GROUP)) { - SystemCmd cmd(CPBIN " --no-dereference --preserve=mode,ownership,links " + - getAbsolutePath(LOC_PRE) + " " + getAbsolutePath(LOC_SYSTEM)); + chown(getAbsolutePath(LOC_SYSTEM).c_str(), fs.st_uid, fs.st_gid); } }