Skip to content

Commit 28ac11f

Browse files
committed
Replacing helper function in other places too
1 parent a7fb515 commit 28ac11f

File tree

1 file changed

+13
-25
lines changed

1 file changed

+13
-25
lines changed

src/uu/mv/src/mv.rs

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -427,24 +427,11 @@ fn handle_two_paths(source: &Path, target: &Path, opts: &Options) -> UResult<()>
427427
} else if target.exists() && source_is_dir {
428428
match opts.overwrite {
429429
OverwriteMode::NoClobber => return Ok(()),
430-
OverwriteMode::Interactive => {
431-
if !prompt_yes!(
432-
"{}",
433-
translate!("mv-prompt-overwrite", "target" => target.quote())
434-
) {
435-
return Err(io::Error::other("").into());
436-
}
437-
}
430+
OverwriteMode::Interactive => prompt_overwrite(target)?,
438431
OverwriteMode::Force => {}
439432
OverwriteMode::Default => {
440-
if std::io::stdin().is_terminal()
441-
&& !is_writable(target)
442-
&& !prompt_yes!(
443-
"{}",
444-
translate!("mv-prompt-overwrite", "target" => target.quote())
445-
)
446-
{
447-
return Err(io::Error::other("").into());
433+
if std::io::stdin().is_terminal() && !is_writable(target) {
434+
prompt_overwrite(target)?;
448435
}
449436
}
450437
}
@@ -741,26 +728,19 @@ fn rename(
741728
return Err(io::Error::other(err_msg));
742729
}
743730

744-
let prompt_and_check = || -> io::Result<()> {
745-
if !prompt_yes!("{}", get_interactive_prompt(to)) {
746-
return Err(io::Error::other(""));
747-
}
748-
Ok(())
749-
};
750-
751731
match opts.overwrite {
752732
OverwriteMode::NoClobber => {
753733
if opts.debug {
754734
println!("{}", translate!("mv-debug-skipped", "target" => to.quote()));
755735
}
756736
return Ok(());
757737
}
758-
OverwriteMode::Interactive => prompt_and_check()?,
738+
OverwriteMode::Interactive => prompt_overwrite(to)?,
759739
OverwriteMode::Force => {}
760740
OverwriteMode::Default => {
761741
// GNU mv prompts when stdin is a TTY and target is not writable
762742
if std::io::stdin().is_terminal() && !is_writable(to) {
763-
prompt_and_check()?;
743+
prompt_overwrite(to)?;
764744
}
765745
}
766746
}
@@ -1265,6 +1245,14 @@ fn get_interactive_prompt(to: &Path) -> String {
12651245
translate!("mv-prompt-overwrite", "target" => to.quote())
12661246
}
12671247

1248+
/// Prompts the user for confirmation and returns an error if declined.
1249+
fn prompt_overwrite(to: &Path) -> io::Result<()> {
1250+
if !prompt_yes!("{}", get_interactive_prompt(to)) {
1251+
return Err(io::Error::other(""));
1252+
}
1253+
Ok(())
1254+
}
1255+
12681256
/// Checks if a file can be deleted by attempting to open it with delete permissions.
12691257
#[cfg(windows)]
12701258
fn can_delete_file(path: &Path) -> bool {

0 commit comments

Comments
 (0)