diff --git a/src/uu/df/src/df.rs b/src/uu/df/src/df.rs index 24dccdae7..bf1964db3 100644 --- a/src/uu/df/src/df.rs +++ b/src/uu/df/src/df.rs @@ -431,7 +431,7 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { let opt = Options::from(&matches).map_err(DfError::OptionsError)?; // Get the list of filesystems to display in the output table. - let filesystems: Vec = match matches.get_many::(OPT_PATHS) { + let filesystems: Vec = match matches.get_many::(OPT_PATHS) { None => { let filesystems = get_all_filesystems(&opt).map_err(|e| { let context = get_message("df-error-cannot-read-table-of-mounted-filesystems"); @@ -611,6 +611,7 @@ pub fn uu_app() -> Command { .arg( Arg::new(OPT_PATHS) .action(ArgAction::Append) + .value_parser(ValueParser::os_string()) .value_hint(clap::ValueHint::AnyPath), ) } diff --git a/src/uu/df/src/filesystem.rs b/src/uu/df/src/filesystem.rs index 53589ae8c..00905ab61 100644 --- a/src/uu/df/src/filesystem.rs +++ b/src/uu/df/src/filesystem.rs @@ -8,7 +8,7 @@ //! filesystem mounted at a particular directory. It also includes //! information on amount of space available and amount of space used. // spell-checker:ignore canonicalized -use std::path::Path; +use std::{ffi::OsString, path::Path}; #[cfg(unix)] use uucore::fsext::statfs; @@ -28,7 +28,7 @@ pub(crate) struct Filesystem { /// When invoking `df` with a positional argument, it displays /// usage information for the filesystem that contains the given /// file. If given, this field contains that filename. - pub file: Option, + pub file: Option, /// Information about the mounted device, mount directory, and related options. pub mount_info: MountInfo, @@ -123,7 +123,7 @@ where impl Filesystem { // TODO: resolve uuid in `mount_info.dev_name` if exists - pub(crate) fn new(mount_info: MountInfo, file: Option) -> Option { + pub(crate) fn new(mount_info: MountInfo, file: Option) -> Option { let _stat_path = if mount_info.mount_dir.is_empty() { #[cfg(unix)] { @@ -154,7 +154,7 @@ impl Filesystem { pub(crate) fn from_mount( mounts: &[MountInfo], mount: &MountInfo, - file: Option, + file: Option, ) -> Result { if is_over_mounted(mounts, mount) { Err(FsError::OverMounted) @@ -189,7 +189,7 @@ impl Filesystem { where P: AsRef, { - let file = path.as_ref().display().to_string(); + let file = path.as_ref().as_os_str().to_owned(); let canonicalize = true; let result = mount_info_from_path(mounts, path, canonicalize); diff --git a/src/uu/df/src/table.rs b/src/uu/df/src/table.rs index e3814df2b..e3725c07b 100644 --- a/src/uu/df/src/table.rs +++ b/src/uu/df/src/table.rs @@ -16,6 +16,7 @@ use crate::{BlockSize, Options}; use uucore::fsext::{FsUsage, MountInfo}; use uucore::locale::get_message; +use std::ffi::OsString; use std::fmt; use std::ops::AddAssign; @@ -25,7 +26,7 @@ use std::ops::AddAssign; /// filesystem device, the mountpoint, the number of bytes used, etc. pub(crate) struct Row { /// The filename given on the command-line, if given. - file: Option, + file: Option, /// Name of the device on which the filesystem lives. fs_device: String, @@ -283,7 +284,12 @@ impl<'a> RowFormatter<'a> { Column::Iused => self.scaled_inodes(self.row.inodes_used), Column::Iavail => self.scaled_inodes(self.row.inodes_free), Column::Ipcent => Self::percentage(self.row.inodes_usage), - Column::File => self.row.file.as_ref().unwrap_or(&"-".into()).to_string(), + Column::File => self + .row + .file + .as_ref() + .map(|s| s.to_string_lossy().into_owned()) + .unwrap_or("-".into()), Column::Fstype => self.row.fs_type.to_string(), #[cfg(target_os = "macos")] @@ -516,7 +522,7 @@ mod tests { impl Default for Row { fn default() -> Self { Self { - file: Some("/path/to/file".to_string()), + file: Some("/path/to/file".into()), fs_device: "my_device".to_string(), fs_type: "my_type".to_string(), fs_mount: "my_mount".to_string(),