]> granicus.if.org Git - llvm/commitdiff
Revert using fcopyfile(3) to implement sys::fs::copy_file(Twine, int) on macOS
authorAdrian Prantl <aprantl@apple.com>
Wed, 24 Apr 2019 19:08:43 +0000 (19:08 +0000)
committerAdrian Prantl <aprantl@apple.com>
Wed, 24 Apr 2019 19:08:43 +0000 (19:08 +0000)
It turns out that I mesread the man page and fcopyfile(3) does not
actually support COPYFILE_CLONE for files.

<rdar://problem/50148757>

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@359127 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/Path.cpp
lib/Support/Unix/Path.inc

index 9466591c25e02504c44ee1523fc57531cc6c3a0e..d60c1359b180b312226cb0fb601e41e6b768a35a 100644 (file)
@@ -935,7 +935,6 @@ std::error_code create_directories(const Twine &Path, bool IgnoreExisting,
   return create_directory(P, IgnoreExisting, Perms);
 }
 
-#ifndef __APPLE__
 static std::error_code copy_file_internal(int ReadFD, int WriteFD) {
   const size_t BufSize = 4096;
   char *Buf = new char[BufSize];
@@ -960,6 +959,7 @@ static std::error_code copy_file_internal(int ReadFD, int WriteFD) {
   return std::error_code();
 }
 
+#ifndef __APPLE__
 std::error_code copy_file(const Twine &From, const Twine &To) {
   int ReadFD, WriteFD;
   if (std::error_code EC = openFileForRead(From, ReadFD, OF_None))
@@ -977,6 +977,7 @@ std::error_code copy_file(const Twine &From, const Twine &To) {
 
   return EC;
 }
+#endif
 
 std::error_code copy_file(const Twine &From, int ToFD) {
   int ReadFD;
@@ -989,7 +990,6 @@ std::error_code copy_file(const Twine &From, int ToFD) {
 
   return EC;
 }
-#endif
 
 ErrorOr<MD5::MD5Result> md5_contents(int FD) {
   MD5 Hash;
index fbe3ed11c59b8bc6fe530a2f60bacb3b78c4f307..0e150d1ac2698f27866a552f2c30ae807722c008 100644 (file)
@@ -1119,6 +1119,9 @@ namespace fs {
 #ifdef __APPLE__
 /// This implementation tries to perform an APFS CoW clone of the file,
 /// which can be much faster and uses less space.
+/// Unfortunately fcopyfile(3) does not support COPYFILE_CLONE, so the
+/// file descriptor variant of this function still uses the default
+/// implementation.
 std::error_code copy_file(const Twine &From, const Twine &To) {
   uint32_t Flag = COPYFILE_DATA;
   if (__builtin_available(macos 10.12, *)) {
@@ -1138,26 +1141,7 @@ std::error_code copy_file(const Twine &From, const Twine &To) {
     return std::error_code();
   return std::error_code(errno, std::generic_category());
 }
-
-/// This implementation tries to perform an APFS CoW clone of the file,
-/// which can be much faster and uses less space.
-std::error_code copy_file(const Twine &From, int ToFD) {
-  int ReadFD;
-  if (std::error_code EC = openFileForRead(From, ReadFD, OF_None))
-    return EC;
-
-  uint32_t Flag = COPYFILE_DATA;
-  if (__builtin_available(macos 10.12, *))
-    Flag = COPYFILE_CLONE;
-
-  int Status = fcopyfile(ReadFD, ToFD, /*State*/ NULL, Flag);
-
-  close(ReadFD);
-  if (Status == 0)
-    return std::error_code();
-  return std::error_code(errno, std::generic_category());
-}
-#endif
+#endif // __APPLE__
 
 } // end namespace fs