unpack_strategy/directory: try preserving hardlinks #18497
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
brew style
with your changes locally?brew typecheck
with your changes locally?brew tests
with your changes locally?Try running
cp -al
to preserve hardlinks on both macOS and Linux.If that fails, fall back on
cp -a
which can preserve hardlinks on Linux (but not macOS) assuming target filesystem supports them.Originally tried preserving hardlinks in #13154 but the situation with macOS commands was a bit of a pain (
cp
didn't work well,rsync
was slow and had mtime issues,cpio
was a pain to use and could lead to excessive memory as need to stdin every file, etc.).Exploring this again to figure out a general solution for compacting bottle/install sizes in #18478. Given we now only build bottles for Ventura onward, the limitation on
cp -l
is less of an issue.I think fallback on older macOS should be quick as
cp
will fail right away on illegal options, e.g.There is a slow path if
cp -a
fails and falls back tocp -pR
where:-a
(implicit-R
) continues on failure so it adds overhead of adding then removing files. Again should be rare situation as Linux filesystems would usually support hardlinks. Not sure if possible but maybe could create a scenario of install brew on a USB drive.Specific example is again
trino
but this time the bottle which has hardlinks:Before:
After: