From: Tom de Vries <tdevries@suse.de>
To: gdb-patches@sourceware.org
Subject: [PATCH 1/2] [pre-commit] Reject symlinks in check-file-mode
Date: Tue, 1 Sep 2026 22:27:41 +0200 [thread overview]
Message-ID: <20260901202742.320498-2-tdevries@suse.de> (raw)
In-Reply-To: <20260901202742.320498-1-tdevries@suse.de>
In a recent commit I introduced two symlinks.
After reading a bit more about it, I realized that this can be problematic on
platforms without proper support for it [1].
Which is probably also the reason why there aren't any symlinks in the repo
other than those two.
Eliminate the symlinks, and extend check-file-mode to reject symlinks.
While we're at it, move the existing check into a function, and improve
comments and error message a bit.
[1] https://gitforwindows.org/symbolic-links.html
---
.pre-commit-config.yaml | 4 ++
gdb/contrib/check-file-mode.sh | 77 +++++++++++++++++++++++-----------
gdbserver/.shellcheckrc | 4 +-
gdbsupport/.shellcheckrc | 4 +-
4 files changed, 63 insertions(+), 26 deletions(-)
mode change 120000 => 100644 gdbserver/.shellcheckrc
mode change 120000 => 100644 gdbsupport/.shellcheckrc
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 0b4285e6c82..34d2cba40b9 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -151,6 +151,10 @@ repos:
language: unsupported_script
entry: gdb/contrib/check-file-mode.sh
files: *gdb_files
+ # With the default types == [file], because types and types_or are
+ # and-ed, no symlinks will be selected, so we use types == [] instead.
+ types: []
+ types_or: [file, symlink]
- id: &id5 shellcheck
name: *id5
files: '^(gdb|gdbsupport|gdbserver)/'
diff --git a/gdb/contrib/check-file-mode.sh b/gdb/contrib/check-file-mode.sh
index 5a9b0e89fbe..e9cfaf02ce4 100755
--- a/gdb/contrib/check-file-mode.sh
+++ b/gdb/contrib/check-file-mode.sh
@@ -17,30 +17,59 @@
set -e
set -o pipefail
-no_exec_files=()
-for f in "$@"; do
- case $f in
- */*.py \
- | */*.sh \
- | */configure \
- | gdb/gstack-1.in \
- | gdb/gcore-1.in \
- | gdb/po/gdbtext \
- | gdb/make-init-c \
- | gdb/testsuite/lib/notty-wrap )
- continue
- ;;
- *)
- no_exec_files=("${no_exec_files[@]}" "$f")
- ;;
- esac
-done
+# Flag files that are executable, but not meant to be executable.
+check_exec ()
+{
+ no_exec_files=()
+ for f in "$@"; do
+ case $f in
+ */*.py \
+ | */*.sh )
+ # Shell script or python.
+ continue
+ ;;
+ gdb/po/gdbtext \
+ | gdb/make-init-c \
+ | gdb/testsuite/lib/notty-wrap )
+ # Shell script without .sh extension.
+ continue
+ ;;
+ */configure \
+ | gdb/gstack-1.in \
+ | gdb/gcore-1.in )
+ # Used to generate shell script.
+ continue
+ ;;
+ *)
+ no_exec_files=("${no_exec_files[@]}" "$f")
+ ;;
+ esac
+ done
-if [ ${#no_exec_files[@]} -eq 0 ]; then
- exit 0
-fi
+ if [ ${#no_exec_files[@]} -eq 0 ]; then
+ return
+ fi
-# Flag files that are executable, but not meant to be executable.
+ if ! git ls-files --stage -- "${no_exec_files[@]}" \
+ | (! grep '^100755 '); then
+ echo "Found executable mode (100755) on file without .sh or .py"
+ echo "Please fix or add to exception list in $0"
+ exit 1
+ fi
+}
+
+# Flag symlinks. Symlinks are support by git, but can be problematic on
+# platforms without proper support for it [1].
+# [1] https://gitforwindows.org/symbolic-links.html
+check_symlinks ()
+{
+ if ! git ls-files --stage -- "$@" \
+ | (! grep '^120000 '); then
+ echo "Found symlink mode (120000)"
+ echo "Please replace by copy"
+ exit 1
+ fi
+}
-git ls-files --stage -- "${no_exec_files[@]}" \
- | (! grep '^100755 ')
+check_exec "$@"
+check_symlinks "$@"
diff --git a/gdbserver/.shellcheckrc b/gdbserver/.shellcheckrc
deleted file mode 120000
index 2a49a004d21..00000000000
--- a/gdbserver/.shellcheckrc
+++ /dev/null
@@ -1 +0,0 @@
-../gdb/.shellcheckrc
\ No newline at end of file
diff --git a/gdbserver/.shellcheckrc b/gdbserver/.shellcheckrc
new file mode 100644
index 00000000000..91b66edaf7a
--- /dev/null
+++ b/gdbserver/.shellcheckrc
@@ -0,0 +1,3 @@
+# SC2002 was disabled by default in 0.11.0. Turn it on for
+# compatibility with 0.10.0.
+enable=useless-use-of-cat
diff --git a/gdbsupport/.shellcheckrc b/gdbsupport/.shellcheckrc
deleted file mode 120000
index 2a49a004d21..00000000000
--- a/gdbsupport/.shellcheckrc
+++ /dev/null
@@ -1 +0,0 @@
-../gdb/.shellcheckrc
\ No newline at end of file
diff --git a/gdbsupport/.shellcheckrc b/gdbsupport/.shellcheckrc
new file mode 100644
index 00000000000..91b66edaf7a
--- /dev/null
+++ b/gdbsupport/.shellcheckrc
@@ -0,0 +1,3 @@
+# SC2002 was disabled by default in 0.11.0. Turn it on for
+# compatibility with 0.10.0.
+enable=useless-use-of-cat
--
2.51.0
next prev parent reply other threads:[~2026-09-01 20:28 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-01 20:27 [PATCH 0/2] [pre-commit] Two symlink fixes Tom de Vries
2026-09-01 20:27 ` Tom de Vries [this message]
2026-09-01 20:27 ` [PATCH 2/2] [pre-commit] Add check-copies Tom de Vries
2026-09-15 6:54 ` [PATCH 0/2] [pre-commit] Two symlink fixes Tom de Vries
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260901202742.320498-2-tdevries@suse.de \
--to=tdevries@suse.de \
--cc=gdb-patches@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox