Skip to content

Commit 6918d84

Browse files
committed
refactor(df): separate platform-specific logic for stat_path
Split the initialization of `stat_path` in `Filesystem::new` into distinct `#[cfg(unix)]` and `#[cfg(windows)]` blocks. This improves readability and ensures that Windows builds consistently use the volume ID (`dev_id`).
1 parent f1c3436 commit 6918d84

1 file changed

Lines changed: 4 additions & 10 deletions

File tree

src/uu/df/src/filesystem.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,21 +121,15 @@ where
121121
impl Filesystem {
122122
// TODO: resolve uuid in `mount_info.dev_name` if exists
123123
pub(crate) fn new(mount_info: MountInfo, file: Option<OsString>) -> Option<Self> {
124+
#[cfg(unix)]
124125
let stat_path = if mount_info.mount_dir.is_empty() {
125-
#[cfg(unix)]
126-
{
127-
mount_info.dev_name.clone().into()
128-
}
129-
#[cfg(windows)]
130-
{
131-
// On windows, we expect the volume id
132-
mount_info.dev_id.clone().into()
133-
}
126+
mount_info.dev_name.clone().into()
134127
} else {
135128
mount_info.mount_dir.clone()
136129
};
130+
137131
#[cfg(windows)]
138-
let _stat_path = mount_info.dev_id.clone(); // On windows, we expect the volume id
132+
let stat_path = mount_info.dev_id.clone(); // On windows, we expect the volume id
139133

140134
#[cfg(unix)]
141135
let usage = FsUsage::new(statfs(&stat_path).ok()?);

0 commit comments

Comments
 (0)