llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-support

Author: Juan Manuel Martinez Caamaño (jmmartinez)

<details>
<summary>Changes</summary>

If `rename` fails, `TempFile::keep` fell back to `copy_file` regardless of the 
error on Linux, but only on a cross-device error on Windows.

This patch makes the Linux behavior match the Windows one.

As a result, if `rename` fails with any other error (e.g. `EACCES` or `EBUSY`), 
`keep` now returns that error instead of attempting a copy.

There are other places in LLVM where the same thing is done (which may indicate 
that we need a higher-level helper).

* [LLVM's 
`Caching.cpp`](https://github.com/llvm/llvm-project/blob/f5744e07d2dba7367ec68426fd6b6b07e2916b39/llvm/lib/Support/Caching.cpp#L179);
* [LLDB's 
`SymbolLocatorSymStore.cpp`](https://github.com/llvm/llvm-project/blob/f5744e07d2dba7367ec68426fd6b6b07e2916b39/lldb/source/Plugins/SymbolLocator/SymStore/SymbolLocatorSymStore.cpp#L422).

This patch contains no tests since triggering the
`std::errc::cross_device_link` and other error kinds depends on the test 
environment.

---
Full diff: https://github.com/llvm/llvm-project/pull/240318.diff


1 Files Affected:

- (modified) llvm/lib/Support/Path.cpp (+5-4) 


``````````diff
diff --git a/llvm/lib/Support/Path.cpp b/llvm/lib/Support/Path.cpp
index 44011e2858ac2f..c2bca3b19f60a8 100644
--- a/llvm/lib/Support/Path.cpp
+++ b/llvm/lib/Support/Path.cpp
@@ -1338,10 +1338,11 @@ Error TempFile::keep(const Twine &Name) {
 #else
   std::error_code RenameEC = fs::rename(TmpName, Name);
   if (RenameEC) {
-    // If we can't rename, try to copy to work around cross-device link issues.
-    RenameEC = sys::fs::copy_file(TmpName, Name);
-    // Whether the copy succeeded or not, the temporary file is no longer
-    // needed.
+    // If rename failed because it's cross-device, copy instead.
+    if (RenameEC == std::errc::cross_device_link)
+      RenameEC = copy_file(TmpName, Name);
+    // Whether the rename or the copy failed or not, the temporary file is no
+    // longer needed.
     remove(TmpName);
   }
 #endif

``````````

</details>


https://github.com/llvm/llvm-project/pull/240318
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
  • [llvm-branch-commits... Juan Manuel Martinez Caamaño via llvm-branch-commits
    • [llvm-branch-co... via llvm-branch-commits

Reply via email to