[llvm] [Support][Windows] disk_space handle unicode paths (PR #170716)
Pavel Rosický via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 4 16:06:33 PST 2025
https://github.com/ahorek updated https://github.com/llvm/llvm-project/pull/170716
>From 7a0af7caad9f8dcf2535dac41b6eb4e5f41de679 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pavel=20Rosick=C3=BD?= <pavel.rosicky at easy.cz>
Date: Thu, 4 Dec 2025 19:26:54 +0100
Subject: [PATCH] [Support][Windows] disk_space handle unicode paths
---
llvm/lib/Support/CachePruning.cpp | 4 +++-
llvm/lib/Support/Windows/Path.inc | 17 +++++++++++------
2 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/llvm/lib/Support/CachePruning.cpp b/llvm/lib/Support/CachePruning.cpp
index 4eae08b18c9b5..45d4949231fa8 100644
--- a/llvm/lib/Support/CachePruning.cpp
+++ b/llvm/lib/Support/CachePruning.cpp
@@ -280,7 +280,9 @@ bool llvm::pruneCache(StringRef Path, CachePruningPolicy Policy,
if (Policy.MaxSizePercentageOfAvailableSpace > 0 || Policy.MaxSizeBytes > 0) {
auto ErrOrSpaceInfo = sys::fs::disk_space(Path);
if (!ErrOrSpaceInfo) {
- report_fatal_error("Can't get available size");
+ auto EC = ErrOrSpaceInfo.getError();
+ report_fatal_error(Twine("Can't get available size for '") + Path.str() +
+ "': " + EC.message());
}
sys::fs::space_info SpaceInfo = ErrOrSpaceInfo.get();
auto AvailableSpace = TotalSize + SpaceInfo.free;
diff --git a/llvm/lib/Support/Windows/Path.inc b/llvm/lib/Support/Windows/Path.inc
index be007b7abdb51..717a124f9dd19 100644
--- a/llvm/lib/Support/Windows/Path.inc
+++ b/llvm/lib/Support/Windows/Path.inc
@@ -170,14 +170,19 @@ UniqueID file_status::getUniqueID() const {
ErrorOr<space_info> disk_space(const Twine &Path) {
ULARGE_INTEGER Avail, Total, Free;
- if (!::GetDiskFreeSpaceExA(Path.str().c_str(), &Avail, &Total, &Free))
+ SmallVector<wchar_t, 128> PathUTF16;
+
+ if (std::error_code EC = widenPath(Path, PathUTF16))
+ return EC;
+
+ if (!::GetDiskFreeSpaceExW(PathUTF16.data(), &Avail, &Total, &Free))
return mapWindowsError(::GetLastError());
+
space_info SpaceInfo;
- SpaceInfo.capacity =
- (static_cast<uint64_t>(Total.HighPart) << 32) + Total.LowPart;
- SpaceInfo.free = (static_cast<uint64_t>(Free.HighPart) << 32) + Free.LowPart;
- SpaceInfo.available =
- (static_cast<uint64_t>(Avail.HighPart) << 32) + Avail.LowPart;
+ SpaceInfo.capacity = Total.QuadPart;
+ SpaceInfo.free = Free.QuadPart;
+ SpaceInfo.available = Avail.QuadPart;
+
return SpaceInfo;
}
More information about the llvm-commits
mailing list