Skip to content

Commit

Permalink
permit macOS/FreeBSD stat syntax (#23)
Browse files Browse the repository at this point in the history
use macOS/FreeBSD’s `stat -f` or GNU/uutils’s `stat -c`, to format the device and inode numbers, which fixes #22
  • Loading branch information
LucasLarson authored Mar 22, 2023
1 parent 024642e commit 40e40ac
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions bin/samefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,16 @@ main() {

# stat
# `-L` to dereference symbolic links # https://superuser.com/a/196655
# `-c` to display %d for device and
# %i for inode
[ "$(stat -L -c %d:%i "${1}")" = "$(stat -L -c %d:%i "${2}")" ] && return 0 || return 1
# `-c` for GNU to display %d for device and
# %i for inode
# `-f` for BSD/macOS to display %d for device and
# %i for inode
if stat -L -c '%d:%i' -- . >/dev/null 2>&1; then
argument='-c'
else
argument='-f'
fi
[ "$(stat -L "${argument-}" %d:%i "${1}" 2>/dev/null)" = "$(stat -L "${argument-}" %d:%i "${2}")" ] && return 0 || return 1
{ set +x; } 2>/dev/null

}
Expand Down

0 comments on commit 40e40ac

Please sign in to comment.