From 9245c19a4aaedd8184063b3bb00b63b5954cfcc3 Mon Sep 17 00:00:00 2001 From: Michael Mikonos <127171689+mknos@users.noreply.github.com> Date: Tue, 23 Jul 2024 19:20:51 +0800 Subject: [PATCH] cp: warn for source directory * When running on non-unix, avoid passing a directory to File::Copy::copy() and print a helpful warning message * GNU and OpenBSD versions print a warning for this case too --- bin/cp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/bin/cp b/bin/cp index 0ea02f49..7da3bfe6 100755 --- a/bin/cp +++ b/bin/cp @@ -67,6 +67,11 @@ sub run { require File::Copy; my $err = 0; foreach my $source (@files) { + if (-d $source) { + print { error_fh() } "$0: '$source' is a directory (not copied)\n"; + $err = 1; + next; + } my $catdst = $destination; if( -d $destination ) { $catdst = catfile( $destination, basename($source) )