ask-password-api: don't accidentally create a dir, when we don't want one

Previously, we were using touch(), which usually works fine, because the
path should always refer to an existing directory, in which case it just
updates the timestamp. However, if the dir does not exist yet (which
shouldn't happen), it would be created as regular file, which is just
wrong.

Hence, let's instead create the dir as dir if it is missing, and then
update its timestamp.
This commit is contained in:
Lennart Poettering
2024-10-21 14:14:16 +02:00
parent f4c3bafd10
commit 2ee6fa552e
3 changed files with 21 additions and 11 deletions
+5 -1
View File
@@ -102,7 +102,11 @@ static int touch_ask_password_directory(AskPasswordFlags flags) {
if (r <= 0)
return r;
r = touch(p);
_cleanup_close_ int fd = open_mkdir(p, O_CLOEXEC, 0755);
if (fd < 0)
return fd;
r = touch_fd(fd, USEC_INFINITY);
if (r < 0)
return r;