]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- work on rollback
authorArvin Schnell <aschnell@suse.de>
Tue, 15 Feb 2011 09:45:56 +0000 (10:45 +0100)
committerArvin Schnell <aschnell@suse.de>
Tue, 15 Feb 2011 09:45:56 +0000 (10:45 +0100)
snapper/AppUtil.cc
snapper/AppUtil.h
snapper/File.cc

index 21a84b73086fb73744835efc8dbc3c4d4f517a6e..858fec7568f005acba2798f29b375311788a5b7c 100644 (file)
@@ -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());
     }
 
 
index 6b0661fff8df8c4a8529ef48152998d10d71ea5f..95216409ddfec29463b9c93ccfc198af14972ddf 100644 (file)
@@ -50,7 +50,8 @@ bool setStatMode(const string& Path_Cv, mode_t val );
 
     list<string> 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<class StreamType>
 void classic(StreamType& stream)
index e055d43d4492d939617a44ffda3d5e2ec2d67d78..ce3ab31aeb61a4a621f9c1ba52f896bccf2d8de0 100644 (file)
@@ -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);
            }
        }