tree-wide: use path_split_prefix_filename() where appropriate

This commit is contained in:
Mike Yuan
2026-02-09 09:07:15 +01:00
parent 18a8ea3377
commit cc9a9d6a15
6 changed files with 22 additions and 39 deletions
+5 -6
View File
@@ -69,15 +69,14 @@ int make_lock_file_for(const char *p, int operation, LockFile *ret) {
assert(p);
assert(ret);
r = path_extract_filename(p, &fn);
r = path_split_prefix_filename(p, &dn, &fn);
if (r < 0)
return r;
r = path_extract_directory(p, &dn);
if (r < 0)
return r;
t = strjoin(dn, "/.#", fn, ".lck");
if (dn)
t = strjoin(dn, "/.#", fn, ".lck");
else
t = strjoin(".#", fn, ".lck");
if (!t)
return -ENOMEM;
+3 -8
View File
@@ -161,17 +161,12 @@ static int tempfn_build(const char *p, const char *pre, const char *post, bool c
if (!d)
return -ENOMEM;
} else {
r = path_extract_directory(p, &d);
if (r < 0 && r != -EDESTADDRREQ) /* EDESTADDRREQ → No directory specified, just a filename */
return r;
r = path_extract_filename(p, &fn);
r = path_split_prefix_filename(p, &d, &fn);
if (r < 0)
return r;
if (strlen(fn) > NAME_MAX - len_add)
/* We cannot simply prepend and append strings to the filename. Let's truncate the filename. */
fn[NAME_MAX - len_add] = '\0';
/* Truncate the filename if it would become too long after mangling. */
strshorten(fn, NAME_MAX - len_add);
}
nf = strjoin(".#", strempty(pre), strempty(fn), strempty(post));