Skip to main content

available_bytes

Function available_bytes 

Source
pub fn available_bytes(path: &Path) -> Option<u64>
Expand description

Bytes still writable on the filesystem containing path, or None when the question cannot be answered.

None is not “no space”. It means the probe failed - an unmounted path, a filesystem that does not report statistics, a permissions error - and a caller must treat it as “unknown” rather than as either extreme. Refusing on an unanswerable probe would block writes on any filesystem fs4 cannot read; allowing on it is what the caller does, because a guard that cannot measure has nothing to say.

§A path that does not exist answers differently per platform

On Windows fs4 resolves the path to its volume first (GetVolumePathNameW), which succeeds for a path nothing has created yet, so C:\nope\nope reports C:’s free space. On Unix statvfs needs the path itself and fails.

Neither is wrong - “how much room is there where this would go” is a reasonable question to answer for a path that does not exist yet - so this does not normalize them. Nothing depends on it: the only caller asks about a run’s working directory, which exists by the time anything writes into it. Do not build a “does this path exist” check on top of this.