commit: bc602e3483edec3b68db3fcac9ff760d23c7cfed
parent 7fde5fb371799f705f942768d2afc467781b3b10
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Sat, 13 Sep 2025 04:14:56 +0200
Patch cmd/ln to not error out when recreating the same symlink
Diffstat:
2 files changed, 61 insertions(+), 0 deletions(-)
diff --git a/make-root.sh b/make-root.sh
@@ -217,6 +217,10 @@ ln -s oksh "${out_base}/bin/sh"
gen_oksh_tcc_h > oksh_tcc.h
+cd "${out_base}"/src/utils-std-*
+
+patch -p1 <"${WORKDIR}"/src/utils-std-0.0.9-patches/0001-cmd-ln-change-same-reference-from-error-to-informati.patch || die "Failed patching cmd/ln.c"
+
cd "${out_base}/src"
oyacc=$(echo ./yacc-oyacc-*/)
diff --git a/src/utils-std-0.0.9-patches/0001-cmd-ln-change-same-reference-from-error-to-informati.patch b/src/utils-std-0.0.9-patches/0001-cmd-ln-change-same-reference-from-error-to-informati.patch
@@ -0,0 +1,57 @@
+From c10e309cb4c029629c419d73a2b3f362b42ee65f Mon Sep 17 00:00:00 2001
+From: "Haelwenn (lanodan) Monnier" <contact@hacktivis.me>
+Date: Mon, 8 Sep 2025 19:55:00 +0200
+Subject: [PATCH] cmd/ln: change same reference from error to information
+
+POSIX (2008 and 2024) requires a message to standard error so has
+to be logged. Considering as the action is already done there's
+no need for an errorneous status.
+---
+ cmd/ln.c | 4 ++--
+ test-cmd/ln.sh | 9 ++++++++-
+ 2 files changed, 10 insertions(+), 3 deletions(-)
+
+diff --git a/cmd/ln.c b/cmd/ln.c
+index ad42486..5e866e1 100644
+--- a/cmd/ln.c
++++ b/cmd/ln.c
+@@ -113,10 +113,10 @@ do_link(char *src, char *dest, int destfd)
+ else if(src_stat.st_dev == dest_stat.st_dev && src_stat.st_ino == dest_stat.st_ino)
+ {
+ fprintf(stderr,
+- "ln: error: Source '%s' and destination '%s' refer to the same file\n",
++ "ln: info: Source '%s' and destination '%s' refer to the same file\n",
+ src,
+ dest);
+- return -1;
++ return 0;
+ }
+
+ if(unlink(dest) < 0)
+diff --git a/test-cmd/ln.sh b/test-cmd/ln.sh
+index ca0aa61..39ae619 100755
+--- a/test-cmd/ln.sh
++++ b/test-cmd/ln.sh
+@@ -2,7 +2,7 @@
+ # SPDX-FileCopyrightText: 2017 Haelwenn (lanodan) Monnier <contact+utils@hacktivis.me>
+ # SPDX-License-Identifier: MPL-2.0
+
+-plans=63
++plans=67
+ WD=$(dirname "$0")
+ target="${WD}/../cmd/ln"
+ . "${WD}/tap.sh"
+@@ -107,3 +107,10 @@ t_readlink()
+ " -s /foo/bar/dest_broken_symlink ./
+ t_args 'dest_broken_symlink:force' '' -sf /foo/bar/dest_broken_symlink ./
+ t_cmd 'dest_broken_symlink:cleanup' '' rm dest_broken_symlink
++
++t_args same:create '' -s "$target" same
++t_args --exit=1 same:no_force "ln: error: Destination 'same' already exists
++" -s "$target" same
++t_args same:force "ln: info: Source '$target' and destination 'same' refer to the same file
++" -fs "$target" same
++t_cmd same:cleanup '' rm same
+--
+2.49.1
+