Reviewed by:	obrien
This commit is contained in:
Michael Haro 1999-11-28 09:34:21 +00:00
parent 9f9d09e94b
commit 0efa204039
3 changed files with 33 additions and 29 deletions

View File

@ -214,6 +214,10 @@ option.
This implementation supports that option, however, its use is strongly
discouraged, as it does not correctly copy special files, symbolic links
or fifo's.
.Pp
The
.Fl v
option is non-standard and its use in scripts is not recommended.
.Sh SEE ALSO
.Xr mv 1 ,
.Xr rcp 1 ,

View File

@ -253,23 +253,23 @@ copy(argv, type, fts_options)
struct stat to_stat;
FTS *ftsp;
FTSENT *curr;
int base = 0, dne, nlen, rval;
int base = 0, dne, badcp, nlen, rval;
char *p, *target_mid;
if ((ftsp = fts_open(argv, fts_options, mastercmp)) == NULL)
err(1, NULL);
for (rval = 0; (curr = fts_read(ftsp)) != NULL;) {
for (badcp = rval = 0; (curr = fts_read(ftsp)) != NULL; badcp = 0) {
switch (curr->fts_info) {
case FTS_NS:
case FTS_DNR:
case FTS_ERR:
warnx("%s: %s",
curr->fts_path, strerror(curr->fts_errno));
rval = 1;
badcp = rval = 1;
continue;
case FTS_DC: /* Warn, continue. */
warnx("%s: directory causes a cycle", curr->fts_path);
rval = 1;
badcp = rval = 1;
continue;
case FTS_DP: /* Ignore, continue. */
continue;
@ -321,7 +321,7 @@ copy(argv, type, fts_options)
if (target_mid - to.p_path + nlen > MAXPATHLEN) {
warnx("%s%s: name too long (not copied)",
to.p_path, p);
rval = 1;
badcp = rval = 1;
continue;
}
(void)strncat(target_mid, p, nlen);
@ -338,7 +338,7 @@ copy(argv, type, fts_options)
to_stat.st_ino == curr->fts_statp->st_ino) {
warnx("%s and %s are identical (not copied).",
to.p_path, curr->fts_path);
rval = 1;
badcp = rval = 1;
if (S_ISDIR(curr->fts_statp->st_mode))
(void)fts_set(ftsp, curr, FTS_SKIP);
continue;
@ -347,7 +347,7 @@ copy(argv, type, fts_options)
S_ISDIR(to_stat.st_mode)) {
warnx("cannot overwrite directory %s with non-directory %s",
to.p_path, curr->fts_path);
rval = 1;
badcp = rval = 1;
continue;
}
dne = 0;
@ -356,14 +356,14 @@ copy(argv, type, fts_options)
switch (curr->fts_statp->st_mode & S_IFMT) {
case S_IFLNK:
if (copy_link(curr, !dne))
rval = 1;
badcp = rval = 1;
break;
case S_IFDIR:
if (!Rflag && !rflag) {
warnx("%s is a directory (not copied).",
curr->fts_path);
(void)fts_set(ftsp, curr, FTS_SKIP);
rval = 1;
badcp = rval = 1;
break;
}
/*
@ -389,7 +389,7 @@ copy(argv, type, fts_options)
* forever.
*/
if (pflag && setfile(curr->fts_statp, 0))
rval = 1;
badcp = rval = 1;
else if (dne)
(void)chmod(to.p_path,
curr->fts_statp->st_mode);
@ -398,27 +398,27 @@ copy(argv, type, fts_options)
case S_IFCHR:
if (Rflag) {
if (copy_special(curr->fts_statp, !dne))
rval = 1;
badcp = rval = 1;
} else {
if (copy_file(curr, dne))
rval = 1;
badcp = rval = 1;
}
break;
case S_IFIFO:
if (Rflag) {
if (copy_fifo(curr->fts_statp, !dne))
rval = 1;
badcp = rval = 1;
} else {
if (copy_file(curr, dne))
rval = 1;
badcp = rval = 1;
}
break;
default:
if (copy_file(curr, dne))
rval = 1;
badcp = rval = 1;
break;
}
if (!rval && vflag)
if (vflag && !badcp)
(void)printf("%s -> %s\n", curr->fts_path, to.p_path);
}
if (errno)

View File

@ -150,7 +150,6 @@ rm_tree(argv)
int needstat;
int flags;
int rval;
int e;
/*
* Remove a file hierarchy. If forcing removal (-f), or interactive
@ -226,7 +225,7 @@ rm_tree(argv)
!(p->fts_statp->st_flags & (SF_APPEND|SF_IMMUTABLE)))
rval = chflags(p->fts_accpath,
p->fts_statp->st_flags &= ~(UF_APPEND|UF_IMMUTABLE));
if (!rval) {
if (rval == 0) {
/*
* If we can't read or search the directory, may still be
* able to remove it. Don't print out the un{read,search}able
@ -235,9 +234,9 @@ rm_tree(argv)
switch (p->fts_info) {
case FTS_DP:
case FTS_DNR:
e = rmdir(p->fts_accpath);
if (e == 0 || (fflag && errno == ENOENT)) {
if (e == 0 && vflag)
rval = rmdir(p->fts_accpath);
if (rval == 0 || (fflag && errno == ENOENT)) {
if (rval == 0 && vflag)
(void)printf("%s\n",
p->fts_accpath);
continue;
@ -245,9 +244,9 @@ rm_tree(argv)
break;
case FTS_W:
e = undelete(p->fts_accpath);
if (e == 0 || (fflag && errno == ENOENT)) {
if (e == 0 && vflag)
rval = undelete(p->fts_accpath);
if (rval == 0 && (fflag && errno == ENOENT)) {
if (vflag)
(void)printf("%s\n",
p->fts_accpath);
continue;
@ -257,9 +256,9 @@ rm_tree(argv)
default:
if (Pflag)
rm_overwrite(p->fts_accpath, NULL);
e = unlink(p->fts_accpath);
if (e == 0 || (fflag && errno == ENOENT)) {
if (e == 0 && vflag)
rval = unlink(p->fts_accpath);
if (rval == 0 || (fflag && errno == ENOENT)) {
if (rval == 0 && vflag)
(void)printf("%s\n",
p->fts_accpath);
continue;
@ -316,7 +315,7 @@ rm_file(argv)
(sb.st_flags & (UF_APPEND|UF_IMMUTABLE)) &&
!(sb.st_flags & (SF_APPEND|SF_IMMUTABLE)))
rval = chflags(f, sb.st_flags & ~(UF_APPEND|UF_IMMUTABLE));
if (!rval) {
if (rval == 0) {
if (S_ISWHT(sb.st_mode))
rval = undelete(f);
else if (S_ISDIR(sb.st_mode))
@ -331,7 +330,7 @@ rm_file(argv)
warn("%s", f);
eval = 1;
}
if (vflag)
if (vflag && rval == 0)
(void)printf("%s\n", f);
}
}
@ -472,6 +471,7 @@ checkdot(argv)
void
usage()
{
(void)fprintf(stderr, "usage: rm [-f | -i] [-dPRrvW] file ...\n");
exit(EX_USAGE);
}