fs-util: make symlink_idempotent() optionally create relative link

This commit is contained in:
Yu Watanabe
2018-09-24 18:52:53 +03:00
committed by Lennart Poettering
parent bee13f2e49
commit 6c9c51e5e2
5 changed files with 23 additions and 18 deletions
+16 -1
View File
@@ -346,12 +346,27 @@ int touch(const char *path) {
return touch_file(path, false, USEC_INFINITY, UID_INVALID, GID_INVALID, MODE_INVALID);
}
int symlink_idempotent(const char *from, const char *to) {
int symlink_idempotent(const char *from, const char *to, bool make_relative) {
_cleanup_free_ char *relpath = NULL;
int r;
assert(from);
assert(to);
if (make_relative) {
_cleanup_free_ char *parent = NULL;
parent = dirname_malloc(to);
if (!parent)
return -ENOMEM;
r = path_make_relative(parent, from, &relpath);
if (r < 0)
return r;
from = relpath;
}
if (symlink(from, to) < 0) {
_cleanup_free_ char *p = NULL;