88//! filesystem mounted at a particular directory. It also includes
99//! information on amount of space available and amount of space used.
1010// spell-checker:ignore canonicalized
11- use std:: path:: Path ;
11+ use std:: { ffi :: OsString , path:: Path } ;
1212
1313#[ cfg( unix) ]
1414use uucore:: fsext:: statfs;
@@ -28,7 +28,7 @@ pub(crate) struct Filesystem {
2828 /// When invoking `df` with a positional argument, it displays
2929 /// usage information for the filesystem that contains the given
3030 /// file. If given, this field contains that filename.
31- pub file : Option < String > ,
31+ pub file : Option < OsString > ,
3232
3333 /// Information about the mounted device, mount directory, and related options.
3434 pub mount_info : MountInfo ,
@@ -123,22 +123,22 @@ where
123123
124124impl Filesystem {
125125 // TODO: resolve uuid in `mount_info.dev_name` if exists
126- pub ( crate ) fn new ( mount_info : MountInfo , file : Option < String > ) -> Option < Self > {
126+ pub ( crate ) fn new ( mount_info : MountInfo , file : Option < OsString > ) -> Option < Self > {
127127 let _stat_path = if mount_info. mount_dir . is_empty ( ) {
128128 #[ cfg( unix) ]
129129 {
130- mount_info. dev_name . clone ( )
130+ mount_info. dev_name . clone ( ) . into ( )
131131 }
132132 #[ cfg( windows) ]
133133 {
134134 // On windows, we expect the volume id
135- mount_info. dev_id . clone ( )
135+ mount_info. dev_id . clone ( ) . into ( )
136136 }
137137 } else {
138138 mount_info. mount_dir . clone ( )
139139 } ;
140140 #[ cfg( unix) ]
141- let usage = FsUsage :: new ( statfs ( _stat_path) . ok ( ) ?) ;
141+ let usage = FsUsage :: new ( statfs ( & _stat_path) . ok ( ) ?) ;
142142 #[ cfg( windows) ]
143143 let usage = FsUsage :: new ( Path :: new ( & _stat_path) ) . ok ( ) ?;
144144 Some ( Self {
@@ -154,7 +154,7 @@ impl Filesystem {
154154 pub ( crate ) fn from_mount (
155155 mounts : & [ MountInfo ] ,
156156 mount : & MountInfo ,
157- file : Option < String > ,
157+ file : Option < OsString > ,
158158 ) -> Result < Self , FsError > {
159159 if is_over_mounted ( mounts, mount) {
160160 Err ( FsError :: OverMounted )
@@ -165,7 +165,7 @@ impl Filesystem {
165165
166166 /// Find and create the filesystem from the given mount.
167167 #[ cfg( windows) ]
168- pub ( crate ) fn from_mount ( mount : & MountInfo , file : Option < String > ) -> Result < Self , FsError > {
168+ pub ( crate ) fn from_mount ( mount : & MountInfo , file : Option < OsString > ) -> Result < Self , FsError > {
169169 Self :: new ( mount. clone ( ) , file) . ok_or ( FsError :: MountMissing )
170170 }
171171
@@ -189,7 +189,7 @@ impl Filesystem {
189189 where
190190 P : AsRef < Path > ,
191191 {
192- let file = path. as_ref ( ) . display ( ) . to_string ( ) ;
192+ let file = path. as_ref ( ) . as_os_str ( ) . to_owned ( ) ;
193193 let canonicalize = true ;
194194
195195 let result = mount_info_from_path ( mounts, path, canonicalize) ;
@@ -205,6 +205,8 @@ mod tests {
205205
206206 mod mount_info_from_path {
207207
208+ use std:: ffi:: OsString ;
209+
208210 use uucore:: fsext:: MountInfo ;
209211
210212 use crate :: filesystem:: { FsError , mount_info_from_path} ;
@@ -215,9 +217,9 @@ mod tests {
215217 dev_id : String :: default ( ) ,
216218 dev_name : String :: default ( ) ,
217219 fs_type : String :: default ( ) ,
218- mount_dir : String :: from ( mount_dir) ,
220+ mount_dir : OsString :: from ( mount_dir) ,
219221 mount_option : String :: default ( ) ,
220- mount_root : String :: default ( ) ,
222+ mount_root : OsString :: default ( ) ,
221223 remote : Default :: default ( ) ,
222224 dummy : Default :: default ( ) ,
223225 }
@@ -312,6 +314,8 @@ mod tests {
312314
313315 #[ cfg( not( windows) ) ]
314316 mod over_mount {
317+ use std:: ffi:: OsString ;
318+
315319 use crate :: filesystem:: { Filesystem , FsError , is_over_mounted} ;
316320 use uucore:: fsext:: MountInfo ;
317321
@@ -320,9 +324,9 @@ mod tests {
320324 dev_id : String :: default ( ) ,
321325 dev_name : dev_name. map ( String :: from) . unwrap_or_default ( ) ,
322326 fs_type : String :: default ( ) ,
323- mount_dir : String :: from ( mount_dir) ,
327+ mount_dir : OsString :: from ( mount_dir) ,
324328 mount_option : String :: default ( ) ,
325- mount_root : String :: default ( ) ,
329+ mount_root : OsString :: default ( ) ,
326330 remote : Default :: default ( ) ,
327331 dummy : Default :: default ( ) ,
328332 }
0 commit comments