Skip to content

Commit b01b273

Browse files
authored
[Support][Windows] disk_space handle unicode paths (#170716)
replaces GetDiskFreeSpaceExA with GetDiskFreeSpaceExW to handle user paths with Unicode characters fixes: #170571 I’m not entirely sure the fix is correct, so I’d appreciate it if someone more familiar with the code could review it. Thanks!
1 parent 17e0bac commit b01b273

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

llvm/lib/Support/CachePruning.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,9 @@ bool llvm::pruneCache(StringRef Path, CachePruningPolicy Policy,
280280
if (Policy.MaxSizePercentageOfAvailableSpace > 0 || Policy.MaxSizeBytes > 0) {
281281
auto ErrOrSpaceInfo = sys::fs::disk_space(Path);
282282
if (!ErrOrSpaceInfo) {
283-
report_fatal_error("Can't get available size");
283+
auto EC = ErrOrSpaceInfo.getError();
284+
report_fatal_error(Twine("Can't get available size for '") + Path.str() +
285+
"': " + EC.message());
284286
}
285287
sys::fs::space_info SpaceInfo = ErrOrSpaceInfo.get();
286288
auto AvailableSpace = TotalSize + SpaceInfo.free;

llvm/lib/Support/Windows/Path.inc

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,14 +170,19 @@ UniqueID file_status::getUniqueID() const {
170170

171171
ErrorOr<space_info> disk_space(const Twine &Path) {
172172
ULARGE_INTEGER Avail, Total, Free;
173-
if (!::GetDiskFreeSpaceExA(Path.str().c_str(), &Avail, &Total, &Free))
173+
SmallVector<wchar_t, 128> PathUTF16;
174+
175+
if (std::error_code EC = widenPath(Path, PathUTF16))
176+
return EC;
177+
178+
if (!::GetDiskFreeSpaceExW(PathUTF16.data(), &Avail, &Total, &Free))
174179
return mapWindowsError(::GetLastError());
180+
175181
space_info SpaceInfo;
176-
SpaceInfo.capacity =
177-
(static_cast<uint64_t>(Total.HighPart) << 32) + Total.LowPart;
178-
SpaceInfo.free = (static_cast<uint64_t>(Free.HighPart) << 32) + Free.LowPart;
179-
SpaceInfo.available =
180-
(static_cast<uint64_t>(Avail.HighPart) << 32) + Avail.LowPart;
182+
SpaceInfo.capacity = Total.QuadPart;
183+
SpaceInfo.free = Free.QuadPart;
184+
SpaceInfo.available = Avail.QuadPart;
185+
181186
return SpaceInfo;
182187
}
183188

0 commit comments

Comments
 (0)