fs-util,label: introduce symlink_atomic_full() and symlink_atomic_full_label()

These new functions optionally create symlink of relative path.
This commit is contained in:
Yu Watanabe
2022-09-14 06:22:09 +09:00
parent 449375d2ad
commit 590d81002b
4 changed files with 20 additions and 6 deletions
+10 -2
View File
@@ -432,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);