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

Conversation

kastiglione
Copy link
Contributor

This should be a safe simple addition. From man copyfile(3):

Try to clone the file instead. This is a best try flag i.e. if cloning fails, fallback to copying the file.

@@ -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 😋

@kastiglione
Copy link
Contributor Author

Tested with our build, checked with --swiftcopt=-driver-show-incremental

@allevato
Copy link
Member

I initially had some concerns about the clone behavior of "fails if the file already exists", but as long as we can assume that Bazel does the appropriate cleanup of the copy destination (whether sandboxed or not), this should be safe.

@kastiglione
Copy link
Contributor Author

Should we add a fallback second call to copyfile() without _CLONE to handle that case?

@allevato
Copy link
Member

Should we add a fallback second call to copyfile() without _CLONE to handle that case?

I'm not that worried about it right now. I've also already started the internal submit that will merge this 😛

@swiple-rules-gardener swiple-rules-gardener merged commit cf07fdd into bazelbuild:master May 16, 2019
swiple-rules-gardener added a commit that referenced this pull request May 16, 2019
…yfile_clone

PiperOrigin-RevId: 248588535
@kastiglione kastiglione deleted the dl/request-cloning-using-copyfile_clone branch May 16, 2019 20:28
@kastiglione
Copy link
Contributor Author

Thanks

tymurmustafaiev pushed a commit to tymurmustafaiev/rules_swift that referenced this pull request Jul 19, 2023
…-using-copyfile_clone

PiperOrigin-RevId: 248588535
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.

5 participants