diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 29 | 
1 files changed, 14 insertions, 15 deletions
| diff --git a/src/main.rs b/src/main.rs index bf695cd..1698968 100644 --- a/src/main.rs +++ b/src/main.rs @@ -134,23 +134,10 @@ fn work() -> Result<(), Error> {  	ps.sort_by_key(|s| Reverse(s.0.components().count()));  	for (s, t, _) in ps.iter() { -		if flags.verbose { -			println!("{} -> {}", s.as_path().display(), t.as_path().display()); -		} - -		if !flags.dryrun { -			copy_and_remove_file_or_dir(&s, &t)?; -		} +		move_path(&flags, &s, &t)?;  	} -  	for (_, t, d) in ps.iter().rev() { -		if flags.verbose { -			println!("{} -> {}", t.as_path().display(), d.as_path().display()); -		} - -		if !flags.dryrun { -			copy_and_remove_file_or_dir(&t, &d)?; -		} +		move_path(&flags, &t, &d)?;  	}  	Ok(()) @@ -257,6 +244,18 @@ fn normalize_path(path: &Path) -> PathBuf {  	ret  } +fn move_path(flags: &Flags, from: &PathBuf, to: &PathBuf) -> io::Result<()> { +	if flags.verbose { +		println!("{} -> {}", from.as_path().display(), to.as_path().display()); +	} + +	if !flags.dryrun { +		copy_and_remove_file_or_dir(&from, &to)?; +	} + +	Ok(()) +} +  fn copy_and_remove_file_or_dir<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> io::Result<()> {  	let data = fs::metadata(&from)?;  	if data.is_dir() { |