Skip to content

Commit 65fe95e

Browse files
committed
uucore: fsext: Fix Windows/Mac
Windows handling can be done more properly, but I don't have a machine to test this.
1 parent 9bd4575 commit 65fe95e

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/uu/df/src/filesystem.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

src/uucore/src/lib/features/fsext.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ const MAX_PATH: usize = 266;
1919
static EXIT_ERR: i32 = 1;
2020

2121
#[cfg(any(
22-
windows,
2322
target_os = "freebsd",
2423
target_vendor = "apple",
2524
target_os = "netbsd",
2625
target_os = "openbsd"
2726
))]
27+
use crate::os_str_from_bytes;
2828
#[cfg(windows)]
2929
use crate::show_warning;
3030

@@ -243,6 +243,8 @@ impl MountInfo {
243243
// TODO: support the case when `GetLastError()` returns `ERROR_MORE_DATA`
244244
return None;
245245
}
246+
// TODO: This should probably call `OsString::from_wide`, but unclear if
247+
// terminating zeros need to be striped first.
246248
let mount_root = LPWSTR2String(&mount_root_buf);
247249

248250
let mut fs_type_buf = [0u16; MAX_PATH];
@@ -273,8 +275,8 @@ impl MountInfo {
273275
dev_id: volume_name,
274276
dev_name,
275277
fs_type: fs_type.unwrap_or_default(),
276-
mount_root,
277-
mount_dir: String::new(),
278+
mount_root: mount_root.into(), // TODO: We should figure out how to keep an OsString here.
279+
mount_dir: OsString::new(),
278280
mount_option: String::new(),
279281
remote,
280282
dummy: false,
@@ -302,12 +304,11 @@ impl From<StatFs> for MountInfo {
302304
.to_string_lossy()
303305
.into_owned()
304306
};
305-
let mount_dir = unsafe {
307+
let mount_dir_bytes = unsafe {
306308
// spell-checker:disable-next-line
307-
CStr::from_ptr(&statfs.f_mntonname[0])
308-
.to_string_lossy()
309-
.into_owned()
309+
CStr::from_ptr(&statfs.f_mntonname[0]).to_bytes()
310310
};
311+
let mount_dir = os_str_from_bytes(mount_dir_bytes).unwrap().into_owned();
311312

312313
let dev_id = mount_dev_id(&mount_dir);
313314
let dummy = is_dummy_filesystem(&fs_type, "");
@@ -318,7 +319,7 @@ impl From<StatFs> for MountInfo {
318319
dev_name,
319320
fs_type,
320321
mount_dir,
321-
mount_root: String::new(),
322+
mount_root: OsString::new(),
322323
mount_option: String::new(),
323324
remote,
324325
dummy,

0 commit comments

Comments
 (0)