commit: 4cc41cb31b2f541937b769dd14765f305657d2ae
parent 09d721ab75fb28f7e2f0fc940be70900c354195f
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Mon, 8 Sep 2025 01:14:59 +0200
cmd/touch: handle link pointing nowhere
Diffstat:
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/cmd/touch.c b/cmd/touch.c
@@ -282,12 +282,12 @@ main(int argc, char *argv[])
int fd = open(file, open_flags, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
if(fd == -1)
{
- if(errno == EISDIR)
+ if(errno == EISDIR || (errno == ELOOP && FIELD_MATCH(open_flags, O_NOFOLLOW)))
{
if(utimensat(AT_FDCWD, file, times, utimensat_flags) != 0)
{
fprintf(stderr,
- "touch: error: Failed setting new times on directory '%s': %s\n",
+ "touch: error: Failed setting new times on file '%s': %s\n",
file,
strerror(errno));
return 1;
diff --git a/test-cmd/touch.sh b/test-cmd/touch.sh
@@ -2,13 +2,14 @@
# SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
# SPDX-License-Identifier: MPL-2.0
+plans=36
+
if ! command -v stat >/dev/null 2>/dev/null; then
echo '1..0 # SKIP: missing command: stat'
exit 0
fi
WD=$(dirname "$0")
-plans=33
target="${WD}/../cmd/touch"
. "${WD}/tap.sh"
@@ -78,3 +79,7 @@ t_cmd --exit=1 empty_str "touch: error: Failed opening file '': No such file or
t_cmd rm_tempfile '' rm "${tempfile}"
t_cmd rm_tempdir '' rm -r "${tempdir}"
+
+t_cmd eloop:setup '' ln -sf /var/empty/enoent eloop
+t eloop '-h eloop'
+t_cmd eloop:clean '' rm -f eloop