Skip to content

Commit

Permalink
Request cloning using COPYFILE_CLONE
Browse files Browse the repository at this point in the history
  • Loading branch information
kastiglione committed May 16, 2019
1 parent ee11d3f commit cf07fdd
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
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;
#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

0 comments on commit cf07fdd

Please sign in to comment.