Skip to content

Commit

Permalink
cp -i: continue on prompt
Browse files Browse the repository at this point in the history
* cp can copy multiple files to a destination
* It is not an error for the user to type "n" to not clobber an existing file when running (cp -i)
* Previously if I type "n" cp will exit with a failure code and ignore the remaining files I want to copy

%mkdir dest && perl cp -v a.c ar dest && perl cp -i a.c ar dest
a.c -> dest/a.c
ar -> dest/ar
overwrite dest/a.c? (y/n [n]) [n] n
overwrite dest/ar? (y/n [n]) [n] y
%echo $?
0
  • Loading branch information
mknos authored Nov 20, 2024
1 parent 36ffa5f commit 029b7e8
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions bin/cp
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,7 @@ sub run {
print { output_fh() } "$source -> $catdst\n" if $opts->{v};
if( -e $catdst and $opts->{i} and ! $opts->{f} ) {
my $answer = prompt( "overwrite $catdst? (y/n [n])", 'n' );
unless( $answer =~ m/\A\s*y/i ) {
print { error_fh() } "not overwritten";
return EX_FAILURE;
}
next unless $answer =~ m/\A\s*y/i;
}
if (File::Copy::copy($source, $catdst) == 0) {
print { error_fh() } "$0: $source -> $catdst: copy failed: $!\n";
Expand Down

0 comments on commit 029b7e8

Please sign in to comment.