This is an archive of the discontinued LLVM Phabricator instance.

Support: Reduce stats in fs::copy_file on Darwin
ClosedPublic

Authored by dexonsmith on Oct 21 2021, 11:08 AM.

Details

Summary

fs::copy_file() on Darwin has a nice optimization to clone the file when
possible. Change the implementation to use clonefile() directly, instead
of the higher-level copyfile(). The latter does the wrong thing for
symlinks, which requires calling stat first...

With that out of the way, optimistically call clonefile() all the time,
and then for any error that's recoverable try again with copyfile()
(without the COPYFILE_CLONE flag, as before).

Diff Detail

Event Timeline

dexonsmith created this revision.Oct 21 2021, 11:08 AM
dexonsmith requested review of this revision.Oct 21 2021, 11:08 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 21 2021, 11:08 AM

Unit test is failing on Windows:

[ RUN      ] FileSystemTest.CopyFileW
C:\ws\w4\llvm-project\premerge-checks\llvm\unittests\Support\Path.cpp(2335): error: fs::create_link(path::filename(Sources[2]), Symlink): did not return errc::success.
error number: 2
error message: no such file or directory
 
[  FAILED  ] FileSystemTest.CopyFileW (874 ms)

Given we don't support creating symlinks on Windows and the behaviour has only changed on Darwin, I'm not sure this is important to debug. Thoughts on making this test #ifndef _WIN32?

JDevlieghere accepted this revision.Oct 25 2021, 10:52 AM

LGTM

Unit test is failing on Windows:

[ RUN      ] FileSystemTest.CopyFileW
C:\ws\w4\llvm-project\premerge-checks\llvm\unittests\Support\Path.cpp(2335): error: fs::create_link(path::filename(Sources[2]), Symlink): did not return errc::success.
error number: 2
error message: no such file or directory
 
[  FAILED  ] FileSystemTest.CopyFileW (874 ms)

Given we don't support creating symlinks on Windows and the behaviour has only changed on Darwin, I'm not sure this is important to debug. Thoughts on making this test #ifndef _WIN32?

Sounds reasonable to me.

This revision is now accepted and ready to land.Oct 25 2021, 10:52 AM
aprantl accepted this revision.Oct 29 2021, 11:04 AM

Nice!

Excluding the fs::create_link() logic on Windows to avoid the failing test.

This revision was automatically updated to reflect the committed changes.