Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unpack_strategy/directory: use mv for nested unpack #18518

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cho-m
Copy link
Member

@cho-m cho-m commented Oct 5, 2024

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

mv should preserve hardlinks and allow faster unpack on the same filesystem. A secondary pass is done with cp to copy over attributes onto any existing directories.

We only run this for nested unpacks as most direct Directory strategy usage is for repositories where moving files breaks existing code.

There are also potential user issues that could be due to Apple's cp -l on specific macOS versions. Can consider re-adding cp -l with improved fallback handling if there is noticeable advantages.


This improves performance when pouring bottles if user has brew installed on same filesystem as /tmp directory (~1.2-1.4x when tested via brew reinstall which means direct brew install).


macOS mv man page says:

     As the rename(2) call does not work across file systems, mv uses cp(1) and rm(1) to accomplish the move.  The
     effect is equivalent to:

           rm -f destination_path && \
           cp -pRP source_file destination && \
           rm -rf source_file

Which should essentially be similar to cp -pR when combined with other logic.

@cho-m
Copy link
Member Author

cho-m commented Oct 6, 2024

Will need to think about this a bit more in relation to how we are "unpacking" git repositories.

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth a try once 🟢 and you're ready, thanks!

Library/Homebrew/unpack_strategy/directory.rb Outdated Show resolved Hide resolved
@cho-m cho-m force-pushed the unpack-with-mv branch 2 times, most recently from 67f555c to a803cfe Compare October 19, 2024 01:20
`mv` should preserve hardlinks and allow faster unpack on the same
filesystem. A secondary pass is done with `cp` to copy over attributes
onto any existing directories.

We only run this for nested unpacks as most direct Directory strategy
usage is for repositories where moving files breaks existing code.

There are also potential user issues that could be due to Apple's
`cp -l` on specific macOS versions. Can consider re-adding `cp -l` with
improved fallback handling if there is noticeable advantages.
@cho-m cho-m changed the title unpack_strategy/directory: use FileUtils.mv unpack_strategy/directory: use mv for nested unpack Oct 19, 2024
@cho-m cho-m marked this pull request as ready for review October 19, 2024 13:17
@@ -27,8 +27,8 @@
expect(unpack_dir/"folderSymlink").to be_a_symlink
Copy link
Member Author

@cho-m cho-m Oct 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I need to update these tests to run on both move: true and move: false.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants