]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fs-util: add fsync_path_and_parent_at()
authorLennart Poettering <lennart@poettering.net>
Wed, 3 Feb 2021 19:53:32 +0000 (20:53 +0100)
committerLennart Poettering <lennart@poettering.net>
Thu, 8 Jul 2021 08:22:34 +0000 (10:22 +0200)
src/basic/fs-util.c
src/basic/fs-util.h

index 62c7954c843617ab05e7224adb9a58e5000fdb65..7d7beb13dcfc7a1229fbcba34100ce5754f84d62 100644 (file)
@@ -1508,6 +1508,22 @@ int fsync_parent_at(int at_fd, const char *path) {
         return fsync_directory_of_file(opened_fd);
 }
 
+int fsync_path_and_parent_at(int at_fd, const char *path) {
+        _cleanup_close_ int opened_fd = -1;
+
+        if (isempty(path)) {
+                if (at_fd != AT_FDCWD)
+                        return fsync_full(at_fd);
+
+                opened_fd = open(".", O_RDONLY|O_DIRECTORY|O_CLOEXEC);
+        } else
+                opened_fd = openat(at_fd, path, O_RDONLY|O_NOFOLLOW|O_NONBLOCK|O_CLOEXEC);
+        if (opened_fd < 0)
+                return -errno;
+
+        return fsync_full(opened_fd);
+}
+
 int syncfs_path(int atfd, const char *path) {
         _cleanup_close_ int fd = -1;
 
index c4ab98dbb4ec2545a1093f587baf5d842c75108e..d612cbe404a03419fea7e3c0c105c1e0b1855c1b 100644 (file)
@@ -141,6 +141,7 @@ int fsync_directory_of_file(int fd);
 int fsync_full(int fd);
 int fsync_path_at(int at_fd, const char *path);
 int fsync_parent_at(int at_fd, const char *path);
+int fsync_path_and_parent_at(int at_fd, const char *path);
 
 int syncfs_path(int atfd, const char *path);