1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 12:07:46 +00:00

mv: refactor try! to ?

This commit is contained in:
Roy Ivy III 2019-02-09 13:23:43 -06:00
parent fb1d844e14
commit 52c7f0aa34

View file

@ -358,11 +358,11 @@ fn rename(from: &PathBuf, to: &PathBuf, b: &Behaviour) -> Result<()> {
BackupMode::ExistingBackup => Some(existing_backup_path(to, &b.suffix)), BackupMode::ExistingBackup => Some(existing_backup_path(to, &b.suffix)),
}; };
if let Some(ref p) = backup_path { if let Some(ref p) = backup_path {
try!(fs::rename(to, p)); fs::rename(to, p)?;
} }
if b.update { if b.update {
if try!(try!(fs::metadata(from)).modified()) <= try!(try!(fs::metadata(to)).modified()) if fs::metadata(from)?.modified()? <= fs::metadata(to)?.modified()?
{ {
return Ok(()); return Ok(());
} }
@ -374,14 +374,14 @@ fn rename(from: &PathBuf, to: &PathBuf, b: &Behaviour) -> Result<()> {
// normalize behavior between *nix and windows // normalize behavior between *nix and windows
if from.is_dir() { if from.is_dir() {
if is_empty_dir(to) { if is_empty_dir(to) {
try!(fs::remove_dir(to)) fs::remove_dir(to)?
} else { } else {
return Err(std::io::Error::new(std::io::ErrorKind::Other, "Directory not empty")); return Err(std::io::Error::new(std::io::ErrorKind::Other, "Directory not empty"));
} }
} }
} }
try!(fs::rename(from, to)); fs::rename(from, to)?;
if b.verbose { if b.verbose {
print!("{} -> {}", from.display(), to.display()); print!("{} -> {}", from.display(), to.display());