From 091a42302006ac47817b03528ca2cdbec03766e3 Mon Sep 17 00:00:00 2001 From: Eliah Kagan Date: Mon, 8 Apr 2024 22:37:55 -0400 Subject: [PATCH] Don't use a trailing slash on the find root path While a command like `find foo` should add a `/` to make paths like `foo/bar`, some find implementations, including in macOS, add their own second slash even when there already was one, so `find foo/` outputs paths like `foo//bar`. (The current POSIX standard seems to forbid this, but it seems early standards did not, and in any case it is the behavior of find even on recent macOS systems.) That broke the copy-packetline.sh script on macOS: - Unsightly extra slashes were added to the headers placed in the copied/generated files inside gix-packetline-blocking/src. - Due to this happening on macOS, the script produced different output on macOS and other systems, preventing a precise portable CI check that the worktree remains clean even after running it. This commit addresses that by not adding a `/` to the path anymore, and making the required slight change to how the source prefix is removed (to be replaced by the target prefix) to accommodate this. That prefix removal was the original reason I had added a `/` originally. It served two purposes: to make the nature of the replacement slightly clearer to human readers, and to safeguard against a prefix that was not a whole path component. The first goal remains valuable but the benefit was slight, so it's okay to lose out on that. The second is no longer needed, because it was related to a way the script was more complex and thus more prone to to error at that time; the associated check was already removed. --- etc/copy-packetline.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/etc/copy-packetline.sh b/etc/copy-packetline.sh index 6f08d9a5e34..56e8e309c24 100755 --- a/etc/copy-packetline.sh +++ b/etc/copy-packetline.sh @@ -111,7 +111,7 @@ function generate_one () { local source_file target_file source_file="$1" - target_file="$target_dir/${source_file#"$source_dir"/}" + target_file="$target_dir${source_file#"$source_dir"}" if test -d "$source_file"; then mkdir -p -- "$target_file" @@ -144,7 +144,7 @@ function generate_all () { fail 'unable to remove target location' fi - find "$source_dir/" -print0 | while IFS= read -r -d '' source_file; do + find "$source_dir" -print0 | while IFS= read -r -d '' source_file; do generate_one "$source_file" done }