]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- added exchange function 1136/head
authorArvin Schnell <aschnell@suse.de>
Wed, 27 May 2026 07:07:23 +0000 (09:07 +0200)
committerArvin Schnell <aschnell@suse.de>
Wed, 27 May 2026 07:07:23 +0000 (09:07 +0200)
snapper/FileUtils.cc
snapper/FileUtils.h

index d7951ee164c8424e550c5fb3f24beffd2f93384a..329a53c0a12687b8f523e2ab6153b5467e70ce3f 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "config.h"
 
+#include <cstdio>
 #include <cstring>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -348,22 +349,12 @@ namespace snapper
 
 
     int
-    SDir::rmdir(const string& name) const
+    SDir::unlink(const string& name, int flags) const
     {
        assert(name.find('/') == string::npos);
        assert(name != "..");
 
-       return ::unlinkat(dirfd, name.c_str(), AT_REMOVEDIR);
-    }
-
-
-    int
-    SDir::unlink(const string& name) const
-    {
-       assert(name.find('/') == string::npos);
-       assert(name != "..");
-
-       return ::unlinkat(dirfd, name.c_str(), 0);
+       return ::unlinkat(dirfd, name.c_str(), flags);
     }
 
 
@@ -388,7 +379,7 @@ namespace snapper
 
 
     int
-    SDir::rename(const string& oldname, const string& newname) const
+    SDir::rename(const string& oldname, const string& newname, int flags) const
     {
        assert(oldname.find('/') == string::npos);
        assert(oldname != "..");
@@ -396,7 +387,7 @@ namespace snapper
        assert(newname.find('/') == string::npos);
        assert(newname != "..");
 
-       return ::renameat(dirfd, oldname.c_str(), dirfd, newname.c_str());
+       return ::renameat2(dirfd, oldname.c_str(), dirfd, newname.c_str(), flags);
     }
 
 
index bdbd5c0f3e534e7f28d53434959bf89a35899f95..e2a394adf66cb2e742bf0ed768747de7fd0dadfa 100644 (file)
@@ -91,11 +91,14 @@ namespace snapper
        int open(const string& name, int flags, mode_t mode) const;
        ssize_t readlink(const string& name, string& buf) const;
        int mkdir(const string& name, mode_t mode) const;
-       int rmdir(const string& name) const;
-       int unlink(const string& name) const;
+       int unlink(const string& name, int flags = 0) const;
+       int rmdir(const string& name) const
+           { return unlink(name, AT_REMOVEDIR); }
        int chmod(const string& name, mode_t mode, int flags) const;
        int chown(const string& name, uid_t owner, gid_t group, int flags) const;
-       int rename(const string& oldname, const string& newname) const;
+       int rename(const string& oldname, const string& newname, int flags = 0) const;
+       int exchange(const string& oldname, const string& newname) const
+           { return rename(oldname, newname, RENAME_EXCHANGE); }
        int fsync() const;
 
        // Query size and free.