summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorMichael Haro <mharo@FreeBSD.org>1999-12-11 20:33:34 +0000
committerMichael Haro <mharo@FreeBSD.org>1999-12-11 20:33:34 +0000
commitafd948d483a45c812e4c80d9e3ebe16d5580ac6c (patch)
treecbe20dd32e1e22e29f1d33ee08a3ef53a1086bc3 /bin
parent001e39582a43822d969a5839e436432f39445c9f (diff)
Notes
Diffstat (limited to 'bin')
-rw-r--r--bin/cp/cp.112
-rw-r--r--bin/cp/cp.c45
-rw-r--r--bin/cp/utils.c11
-rw-r--r--bin/mv/mv.110
-rw-r--r--bin/mv/mv.c24
5 files changed, 70 insertions, 32 deletions
diff --git a/bin/cp/cp.1 b/bin/cp/cp.1
index 126b3ca933b7..54e050a50cef 100644
--- a/bin/cp/cp.1
+++ b/bin/cp/cp.1
@@ -48,7 +48,7 @@
.Op Fl H | Fl L | Fl P
.Oc
.Op Fl f | i
-.Op Fl p
+.Op Fl pv
.Ar source_file target_file
.Nm cp
.Oo
@@ -56,7 +56,7 @@
.Op Fl H | Fl L | Fl P
.Oc
.Op Fl f | i
-.Op Fl p
+.Op Fl pv
.Ar source_file ... target_directory
.Sh DESCRIPTION
In the first synopsis form, the
@@ -145,6 +145,10 @@ If the source file has both its set user ID and set group ID bits on,
and either the user ID or group ID cannot be preserved, neither
the set user ID nor set group ID bits are preserved in the copy's
permissions.
+.It Fl v
+Cause
+.Nm
+to be verbose, showing files as they are copied.
.El
.Pp
For each destination file that already exists, its contents are
@@ -210,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 ,
diff --git a/bin/cp/cp.c b/bin/cp/cp.c
index bbac504a75f1..e528aeae93cb 100644
--- a/bin/cp/cp.c
+++ b/bin/cp/cp.c
@@ -69,6 +69,7 @@ static const char rcsid[] =
#include <err.h>
#include <errno.h>
#include <fts.h>
+#include <stdio.h>
#include <string.h>
#include <unistd.h>
@@ -79,10 +80,10 @@ static const char rcsid[] =
*--(p).p_end = 0; \
}
-PATH_T to = { to.p_path, "" };
+PATH_T to = { to.p_path, "", "" };
uid_t myuid;
-int Rflag, iflag, pflag, rflag, fflag;
+int Rflag, iflag, pflag, rflag, fflag, vflag;
int myumask;
enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
@@ -101,7 +102,7 @@ main(argc, argv)
char *target;
Hflag = Lflag = Pflag = 0;
- while ((ch = getopt(argc, argv, "HLPRfipr")) != -1)
+ while ((ch = getopt(argc, argv, "HLPRfiprv")) != -1)
switch (ch) {
case 'H':
Hflag = 1;
@@ -132,6 +133,9 @@ main(argc, argv)
case 'r':
rflag = 1;
break;
+ case 'v':
+ vflag = 1;
+ break;
default:
usage();
break;
@@ -249,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;
@@ -295,7 +299,7 @@ copy(argv, type, fts_options)
* Since the first level MUST be FTS_ROOTLEVEL, base
* is always initialized.
*/
- if (curr->fts_level == FTS_ROOTLEVEL)
+ if (curr->fts_level == FTS_ROOTLEVEL) {
if (type != DIR_TO_DNE) {
p = strrchr(curr->fts_path, '/');
base = (p == NULL) ? 0 :
@@ -306,6 +310,7 @@ copy(argv, type, fts_options)
base += 1;
} else
base = curr->fts_pathlen;
+ }
p = &curr->fts_path[base];
nlen = curr->fts_pathlen - base;
@@ -316,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);
@@ -333,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;
@@ -342,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;
@@ -351,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;
}
/*
@@ -384,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);
@@ -393,26 +398,28 @@ 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 (vflag && !badcp)
+ (void)printf("%s -> %s\n", curr->fts_path, to.p_path);
}
if (errno)
err(1, "fts_read");
diff --git a/bin/cp/utils.c b/bin/cp/utils.c
index b6af599e0a20..7e94ed9b56fc 100644
--- a/bin/cp/utils.c
+++ b/bin/cp/utils.c
@@ -50,6 +50,7 @@ static const char rcsid[] =
#include <fcntl.h>
#include <fts.h>
#include <stdio.h>
+#include <sysexits.h>
#include <unistd.h>
#include "extern.h"
@@ -183,7 +184,7 @@ copy_file(entp, dne)
*/
#define RETAINBITS \
(S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO)
- else if (fs->st_mode & (S_ISUID | S_ISGID) && fs->st_uid == myuid)
+ else if (fs->st_mode & (S_ISUID | S_ISGID) && fs->st_uid == myuid) {
if (fstat(to_fd, &to_stat)) {
warn("%s", to.p_path);
rval = 1;
@@ -192,6 +193,7 @@ copy_file(entp, dne)
warn("%s", to.p_path);
rval = 1;
}
+ }
(void)close(from_fd);
if (close(to_fd)) {
warn("%s", to.p_path);
@@ -319,8 +321,9 @@ setfile(fs, fd)
void
usage()
{
+
(void)fprintf(stderr, "%s\n%s\n",
-"usage: cp [-R [-H | -L | -P]] [-f | -i] [-p] src target",
-" cp [-R [-H | -L | -P]] [-f | -i] [-p] src1 ... srcN directory");
- exit(1);
+"usage: cp [-R [-H | -L | -P]] [-f | -i] [-pv] src target",
+" cp [-R [-H | -L | -P]] [-f | -i] [-pv] src1 ... srcN directory");
+ exit(EX_USAGE);
}
diff --git a/bin/mv/mv.1 b/bin/mv/mv.1
index be97d80e1b09..528eeaa1a8be 100644
--- a/bin/mv/mv.1
+++ b/bin/mv/mv.1
@@ -44,9 +44,11 @@
.Sh SYNOPSIS
.Nm mv
.Op Fl f | Fl i
+.Op Fl v
.Ar source target
.Nm mv
.Op Fl f | Fl i
+.Op Fl v
.Ar source ... directory
.Sh DESCRIPTION
In its first form, the
@@ -95,6 +97,10 @@ the move is attempted.
option overrides any previous
.Fl f
options.)
+.It Fl v
+Cause
+.Nm
+to be verbose, showing files after they are moved.
.El
.Pp
It is an error for either the
@@ -130,6 +136,10 @@ utility exits 0 on success, and >0 if an error occurs.
.Xr cp 1 ,
.Xr rm 1 ,
.Xr symlink 7
+.Sh COMPATIBILITY
+The
+.Fl v
+option is non-standard and its use in scripts is not recommended.
.Sh STANDARDS
The
.Nm
diff --git a/bin/mv/mv.c b/bin/mv/mv.c
index 6db419244166..5f0f28b1882d 100644
--- a/bin/mv/mv.c
+++ b/bin/mv/mv.c
@@ -60,11 +60,12 @@ static const char rcsid[] =
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sysexits.h>
#include <unistd.h>
#include "pathnames.h"
-int fflg, iflg;
+int fflg, iflg, vflg;
int copy __P((char *, char *));
int do_move __P((char *, char *));
@@ -82,7 +83,7 @@ main(argc, argv)
int ch;
char path[MAXPATHLEN];
- while ((ch = getopt(argc, argv, "fi")) != -1)
+ while ((ch = getopt(argc, argv, "fiv")) != -1)
switch (ch) {
case 'i':
iflg = 1;
@@ -92,6 +93,9 @@ main(argc, argv)
fflg = 1;
iflg = 0;
break;
+ case 'v':
+ vflg = 1;
+ break;
default:
usage();
}
@@ -188,8 +192,11 @@ do_move(from, to)
}
}
}
- if (!rename(from, to))
+ if (!rename(from, to)) {
+ if (vflg)
+ printf("%s -> %s\n", from, to);
return (0);
+ }
if (errno == EXDEV) {
struct statfs sfs;
@@ -299,6 +306,8 @@ err: if (unlink(to))
warn("%s: remove", from);
return (1);
}
+ if (vflg)
+ printf("%s -> %s\n", from, to);
return (0);
}
@@ -309,7 +318,7 @@ copy(from, to)
int pid, status;
if ((pid = fork()) == 0) {
- execl(_PATH_CP, "mv", "-PRp", from, to, NULL);
+ execl(_PATH_CP, "mv", vflg ? "-PRpv" : "-PRp", from, to, NULL);
warn("%s", _PATH_CP);
_exit(1);
}
@@ -350,8 +359,9 @@ copy(from, to)
void
usage()
{
+
(void)fprintf(stderr, "%s\n%s\n",
- "usage: mv [-f | -i] source target",
- " mv [-f | -i] source ... directory");
- exit(1);
+ "usage: mv [-f | -i] [-v] source target",
+ " mv [-f | -i] [-v] source ... directory");
+ exit(EX_USAGE);
}