Skip to content

A fast file manager for Windows and macOS that never freezes: tabs, dual panes, archives as folders, Quick Look-style previews. A File Explorer and Finder alternative written in Rust.

Show external and network volumes' real free space on the Mac Home page

gelenmedyae48da13d8b76
diff --git a/macos/Sources/RustyFiles/HomeView.swift b/macos/Sources/RustyFiles/HomeView.swift
index cc473907..7ae123df 100644
--- a/macos/Sources/RustyFiles/HomeView.swift
+++ b/macos/Sources/RustyFiles/HomeView.swift
@@ -108,6 +108,14 @@ final class HomeView: FlippedView {
let detail: String
}
+ /// A volume's free space. "For important usage" counts what macOS could purge, but on
+ /// external, exFAT and SMB volumes it is 0 rather than missing (issue 758): there the plain
+ /// available capacity is the answer.
+ nonisolated static func freeBytes(_ v: URLResourceValues) -> Int64 {
+ if let important = v.volumeAvailableCapacityForImportantUsage, important > 0 { return important }
+ return Int64(v.volumeAvailableCapacity ?? 0)
+ }
+
static func volumes() -> [Volume] {
let keys: [URLResourceKey] = [
.volumeLocalizedNameKey, .volumeIsLocalKey, .volumeIsRemovableKey, .volumeIsEjectableKey, .volumeIsInternalKey,
@@ -125,7 +133,7 @@ final class HomeView: FlippedView {
icon = "hard-drive"
}
let total = Int64(v?.volumeTotalCapacity ?? 0)
- let free = v?.volumeAvailableCapacityForImportantUsage ?? Int64(v?.volumeAvailableCapacity ?? 0)
+ let free = v.map(freeBytes) ?? 0
let used: Double? = total > 0 ? 1 - Double(free) / Double(total) : nil
let detail = total > 0
? String(localized: "\(formatSize(bytes: UInt64(max(free, 0)))) free / \(formatSize(bytes: UInt64(total)))") : ""
diff --git a/macos/Sources/RustyFiles/SelfTest.swift b/macos/Sources/RustyFiles/SelfTest.swift
index 45e4390d..a502d7db 100644
--- a/macos/Sources/RustyFiles/SelfTest.swift
+++ b/macos/Sources/RustyFiles/SelfTest.swift
@@ -388,6 +388,8 @@ enum SelfTest {
DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
check(!xdone1 && !xdone2 && !fm.fileExists(atPath: xsub.appendingPathComponent("Box").path),
"on exFAT a copy into its own subfolder by a link or other letter case is refused")
+ let vol = try? volume.resourceValues(forKeys: [.volumeAvailableCapacityForImportantUsageKey, .volumeAvailableCapacityKey])
+ check(vol.map { HomeView.freeBytes($0) > 0 } ?? false, "an exFAT disk's free space is not 0 (issue 758)")
_ = hdiutil(["detach", volume.path])
done()
}