crates/veilvoice-setup/src/space.rs
veilvoice-setup · 171 lines · read the source here · or on GitHub
How much room is actually free where VeilVoice keeps things.
Why this is measured rather than assumed
Decoy vaults are only worth making if there is somewhere to put them, and how many to make is a question with a real answer on each machine. A number picked here would be a guess dressed as advice: nine decoys is careless on a nearly full laptop and timid on a four-terabyte disk.
So this asks the operating system, and where the operating system will not say, it returns None and the interface says the count is a suggestion rather than a measurement. Not measuring and not saying so is the answer this module exists to avoid.
No unsafe, and no new dependency
The free-space call is statvfs on Unix and GetDiskFreeSpaceEx on Windows, and reaching either from Rust means an unsafe block or a crate. This workspace forbids the first everywhere and weighs the second against a dependency graph people are invited to read, and neither is worth paying for one integer.
So it runs the tool the platform already ships. On Unix that is df with -Pk, whose output format is specified by POSIX rather than left to the implementation, which is the whole reason that flag is there: the columns are fixed, the block size is 1024, and one line describes the filesystem asked about.
In plain words
Asks the system how much space is free where VeilVoice is putting files, so it can suggest a sensible number of decoy vaults instead of inventing one. If the system will not say, it says so rather than guessing.
WHAT THIS FILE CONTAINS
171 lines defining 5 functions (3 public), 0 types and 0 constants. Everything below is read out of the source, so it cannot disagree with the code.
What happens when it runs. These are the ways in: public, and nothing else in this file calls them, so they are what an outside caller reaches first.
free_bytesline 45 · Free space at path, in bytes, or None if the platform would not say.
reachesunix_free,windows_free,parse_df,parse_fsutil
WHAT CALLS WHAT
The functions this file defines, and the calls between them. An edge means the callee's name appears, called, inside the caller's body. This is a syntactic reading, not a type-resolved one.
The same graph as Mermaid source
%%{init: {"theme":"base","themeVariables":{"background":"#1a1b26","primaryColor":"#1f2335","primaryTextColor":"#c0caf5","primaryBorderColor":"#7aa2f7","secondaryColor":"#16161e","tertiaryColor":"#16161e","lineColor":"#737aa2","textColor":"#c0caf5","mainBkg":"#1f2335","nodeBorder":"#7aa2f7","clusterBkg":"#16161e","clusterBorder":"#2f3549","fontFamily":"ui-monospace, SFMono-Regular, Consolas, monospace","fontSize":"14px"}}}%%
flowchart TD
n_free_bytes(["free_bytes<br/>line 45"])
n_unix_free["unix_free<br/>line 63"]
n_parse_df["parse_df<br/>line 91"]
n_windows_free["windows_free<br/>line 115"]
n_parse_fsutil["parse_fsutil<br/>line 150"]
n_free_bytes --> n_unix_free
n_free_bytes --> n_windows_free
n_unix_free --> n_parse_df
n_windows_free --> n_parse_fsutil
click n_free_bytes href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-setup/src/space.rs#L45" "open the source"
click n_unix_free href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-setup/src/space.rs#L63" "open the source"
click n_parse_df href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-setup/src/space.rs#L91" "open the source"
click n_windows_free href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-setup/src/space.rs#L115" "open the source"
click n_parse_fsutil href "https://github.com/tilas01/veilvoice/blob/main/crates/veilvoice-setup/src/space.rs#L150" "open the source"
classDef entry fill:#1f2335,stroke:#7aa2f7,color:#c0caf5
class n_free_bytes entry
classDef api fill:#1f2335,stroke:#7dcfff,color:#c0caf5
class n_parse_df,n_parse_fsutil api
classDef helper fill:#1f2335,stroke:#bb9af7,color:#c0caf5
class n_unix_free,n_windows_free helper
This site loads no third-party script, so it cannot run Mermaid; the diagram above is the same nodes and edges drawn by the generator instead. GitHub renders the source below directly.
ITEMS
| Item | Line | Documentation |
|---|---|---|
free_bytes pub fn | 45 | Free space at path, in bytes, or None if the platform would not say. |
unix_free fn | 63 | df -Pk, parsed from the format POSIX specifies. |
parse_df pub fn | 91 | The available column of a df -Pk report. |
windows_free fn | 115 | fsutil volume diskfree, which is on every Windows since Vista. |
parse_fsutil pub fn | 150 | The free-bytes figure from fsutil volume diskfree. |