From f0fb2943696fca8b908bdb11f1939ad4c8922e51 Mon Sep 17 00:00:00 2001 From: Mike Yuan Date: Mon, 29 Apr 2024 16:23:00 +0800 Subject: [PATCH] fs-util: modernize touch_file a bit --- src/basic/fs-util.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/basic/fs-util.c b/src/basic/fs-util.c index 43836f082ff..b3d5e8a07d2 100644 --- a/src/basic/fs-util.c +++ b/src/basic/fs-util.c @@ -415,17 +415,14 @@ int touch_file(const char *path, bool parents, usec_t stamp, uid_t uid, gid_t gi ret = fchmod_and_chown(fd, mode, uid, gid); if (stamp != USEC_INFINITY) { - struct timespec ts[2]; + struct timespec ts; + timespec_store(&ts, stamp); - timespec_store(&ts[0], stamp); - ts[1] = ts[0]; - r = futimens_opath(fd, ts); + r = futimens_opath(fd, (const struct timespec[2]) { ts, ts }); } else - r = futimens_opath(fd, NULL); - if (r < 0 && ret >= 0) - return r; + r = futimens_opath(fd, /* ts = */ NULL); - return ret; + return RET_GATHER(ret, r); } int symlink_idempotent(const char *from, const char *to, bool make_relative) { -- 2.47.3