mirror of
https://github.com/uutils/coreutils.git
synced 2025-12-23 08:47:37 +00:00
uucore/safe_traversal: remove unnecessary vars
and use into_owned() instead of to_string()
This commit is contained in:
parent
61aec2c195
commit
6464355688
1 changed files with 4 additions and 8 deletions
|
|
@ -133,7 +133,6 @@ pub struct DirFd {
|
|||
impl DirFd {
|
||||
/// Open a directory and return a file descriptor
|
||||
pub fn open(path: &Path) -> io::Result<Self> {
|
||||
let path_str = path.to_string_lossy();
|
||||
let path_cstr = CString::new(path.as_os_str().as_bytes())
|
||||
.map_err(|_| SafeTraversalError::PathContainsNull)?;
|
||||
|
||||
|
|
@ -146,7 +145,7 @@ impl DirFd {
|
|||
|
||||
if fd < 0 {
|
||||
Err(SafeTraversalError::OpenFailed {
|
||||
path: path_str.to_string(),
|
||||
path: path.to_string_lossy().into_owned(),
|
||||
source: io::Error::last_os_error(),
|
||||
}
|
||||
.into())
|
||||
|
|
@ -157,7 +156,6 @@ impl DirFd {
|
|||
|
||||
/// Open a subdirectory relative to this directory
|
||||
pub fn open_subdir(&self, name: &OsStr) -> io::Result<Self> {
|
||||
let name_str = name.to_string_lossy();
|
||||
let name_cstr =
|
||||
CString::new(name.as_bytes()).map_err(|_| SafeTraversalError::PathContainsNull)?;
|
||||
|
||||
|
|
@ -171,7 +169,7 @@ impl DirFd {
|
|||
|
||||
if fd < 0 {
|
||||
Err(SafeTraversalError::OpenFailed {
|
||||
path: name_str.to_string(),
|
||||
path: name.to_string_lossy().into_owned(),
|
||||
source: io::Error::last_os_error(),
|
||||
}
|
||||
.into())
|
||||
|
|
@ -182,7 +180,6 @@ impl DirFd {
|
|||
|
||||
/// Get raw stat data for a file relative to this directory
|
||||
pub fn stat_at(&self, name: &OsStr, follow_symlinks: bool) -> io::Result<libc::stat> {
|
||||
let name_str = name.to_string_lossy();
|
||||
let name_cstr =
|
||||
CString::new(name.as_bytes()).map_err(|_| SafeTraversalError::PathContainsNull)?;
|
||||
|
||||
|
|
@ -197,7 +194,7 @@ impl DirFd {
|
|||
|
||||
if ret < 0 {
|
||||
Err(SafeTraversalError::StatFailed {
|
||||
path: name_str.to_string(),
|
||||
path: name.to_string_lossy().into_owned(),
|
||||
source: io::Error::last_os_error(),
|
||||
}
|
||||
.into())
|
||||
|
|
@ -264,7 +261,6 @@ impl DirFd {
|
|||
|
||||
/// Remove a file or empty directory relative to this directory
|
||||
pub fn unlink_at(&self, name: &OsStr, is_dir: bool) -> io::Result<()> {
|
||||
let name_str = name.to_string_lossy();
|
||||
let name_cstr =
|
||||
CString::new(name.as_bytes()).map_err(|_| SafeTraversalError::PathContainsNull)?;
|
||||
let flags = if is_dir { libc::AT_REMOVEDIR } else { 0 };
|
||||
|
|
@ -273,7 +269,7 @@ impl DirFd {
|
|||
|
||||
if ret < 0 {
|
||||
Err(SafeTraversalError::UnlinkFailed {
|
||||
path: name_str.to_string(),
|
||||
path: name.to_string_lossy().into_owned(),
|
||||
source: io::Error::last_os_error(),
|
||||
}
|
||||
.into())
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue