[llvm] [Support][vfs] Remove can_write check when replacing file (PR #219540)
Michael Kruse via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 28 14:55:27 PDT 2026
https://github.com/Meinersbur updated https://github.com/llvm/llvm-project/pull/219540
>From 7c97aa393792ead8e5a20c0fe31dd150d54f58b4 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Fri, 28 Aug 2026 19:06:02 +0200
Subject: [PATCH 1/3] Remove can_write check
---
llvm/lib/Support/VirtualOutputBackends.cpp | 6 ------
1 file changed, 6 deletions(-)
diff --git a/llvm/lib/Support/VirtualOutputBackends.cpp b/llvm/lib/Support/VirtualOutputBackends.cpp
index 0c6ce825d02d0..56f6408e82f96 100644
--- a/llvm/lib/Support/VirtualOutputBackends.cpp
+++ b/llvm/lib/Support/VirtualOutputBackends.cpp
@@ -314,12 +314,6 @@ Error OnDiskOutputFile::initializeFile(std::optional<int> &FD) {
if (sys::fs::exists(Status)) {
if (!sys::fs::is_regular_file(Status))
Config.setNoAtomicWrite();
-
- // Fail now if we can't write to the final destination.
- if (!sys::fs::can_write(OutputPath))
- return make_error<OutputError>(
- OutputPath,
- std::make_error_code(std::errc::operation_not_permitted));
}
}
>From 7ba7fff8259d753f1562d2cefe04aedf1edd6612 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Fri, 28 Aug 2026 19:26:14 +0200
Subject: [PATCH 2/3] Keep check in append mode
---
llvm/lib/Support/VirtualOutputBackends.cpp | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/llvm/lib/Support/VirtualOutputBackends.cpp b/llvm/lib/Support/VirtualOutputBackends.cpp
index 56f6408e82f96..a90d9c076fc63 100644
--- a/llvm/lib/Support/VirtualOutputBackends.cpp
+++ b/llvm/lib/Support/VirtualOutputBackends.cpp
@@ -314,6 +314,12 @@ Error OnDiskOutputFile::initializeFile(std::optional<int> &FD) {
if (sys::fs::exists(Status)) {
if (!sys::fs::is_regular_file(Status))
Config.setNoAtomicWrite();
+
+ // Fail now if we can't write to the final destination.
+ if (Config.getAppend() && !sys::fs::can_write(OutputPath))
+ return make_error<OutputError>(
+ OutputPath,
+ std::make_error_code(std::errc::operation_not_permitted));
}
}
>From 358765ae1b4e680e6f8a7291c3468153d39c2ff3 Mon Sep 17 00:00:00 2001
From: Michael Kruse <llvm-project at meinersbur.de>
Date: Fri, 28 Aug 2026 23:55:07 +0200
Subject: [PATCH 3/3] update comments
---
llvm/lib/Support/VirtualOutputBackends.cpp | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/llvm/lib/Support/VirtualOutputBackends.cpp b/llvm/lib/Support/VirtualOutputBackends.cpp
index a90d9c076fc63..91ed0113409af 100644
--- a/llvm/lib/Support/VirtualOutputBackends.cpp
+++ b/llvm/lib/Support/VirtualOutputBackends.cpp
@@ -306,8 +306,8 @@ Error OnDiskOutputFile::initializeFile(std::optional<int> &FD) {
assert(OutputPath != "-" && "Unexpected request for FD of stdout");
// Disable temporary file for other non-regular files, and if we get a status
- // object, also check if we can write and disable write-through buffers if
- // appropriate.
+ // object, also check if in append mode we can write and disable write-through
+ // buffers if appropriate.
if (Config.getAtomicWrite()) {
sys::fs::file_status Status;
sys::fs::status(OutputPath, Status);
@@ -315,7 +315,10 @@ Error OnDiskOutputFile::initializeFile(std::optional<int> &FD) {
if (!sys::fs::is_regular_file(Status))
Config.setNoAtomicWrite();
- // Fail now if we can't write to the final destination.
+ // In append mode, we will open the file for writing which will need write
+ // permission. Fail now if it is already clear that we can't write to the
+ // final destination. Otherwise, we will delete and replace the file.
+ // Permission bits of the file itself are irrelvant in this case.
if (Config.getAppend() && !sys::fs::can_write(OutputPath))
return make_error<OutputError>(
OutputPath,
More information about the llvm-commits
mailing list