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

Request cloning using COPYFILE_CLONE #232

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion tools/common/file_system.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ bool CopyFile(const std::string &src, const std::string &dest) {
#ifdef __APPLE__
// The `copyfile` function with `COPYFILE_ALL` mode preserves permissions and
// modification time.
return copyfile(src.c_str(), dest.c_str(), nullptr, COPYFILE_ALL) == 0;
return copyfile(src.c_str(), dest.c_str(), nullptr,
COPYFILE_ALL | COPYFILE_CLONE) == 0;
Copy link
Member

Choose a reason for hiding this comment

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

Does this need to be gated on an OS version?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

¯\_(ツ)_/¯ Nothing in copyfile.h mentions versions, there are no uses of availability attributes.

Copy link
Contributor Author

@kastiglione kastiglione May 16, 2019

Choose a reason for hiding this comment

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

We could add a #ifdef COPYFILE_CLONE to be extra safe.

Copy link
Member

Choose a reason for hiding this comment

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

I don't have a machine on any older macOS version than Mojave but we don't expect it to be on any older version since it's related to APFS do we?

Copy link
Member

Choose a reason for hiding this comment

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

For what it's worth, LLVM supports this and checks that it's on macOS 10.12 or greater: https://reviews.llvm.org/rL360174

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does the worker support 10.11 or earlier?

Copy link
Member

Choose a reason for hiding this comment

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

And to finish my thought, I don't know if we care about anyone running such an old version of macOS. I'd say leave it unconditional, and if someone hits a bug because of it, we can patch it then.

Copy link
Member

Choose a reason for hiding this comment

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

How did we both manage to wait an hour to reply at exactly the same time?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

maybe it was lunch 😋

#elif __unix__
// On Linux, we can use `sendfile` to copy it more easily than calling
// `read`/`write` in a loop.
Expand Down
2 changes: 0 additions & 2 deletions tools/worker/work_processor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,6 @@ void WorkProcessor::ProcessWorkRequest(
if (!is_wmo) {
// Copy the output files from the incremental storage area back to the
// locations where Bazel declared the files.
// TODO(allevato): Investigate copy-on-write on macOS, or hard-linking in
// general, as a possible optimization.
for (auto expected_object_pair : output_file_map.incremental_outputs()) {
if (!CopyFile(expected_object_pair.second, expected_object_pair.first)) {
std::cerr << "Could not copy " << expected_object_pair.second << " to "
Expand Down