Skip to content

Commit 64812b0

Browse files
committed
improve code
1 parent 3fa52ce commit 64812b0

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

src/uucore/src/lib/features/perms.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -313,22 +313,24 @@ impl ChownExecutor {
313313
#[cfg(target_os = "linux")]
314314
{
315315
match DirFd::open(path) {
316-
Ok(dir_fd) => self.safe_chown_dir(&dir_fd, path, &meta).map(|_| String::new()),
316+
Ok(dir_fd) => self
317+
.safe_chown_dir(&dir_fd, path, &meta)
318+
.map(|_| String::new()),
317319
Err(_e) => {
318320
// Don't show error here - let safe_dive_into handle directory traversal errors
319321
// This prevents duplicate error messages
320322
Ok(String::new())
321323
}
322324
}
323325
}
324-
} else {
325-
// For non-directories (files, symlinks), use the regular wrap_chown method
326326
#[cfg(not(target_os = "linux"))]
327327
{
328328
unreachable!()
329329
}
330-
wrap_chown(
330+
} else {
331331
// For non-directories (files, symlinks) or non-Linux systems, use the regular wrap_chown method
332+
wrap_chown(
333+
path,
332334
&meta,
333335
self.dest_uid,
334336
self.dest_gid,
@@ -372,15 +374,10 @@ impl ChownExecutor {
372374
} else {
373375
ret
374376
}
375-
) -> Result<(), String> {
377+
}
376378

377379
#[cfg(target_os = "linux")]
378-
fn safe_chown_dir(
379-
&self,
380-
dir_fd: &DirFd,
381-
path: &Path,
382-
meta: &Metadata,
383-
) -> Result<String, String> {
380+
fn safe_chown_dir(&self, dir_fd: &DirFd, path: &Path, meta: &Metadata) -> Result<(), String> {
384381
let dest_uid = self.dest_uid.unwrap_or_else(|| meta.uid());
385382
let dest_gid = self.dest_gid.unwrap_or_else(|| meta.gid());
386383

@@ -417,15 +414,15 @@ impl ChownExecutor {
417414
entries::uid2usr(dest_uid).unwrap_or_else(|_| dest_uid.to_string()),
418415
entries::gid2grp(dest_gid).unwrap_or_else(|_| dest_gid.to_string())
419416
)
420-
Ok(())
417+
};
421418
}
422419

423420
return Err(error_msg);
424421
}
425422

426423
// Report the change if verbose (similar to wrap_chown)
427424
self.report_ownership_change_success(path, meta.uid(), meta.gid());
428-
Ok(String::new())
425+
Ok(())
429426
}
430427

431428
#[cfg(target_os = "linux")]

0 commit comments

Comments
 (0)