aboutsummaryrefslogtreecommitdiff
path: root/bin/cp
diff options
context:
space:
mode:
authorAndrey A. Chernov <ache@FreeBSD.org>2002-05-17 11:52:48 +0000
committerAndrey A. Chernov <ache@FreeBSD.org>2002-05-17 11:52:48 +0000
commit27d3ae358753b8e77b8aa5887d67b45b01d920ff (patch)
treec163ae39d53c21b1829b4cd78a7cd09df402c9bd /bin/cp
parent5fab96cfa446429edc98c2ee99b1fca16c4064cb (diff)
downloadsrc-27d3ae358753b8e77b8aa5887d67b45b01d920ff.tar.gz
src-27d3ae358753b8e77b8aa5887d67b45b01d920ff.zip
Trailing slash fixes.
Fix the case: cp file nonexistent/ which create nonextstent as file while trailing slash clearly indicates that nonexistent must be a directory. Also fix the case: cp file1 file2/ which should produce error.
Notes
Notes: svn path=/head/; revision=96808
Diffstat (limited to 'bin/cp')
-rw-r--r--bin/cp/cp.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/bin/cp/cp.c b/bin/cp/cp.c
index 935388df1ff9..e803e8274a62 100644
--- a/bin/cp/cp.c
+++ b/bin/cp/cp.c
@@ -99,8 +99,8 @@ main(int argc, char *argv[])
{
struct stat to_stat, tmp_stat;
enum op type;
- int Hflag, Lflag, Pflag, ch, fts_options, r;
- char *target;
+ int Hflag, Lflag, Pflag, ch, fts_options, r, have_trailing_slash;
+ char *target, *s;
Hflag = Lflag = Pflag = 0;
while ((ch = getopt(argc, argv, "HLPRfiprv")) != -1)
@@ -179,6 +179,8 @@ main(int argc, char *argv[])
*to.p_end++ = '.';
*to.p_end = 0;
}
+ have_trailing_slash =
+ ((s = strrchr(to.p_path, '/')) != NULL && s[1] == '\0');
STRIP_TRAILING_SLASH(to);
to.target_end = to.p_end;
@@ -229,6 +231,14 @@ main(int argc, char *argv[])
type = FILE_TO_FILE;
} else
type = FILE_TO_FILE;
+
+ if (have_trailing_slash && type == FILE_TO_FILE) {
+ if (r == -1)
+ errx(1, "directory %s does not exist",
+ to.p_path);
+ else
+ errx(1, "%s is not a directory", to.p_path);
+ }
} else
/*
* Case (2). Target is a directory.