aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2023-07-29 13:35:45 +0200
committerThomas Voss <mail@thomasvoss.com> 2023-07-29 13:35:45 +0200
commit8ec5d631f21c54c9bb0bbd7d6fa39513c9242219 (patch)
tree0419fd01ca4925c75064d739b9ae40efc508789b /src
parenta6512c1dc52c013b6b3c25840058d8a9085b0cc1 (diff)
Move some code out to move_path()
Diffstat (limited to 'src')
-rw-r--r--src/main.rs29
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() {