Commit Graph

1 Commits

Author SHA1 Message Date
Samuel Karp
2ab8c12fc8
archive: use Linkat on FreeBSD for hardlinks
Calling link(2) with a symlink as the target will cause FreeBSD to
attempt to create a new hard link pointing to the target of the symlink
rather than a hardlink to the symlink itself. By contrast, Linux creates
a hardlink to the symlink.

Use linkat(2) instead, which accepts a flag controlling this behavior.
If linkat(2) is called with AT_SYMLINK_FOLLOW, it will behave the same
as link(2).  If linkat(2) is called without AT_SYMLINK_FOLLOW, it will
behave the same as Linux's link(2) instead.

See FreeBSD's implementation of ln(1), which uses linkat(2) and controls
this behavior by way of the -P and -L flags:
3003117253/bin/ln/ln.c (L342-L343)

Signed-off-by: Samuel Karp <me@samuelkarp.com>
2022-06-09 18:54:09 -07:00