Merge pull request #24646 from yuwata/udev-node-symlink_atomic

udev: introduce symlink_atomic_full() and use it
This commit is contained in:
Yu Watanabe
2022-09-19 05:25:58 +09:00
committed by GitHub
5 changed files with 29 additions and 40 deletions
+11 -9
View File
@@ -406,13 +406,7 @@ int symlink_idempotent(const char *from, const char *to, bool make_relative) {
assert(to);
if (make_relative) {
_cleanup_free_ char *parent = NULL;
r = path_extract_directory(to, &parent);
if (r < 0)
return r;
r = path_make_relative(parent, from, &relpath);
r = path_make_relative_parent(to, from, &relpath);
if (r < 0)
return r;
@@ -438,13 +432,21 @@ int symlink_idempotent(const char *from, const char *to, bool make_relative) {
return 0;
}
int symlink_atomic(const char *from, const char *to) {
_cleanup_free_ char *t = NULL;
int symlink_atomic_full(const char *from, const char *to, bool make_relative) {
_cleanup_free_ char *relpath = NULL, *t = NULL;
int r;
assert(from);
assert(to);
if (make_relative) {
r = path_make_relative_parent(to, from, &relpath);
if (r < 0)
return r;
from = relpath;
}
r = tempfn_random(to, NULL, &t);
if (r < 0)
return r;
+4 -1
View File
@@ -58,7 +58,10 @@ static inline int touch(const char *path) {
int symlink_idempotent(const char *from, const char *to, bool make_relative);
int symlink_atomic(const char *from, const char *to);
int symlink_atomic_full(const char *from, const char *to, bool make_relative);
static inline int symlink_atomic(const char *from, const char *to) {
return symlink_atomic_full(from, to, false);
}
int mknod_atomic(const char *path, mode_t mode, dev_t dev);
int mkfifo_atomic(const char *path, mode_t mode);
int mkfifoat_atomic(int dir_fd, const char *path, mode_t mode);