Skip to content

Commit

Permalink
Don't use a trailing slash on the find root path
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
EliahKagan committed Apr 9, 2024
1 parent 5075c81 commit 091a423
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions etc/copy-packetline.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 091a423

Please sign in to comment.