Skip to content

Commit fb1f01b

Browse files
committed
Minor code cleanups.
Simplify `CurDir.as_os_str().as_ref()` to `CurDir.as_ref()`.
1 parent 9e0df91 commit fb1f01b

File tree

6 files changed

+9
-12
lines changed

6 files changed

+9
-12
lines changed

cap-primitives/src/fs/file_path_by_searching.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub(crate) fn file_path_by_searching(file: &fs::File) -> Option<PathBuf> {
1313
// Iterate with `..` until we reach the root directory.
1414
'next_component: loop {
1515
// Open `..`.
16-
let mut iter = read_dir_unchecked(&base, Component::ParentDir.as_os_str().as_ref()).ok()?;
16+
let mut iter = read_dir_unchecked(&base, Component::ParentDir.as_ref()).ok()?;
1717
let metadata = Metadata::from_file(&*base).ok()?;
1818

1919
// Search the children until we find one with matching metadata, and
@@ -24,7 +24,7 @@ pub(crate) fn file_path_by_searching(file: &fs::File) -> Option<PathBuf> {
2424
// Found a match. Record the name and continue to the next component.
2525
components.push(child.file_name());
2626
base = MaybeOwnedFile::owned_noassert(
27-
open_dir_unchecked(&base, Component::ParentDir.as_os_str().as_ref()).ok()?,
27+
open_dir_unchecked(&base, Component::ParentDir.as_ref()).ok()?,
2828
);
2929
continue 'next_component;
3030
}

cap-primitives/src/fs/manually/open.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ impl<'start> Context<'start> {
168168
)?)
169169
}
170170
#[cfg(windows)]
171-
open_dir_unchecked(&self.base, Component::CurDir.as_os_str().as_ref()).map(|_| ())
171+
open_dir_unchecked(&self.base, Component::CurDir.as_ref()).map(|_| ())
172172
}
173173

174174
/// Handle a "." path component.
@@ -440,7 +440,7 @@ pub(super) fn internal_open<'start>(
440440
}
441441
ctx.base = MaybeOwnedFile::owned(open_unchecked(
442442
&ctx.base,
443-
Component::CurDir.as_os_str().as_ref(),
443+
Component::CurDir.as_ref(),
444444
options,
445445
)?);
446446
}

cap-primitives/src/rustix/fs/remove_dir_all_impl.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ pub(crate) fn remove_dir_all_impl(start: &fs::File, path: &Path) -> io::Result<(
1919
}
2020

2121
pub(crate) fn remove_open_dir_all_impl(dir: fs::File) -> io::Result<()> {
22-
remove_dir_all_recursive(read_dir_unchecked(
23-
&dir,
24-
Component::CurDir.as_os_str().as_ref(),
25-
)?)?;
22+
remove_dir_all_recursive(read_dir_unchecked(&dir, Component::CurDir.as_ref())?)?;
2623
remove_open_dir(dir)
2724
}
2825

cap-primitives/src/rustix/fs/remove_open_dir_by_searching.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::{fs, io};
77
/// available.
88
pub(crate) fn remove_open_dir_by_searching(dir: fs::File) -> io::Result<()> {
99
let metadata = Metadata::from_file(&dir)?;
10-
let mut iter = read_dir_unchecked(&dir, Component::ParentDir.as_os_str().as_ref())?;
10+
let mut iter = read_dir_unchecked(&dir, Component::ParentDir.as_ref())?;
1111
while let Some(child) = iter.next() {
1212
let child = child?;
1313
if child.is_same_file(&metadata)? {

cap-primitives/src/windows/fs/read_dir_inner.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ pub(crate) struct ReadDirInner {
1010
impl ReadDirInner {
1111
pub(crate) fn new(start: &fs::File, path: &Path) -> io::Result<Self> {
1212
let dir = open_dir(start, path)?;
13-
Self::new_unchecked(&dir, Component::CurDir.as_os_str().as_ref())
13+
Self::new_unchecked(&dir, Component::CurDir.as_ref())
1414
}
1515

1616
pub(crate) fn read_base_dir(start: &fs::File) -> io::Result<Self> {
17-
Self::new_unchecked(&start, Component::CurDir.as_os_str().as_ref())
17+
Self::new_unchecked(&start, Component::CurDir.as_ref())
1818
}
1919

2020
pub(crate) fn new_unchecked(start: &fs::File, path: &Path) -> io::Result<Self> {

cap-primitives/src/windows/fs/remove_dir_all_impl.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub(crate) fn remove_dir_all_impl(start: &fs::File, path: &Path) -> io::Result<(
2323
}
2424

2525
pub(crate) fn remove_open_dir_all_impl(dir: fs::File) -> io::Result<()> {
26-
remove_dir_all_recursive(&dir, Component::CurDir.as_os_str().as_ref())?;
26+
remove_dir_all_recursive(&dir, Component::CurDir.as_ref())?;
2727
remove_open_dir(dir)
2828
}
2929

0 commit comments

Comments
 (0)