diff --git a/bin/cp/cp.1 b/bin/cp/cp.1 index d8d62ef076a..90b1a158a13 100644 --- a/bin/cp/cp.1 +++ b/bin/cp/cp.1 @@ -31,7 +31,7 @@ .\" .\" @(#)cp.1 8.3 (Berkeley) 4/18/94 .\" -.Dd December 14, 2023 +.Dd March 28, 2024 .Dt CP 1 .Os .Sh NAME @@ -311,12 +311,14 @@ differ as they copy special files as normal files while recreating a hierarchy. .Pp The +.Fl a , .Fl l , +.Fl N , +.Fl n , .Fl s , .Fl v , -.Fl x and -.Fl n +.Fl x options are non-standard and their use in scripts is not recommended. .Sh SEE ALSO .Xr mv 1 , diff --git a/bin/cp/cp.c b/bin/cp/cp.c index 852868e65dc..af7d5ffac39 100644 --- a/bin/cp/cp.c +++ b/bin/cp/cp.c @@ -519,9 +519,13 @@ copy(char *argv[], enum op type, int fts_options, struct stat *root_stat) * umask blocks owner writes, we fail. */ if (dne) { - if (mkdir(to.p_path, - curr->fts_statp->st_mode | S_IRWXU) < 0) - err(1, "%s", to.p_path); + mode = curr->fts_statp->st_mode | S_IRWXU; + if (mkdir(to.p_path, mode) != 0) { + warn("%s", to.p_path); + (void)fts_set(ftsp, curr, FTS_SKIP); + badcp = rval = 1; + break; + } /* * First DNE with a NULL root_stat is the root * path, so set root_stat. We can't really @@ -530,14 +534,19 @@ copy(char *argv[], enum op type, int fts_options, struct stat *root_stat) * first directory we created and use that. */ if (root_stat == NULL && - stat(to.p_path, &created_root_stat) == -1) { - err(1, "stat"); - } else if (root_stat == NULL) { - root_stat = &created_root_stat; + stat(to.p_path, &created_root_stat) != 0) { + warn("%s", to.p_path); + (void)fts_set(ftsp, curr, FTS_SKIP); + badcp = rval = 1; + break; } + if (root_stat == NULL) + root_stat = &created_root_stat; } else if (!S_ISDIR(to_stat.st_mode)) { - errno = ENOTDIR; - err(1, "%s", to.p_path); + warnc(ENOTDIR, "%s", to.p_path); + (void)fts_set(ftsp, curr, FTS_SKIP); + badcp = rval = 1; + break; } /* * Arrange to correct directory attributes later