Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Categories Used:

- Fix tar extraction count when --quiet [\#824](https://github.com/ouch-org/ouch/pull/824) ([marcospb19](https://github.com/marcospb19))
- Fix 7z BadSignature error when compressing and then listing [\#819](https://github.com/ouch-org/ouch/pull/819) ([tommady](https://github.com/tommady))
- Fix Unpacking with merge flag failed without --dir flag [\#826](https://github.com/ouch-org/ouch/pull/826) ([tommady](https://github.com/tommady))
Comment thread
marcospb19 marked this conversation as resolved.
Outdated

### Tweaks

Expand Down
4 changes: 3 additions & 1 deletion src/commands/decompress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,9 @@ fn smart_unpack(
};

// Rename the temporary directory to the archive name, which is output_file_path
fs::rename(&previous_path, &new_path)?;
if fs::rename(&previous_path, &new_path).is_err() {
utils::rename_recursively(&previous_path, &new_path)?;
};
info_accessible(format!(
"Successfully moved \"{}\" to \"{}\"",
nice_directory_display(&previous_path),
Expand Down
20 changes: 20 additions & 0 deletions src/utils/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,3 +209,23 @@ pub fn try_infer_extension(path: &Path) -> Option<Extension> {
None
}
}

/// Rename the src directory into the dst directory recursively
pub fn rename_recursively(src: &Path, dst: &Path) -> crate::Result<()> {
if !src.exists() || !dst.exists() {
return Err(crate::Error::NotFound {
error_title: "source or destination directory does not exist".to_string(),
});
}

for entry in fs::read_dir(src)? {
let entry = entry?;
let ty = entry.file_type()?;
if ty.is_dir() {
rename_recursively(entry.path().as_path(), dst.join(entry.file_name()).as_path())?;
} else {
fs::rename(entry.path(), dst.join(entry.file_name()).as_path())?;
}
}
Ok(())
}
2 changes: 1 addition & 1 deletion src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub use self::{
},
fs::{
cd_into_same_dir_as, create_dir_if_non_existent, is_path_stdin, remove_file_or_dir,
rename_for_available_filename, resolve_path_conflict, try_infer_extension,
rename_for_available_filename, rename_recursively, resolve_path_conflict, try_infer_extension,
},
question::{
ask_to_create_file, user_wants_to_continue, user_wants_to_overwrite, FileConflitOperation, QuestionAction,
Expand Down
Loading