Change symlinks params to target & linkpath

This is what the symlinkat.2 man page uses.

The old naming with 'to' and 'from', where 'to' is the symlink name
and 'from' is the symlink target is very confusing.

Follow-up for 892838911b.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek
2025-09-18 12:36:50 +01:00
committed by Luca Boccassi
parent 3b3af5d020
commit 3b54efe78e
3 changed files with 27 additions and 27 deletions
+17 -17
View File
@@ -423,76 +423,76 @@ int touch(const char *path) {
return touch_file(path, false, USEC_INFINITY, UID_INVALID, GID_INVALID, MODE_INVALID);
}
int symlinkat_idempotent(const char *from, int atfd, const char *to, bool make_relative) {
int symlinkat_idempotent(const char *target, int atfd, const char *linkpath, bool make_relative) {
_cleanup_free_ char *relpath = NULL;
int r;
assert(from);
assert(to);
assert(target);
assert(linkpath);
if (make_relative) {
r = path_make_relative_parent(to, from, &relpath);
r = path_make_relative_parent(linkpath, target, &relpath);
if (r < 0)
return r;
from = relpath;
target = relpath;
}
if (symlinkat(from, atfd, to) < 0) {
if (symlinkat(target, atfd, linkpath) < 0) {
_cleanup_free_ char *p = NULL;
if (errno != EEXIST)
return -errno;
r = readlinkat_malloc(atfd, to, &p);
r = readlinkat_malloc(atfd, linkpath, &p);
if (r == -EINVAL) /* Not a symlink? In that case return the original error we encountered: -EEXIST */
return -EEXIST;
if (r < 0) /* Any other error? In that case propagate it as is */
return r;
if (!streq(p, from)) /* Not the symlink we want it to be? In that case, propagate the original -EEXIST */
if (!streq(p, target)) /* Not the symlink we want it to be? In that case, propagate the original -EEXIST */
return -EEXIST;
}
return 0;
}
int symlinkat_atomic_full(const char *from, int atfd, const char *to, SymlinkFlags flags) {
int symlinkat_atomic_full(const char *target, int atfd, const char *linkpath, SymlinkFlags flags) {
int r;
assert(from);
assert(to);
assert(target);
assert(linkpath);
_cleanup_free_ char *relpath = NULL;
if (FLAGS_SET(flags, SYMLINK_MAKE_RELATIVE)) {
r = path_make_relative_parent(to, from, &relpath);
r = path_make_relative_parent(linkpath, target, &relpath);
if (r < 0)
return r;
from = relpath;
target = relpath;
}
_cleanup_free_ char *t = NULL;
r = tempfn_random(to, NULL, &t);
r = tempfn_random(linkpath, NULL, &t);
if (r < 0)
return r;
bool call_label_ops_post = false;
if (FLAGS_SET(flags, SYMLINK_LABEL)) {
r = label_ops_pre(atfd, to, S_IFLNK);
r = label_ops_pre(atfd, linkpath, S_IFLNK);
if (r < 0)
return r;
call_label_ops_post = true;
}
r = RET_NERRNO(symlinkat(from, atfd, t));
r = RET_NERRNO(symlinkat(target, atfd, t));
if (call_label_ops_post)
RET_GATHER(r, label_ops_post(atfd, t, /* created= */ r >= 0));
if (r < 0)
return r;
r = RET_NERRNO(renameat(atfd, t, atfd, to));
r = RET_NERRNO(renameat(atfd, t, atfd, linkpath));
if (r < 0) {
(void) unlinkat(atfd, t, 0);
return r;