Re: [PATCH] cp(1): add -v option for verbosity

2017-06-25 Thread Theo de Raadt
> Job Snijders wrote:
> > On Sun, Jun 25, 2017 at 02:06:20PM +0200, Job Snijders wrote:
> > > This patch adds a -v option to cp(1) for more verbose output.
> > 
> > NetBSD/FreeBSD/DragonFly/OSX's cp(1) with "-v" print file names without
> > the single quotes, which might indeed be more appealing to the eye:
> 
> yes, very much. if we're going to add an option on the basis that everybody
> else has it, it should definitely do the same thing.
> 
> -v seems reasonable to me. it's a common option for lots of other utilities,
> like tar, for which similar objections about lack of benefit can be made. i
> tend to monitor programs' progress using ktrace, but that doesn't mean we
> can't provide an easier way.

and I use ^T alot.  But I only want SIGINFO handlers in certain
programs (I'm unable to be exact about which ones "seem a right fit",
but can declare we don't want them everywhere).  For this case
following the -v herd seems better, and even better than nothing.



Re: [PATCH] cp(1): add -v option for verbosity

2017-06-25 Thread Ted Unangst
Job Snijders wrote:
> On Sun, Jun 25, 2017 at 02:06:20PM +0200, Job Snijders wrote:
> > This patch adds a -v option to cp(1) for more verbose output.
> 
> NetBSD/FreeBSD/DragonFly/OSX's cp(1) with "-v" print file names without
> the single quotes, which might indeed be more appealing to the eye:

yes, very much. if we're going to add an option on the basis that everybody
else has it, it should definitely do the same thing.

-v seems reasonable to me. it's a common option for lots of other utilities,
like tar, for which similar objections about lack of benefit can be made. i
tend to monitor programs' progress using ktrace, but that doesn't mean we
can't provide an easier way.

i'd wait a day to see what other improvements can be made, then resubmit a
complete patch.



Re: [PATCH] cp(1): add -v option for verbosity

2017-06-25 Thread Job Snijders
On Sun, Jun 25, 2017 at 02:06:20PM +0200, Job Snijders wrote:
> This patch adds a -v option to cp(1) for more verbose output.

NetBSD/FreeBSD/DragonFly/OSX's cp(1) with "-v" print file names without
the single quotes, which might indeed be more appealing to the eye:

$ touch a b; mkdir c
$ cp -v a b c
a -> c/a
b -> c/b

> +.It Fl v
> +Explain what is being done.

A more compendious option description for bin/cp/cp.1 would be: 

.It Fl v
Display the source and destination of each copied file.

The above 2 suggestions make sense to the proposed mv(1) patch too,
modulo s/copied/moved/.

Kind regards,

Job



Re: [PATCH] cp(1): add -v option for verbosity

2017-06-25 Thread Paul de Weerd
On Sun, Jun 25, 2017 at 10:49:04PM +0200, Landry Breuil wrote:
| > | Alternatively one can use rsync(1), but that is not part of the base.
| > 
| > That may work for cp(1), but it's hard to replicate mv(1) behavior
| > with rsync (only metadata changes when on the same fs) or even
| > impossible to replciate rm(1) behavior.
| 
| Technically it could be possible to replicate mv with rsync
| --remove-source-files ... :)

rsync will still copy the file first, while mv can simply move the
file to another directory without the copy operation when it's on the
same filesystem (my comment about 'only metadata changes').

Cheers,

Paul

-- 
>[<++>-]<+++.>+++[<-->-]<.>+++[<+
+++>-]<.>++[<>-]<+.--.[-]
 http://www.weirdnet.nl/ 



Re: [PATCH] cp(1): add -v option for verbosity

2017-06-25 Thread Landry Breuil
On Sun, Jun 25, 2017 at 09:59:35PM +0200, Paul de Weerd wrote:
> On Sun, Jun 25, 2017 at 06:22:05PM +0200, Job Snijders wrote:
> | Dear Alexander,
> | 
> | On Sun, Jun 25, 2017 at 06:13:40PM +0200, Alexander Hall wrote:
> | > On June 25, 2017 2:06:20 PM GMT+02:00, Job Snijders  
> wrote:
> | > >This patch adds a -v option to cp(1) for more verbose output.
> | > >
> | > > $ touch a b; mkdir c
> | > > $ cp -v a b c
> | > > 'a' -> 'c/a'
> | > > 'b' -> 'c/b'
> | > > $ cp -rv c d
> | > > 'c' -> 'd/'
> | > > 'c/a' -> 'd/a'
> | > > 'c/b' -> 'd/b'
> | > 
> | > Pardon my ignorance, but why?
> | 
> | A fair question.  I myself have two use cases, but others may have their
> | own to add.
> | 
> | When a glob pattern is used, it can be beneficial to immediately observe
> | (during the execution of the command) which files have been copied.
> | 
> | When copying very large trees, the -v option provides some insight as to
> | what progress the cp operation has made so far.
> 
> I like the -v option for the above reason most (and have missed it on
> several occassions): copy, move or remove a whole bunch of files; it
> takes a while.  Is it working?  Or is NFS stalling / IO to the storage
> device otherwise acting up?
> 
> Also, when using these tools in crons, it can be very useful to have
> cron send out reports of the files copied/moved/deleted.  Note that
> directories can be altered outside of the control of said script: it
> is impossible to deterministically figure out what cp/mv/rm did after
> (or before, as the 'study `find *`' hint suggests) they are run.
> 
> | Alternatively one can use rsync(1), but that is not part of the base.
> 
> That may work for cp(1), but it's hard to replicate mv(1) behavior
> with rsync (only metadata changes when on the same fs) or even
> impossible to replciate rm(1) behavior.

Technically it could be possible to replicate mv with rsync
--remove-source-files ... :)



Re: [PATCH] cp(1): add -v option for verbosity

2017-06-25 Thread Paul de Weerd
On Sun, Jun 25, 2017 at 06:22:05PM +0200, Job Snijders wrote:
| Dear Alexander,
| 
| On Sun, Jun 25, 2017 at 06:13:40PM +0200, Alexander Hall wrote:
| > On June 25, 2017 2:06:20 PM GMT+02:00, Job Snijders  
wrote:
| > >This patch adds a -v option to cp(1) for more verbose output.
| > >
| > >   $ touch a b; mkdir c
| > >   $ cp -v a b c
| > >   'a' -> 'c/a'
| > >   'b' -> 'c/b'
| > >   $ cp -rv c d
| > >   'c' -> 'd/'
| > >   'c/a' -> 'd/a'
| > >   'c/b' -> 'd/b'
| > 
| > Pardon my ignorance, but why?
| 
| A fair question.  I myself have two use cases, but others may have their
| own to add.
| 
| When a glob pattern is used, it can be beneficial to immediately observe
| (during the execution of the command) which files have been copied.
| 
| When copying very large trees, the -v option provides some insight as to
| what progress the cp operation has made so far.

I like the -v option for the above reason most (and have missed it on
several occassions): copy, move or remove a whole bunch of files; it
takes a while.  Is it working?  Or is NFS stalling / IO to the storage
device otherwise acting up?

Also, when using these tools in crons, it can be very useful to have
cron send out reports of the files copied/moved/deleted.  Note that
directories can be altered outside of the control of said script: it
is impossible to deterministically figure out what cp/mv/rm did after
(or before, as the 'study `find *`' hint suggests) they are run.

| Alternatively one can use rsync(1), but that is not part of the base.

That may work for cp(1), but it's hard to replicate mv(1) behavior
with rsync (only metadata changes when on the same fs) or even
impossible to replciate rm(1) behavior.

Cheers,

Paul 'WEiRD' de Weerd

-- 
>[<++>-]<+++.>+++[<-->-]<.>+++[<+
+++>-]<.>++[<>-]<+.--.[-]
 http://www.weirdnet.nl/ 



Re: [PATCH] cp(1): add -v option for verbosity

2017-06-25 Thread Job Snijders
Dear Alexander,

On Sun, Jun 25, 2017 at 06:13:40PM +0200, Alexander Hall wrote:
> On June 25, 2017 2:06:20 PM GMT+02:00, Job Snijders  
> wrote:
> >This patch adds a -v option to cp(1) for more verbose output.
> >
> > $ touch a b; mkdir c
> > $ cp -v a b c
> > 'a' -> 'c/a'
> > 'b' -> 'c/b'
> > $ cp -rv c d
> > 'c' -> 'd/'
> > 'c/a' -> 'd/a'
> > 'c/b' -> 'd/b'
> 
> Pardon my ignorance, but why?

A fair question.  I myself have two use cases, but others may have their
own to add.

When a glob pattern is used, it can be beneficial to immediately observe
(during the execution of the command) which files have been copied.

When copying very large trees, the -v option provides some insight as to
what progress the cp operation has made so far.

Alternatively one can use rsync(1), but that is not part of the base.

> Is this a gnu thing? 

Not specifically: freebsd, netbsd, darwin and dragonfly have it too.

Kind regards,

Job



Re: [PATCH] cp(1): add -v option for verbosity

2017-06-25 Thread Alexander Hall


On June 25, 2017 2:06:20 PM GMT+02:00, Job Snijders  wrote:
>Dear team,
>
>This patch adds a -v option to cp(1) for more verbose output.
>
>   $ touch a b; mkdir c
>   $ cp -v a b c
>   'a' -> 'c/a'
>   'b' -> 'c/b'
>   $ cp -rv c d
>   'c' -> 'd/'
>   'c/a' -> 'd/a'
>   'c/b' -> 'd/b'

Pardon my ignorance, but why? Is this a gnu thing? 

/Alexander 

>
>Kind regards,
>
>Job
>
>diff --git bin/cp/cp.1 bin/cp/cp.1
>index 8573d801ca5..d4346d23f1d 100644
>--- bin/cp/cp.1
>+++ bin/cp/cp.1
>@@ -41,14 +41,14 @@
> .Nd copy files
> .Sh SYNOPSIS
> .Nm cp
>-.Op Fl fip
>+.Op Fl fipv
> .Oo
> .Fl R
> .Op Fl H | L | P
> .Oc
> .Ar source target
> .Nm cp
>-.Op Fl fip
>+.Op Fl fipv
> .Oo
> .Fl R
> .Op Fl H | L | P
>@@ -145,6 +145,8 @@ use a utility such as
> or
> .Xr tar 1
> instead.
>+.It Fl v
>+Explain what is being done.
> .El
> .Pp
> For each destination file that already exists, its contents are
>diff --git bin/cp/cp.c bin/cp/cp.c
>index 643d82ed9fa..819e02f7be8 100644
>--- bin/cp/cp.c
>+++ bin/cp/cp.c
>@@ -71,7 +71,7 @@
> PATH_T to = { to.p_path, "" };
> 
> uid_t myuid;
>-int Rflag, fflag, iflag, pflag, rflag;
>+int Rflag, fflag, iflag, pflag, rflag, vflag;
> mode_t myumask;
> 
> enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
>@@ -88,7 +88,7 @@ main(int argc, char *argv[])
>   char *target;
> 
>   Hflag = Lflag = Pflag = Rflag = 0;
>-  while ((ch = getopt(argc, argv, "HLPRfipr")) != -1)
>+  while ((ch = getopt(argc, argv, "HLPRfiprv")) != -1)
>   switch (ch) {
>   case 'H':
>   Hflag = 1;
>@@ -119,6 +119,9 @@ main(int argc, char *argv[])
>   case 'r':
>   rflag = 1;
>   break;
>+  case 'v':
>+  vflag = 1;
>+  break;
>   default:
>   usage();
>   break;
>@@ -394,6 +397,9 @@ copy(char *argv[], enum op type, int fts_options)
>   case S_IFLNK:
>   if (copy_link(curr, !fts_dne(curr)))
>   rval = 1;
>+  else if (vflag)
>+  (void)fprintf(stdout, "'%s' -> '%s'\n",
>+  curr->fts_path, to.p_path);
>   break;
>   case S_IFDIR:
>   if (!Rflag && !rflag) {
>@@ -415,6 +421,9 @@ copy(char *argv[], enum op type, int fts_options)
>   if (mkdir(to.p_path,
>   curr->fts_statp->st_mode | S_IRWXU) < 0)
>   err(1, "%s", to.p_path);
>+  else if (vflag)
>+  (void)fprintf(stdout, "'%s' -> '%s'\n",
>+  curr->fts_path, to.p_path);
>   } else if (!S_ISDIR(to_stat.st_mode))
>   errc(1, ENOTDIR, "%s", to.p_path);
>   break;
>@@ -426,6 +435,9 @@ copy(char *argv[], enum op type, int fts_options)
>   } else
>   if (copy_file(curr, fts_dne(curr)))
>   rval = 1;
>+  if (!rval && vflag)
>+  (void)fprintf(stdout, "'%s' -> '%s'\n",
>+  curr->fts_path, to.p_path);
>   break;
>   case S_IFIFO:
>   if (Rflag) {
>@@ -434,6 +446,9 @@ copy(char *argv[], enum op type, int fts_options)
>   } else
>   if (copy_file(curr, fts_dne(curr)))
>   rval = 1;
>+  if (!rval && vflag)
>+  (void)fprintf(stdout, "'%s' -> '%s'\n",
>+  curr->fts_path, to.p_path);
>   break;
>   case S_IFSOCK:
>   warnc(EOPNOTSUPP, "%s", curr->fts_path);
>@@ -441,6 +456,9 @@ copy(char *argv[], enum op type, int fts_options)
>   default:
>   if (copy_file(curr, fts_dne(curr)))
>   rval = 1;
>+  else if (vflag)
>+  (void)fprintf(stdout, "'%s' -> '%s'\n",
>+  curr->fts_path, to.p_path);
>   break;
>   }
>   }
>diff --git bin/cp/utils.c bin/cp/utils.c
>index 6a3c5178647..2189dd4be1f 100644
>--- bin/cp/utils.c
>+++ bin/cp/utils.c
>@@ -307,9 +307,9 @@ void
> usage(void)
> {
>   (void)fprintf(stderr,
>-  "usage: %s [-fip] [-R [-H | -L | -P]] source target\n",
>__progname);
>+  "usage: %s [-fipv] [-R [-H | -L | -P]] source target\n",
>__progname);
>   (void)fprintf(stderr,
>-  "   %s [-fip] [-R [-H | -L | -P]] source ... directory\n",
>+  " 

[PATCH] cp(1): add -v option for verbosity

2017-06-25 Thread Job Snijders
Dear team,

This patch adds a -v option to cp(1) for more verbose output.

$ touch a b; mkdir c
$ cp -v a b c
'a' -> 'c/a'
'b' -> 'c/b'
$ cp -rv c d
'c' -> 'd/'
'c/a' -> 'd/a'
'c/b' -> 'd/b'

Kind regards,

Job

diff --git bin/cp/cp.1 bin/cp/cp.1
index 8573d801ca5..d4346d23f1d 100644
--- bin/cp/cp.1
+++ bin/cp/cp.1
@@ -41,14 +41,14 @@
 .Nd copy files
 .Sh SYNOPSIS
 .Nm cp
-.Op Fl fip
+.Op Fl fipv
 .Oo
 .Fl R
 .Op Fl H | L | P
 .Oc
 .Ar source target
 .Nm cp
-.Op Fl fip
+.Op Fl fipv
 .Oo
 .Fl R
 .Op Fl H | L | P
@@ -145,6 +145,8 @@ use a utility such as
 or
 .Xr tar 1
 instead.
+.It Fl v
+Explain what is being done.
 .El
 .Pp
 For each destination file that already exists, its contents are
diff --git bin/cp/cp.c bin/cp/cp.c
index 643d82ed9fa..819e02f7be8 100644
--- bin/cp/cp.c
+++ bin/cp/cp.c
@@ -71,7 +71,7 @@
 PATH_T to = { to.p_path, "" };
 
 uid_t myuid;
-int Rflag, fflag, iflag, pflag, rflag;
+int Rflag, fflag, iflag, pflag, rflag, vflag;
 mode_t myumask;
 
 enum op { FILE_TO_FILE, FILE_TO_DIR, DIR_TO_DNE };
@@ -88,7 +88,7 @@ main(int argc, char *argv[])
char *target;
 
Hflag = Lflag = Pflag = Rflag = 0;
-   while ((ch = getopt(argc, argv, "HLPRfipr")) != -1)
+   while ((ch = getopt(argc, argv, "HLPRfiprv")) != -1)
switch (ch) {
case 'H':
Hflag = 1;
@@ -119,6 +119,9 @@ main(int argc, char *argv[])
case 'r':
rflag = 1;
break;
+   case 'v':
+   vflag = 1;
+   break;
default:
usage();
break;
@@ -394,6 +397,9 @@ copy(char *argv[], enum op type, int fts_options)
case S_IFLNK:
if (copy_link(curr, !fts_dne(curr)))
rval = 1;
+   else if (vflag)
+   (void)fprintf(stdout, "'%s' -> '%s'\n",
+   curr->fts_path, to.p_path);
break;
case S_IFDIR:
if (!Rflag && !rflag) {
@@ -415,6 +421,9 @@ copy(char *argv[], enum op type, int fts_options)
if (mkdir(to.p_path,
curr->fts_statp->st_mode | S_IRWXU) < 0)
err(1, "%s", to.p_path);
+   else if (vflag)
+   (void)fprintf(stdout, "'%s' -> '%s'\n",
+   curr->fts_path, to.p_path);
} else if (!S_ISDIR(to_stat.st_mode))
errc(1, ENOTDIR, "%s", to.p_path);
break;
@@ -426,6 +435,9 @@ copy(char *argv[], enum op type, int fts_options)
} else
if (copy_file(curr, fts_dne(curr)))
rval = 1;
+   if (!rval && vflag)
+   (void)fprintf(stdout, "'%s' -> '%s'\n",
+   curr->fts_path, to.p_path);
break;
case S_IFIFO:
if (Rflag) {
@@ -434,6 +446,9 @@ copy(char *argv[], enum op type, int fts_options)
} else
if (copy_file(curr, fts_dne(curr)))
rval = 1;
+   if (!rval && vflag)
+   (void)fprintf(stdout, "'%s' -> '%s'\n",
+   curr->fts_path, to.p_path);
break;
case S_IFSOCK:
warnc(EOPNOTSUPP, "%s", curr->fts_path);
@@ -441,6 +456,9 @@ copy(char *argv[], enum op type, int fts_options)
default:
if (copy_file(curr, fts_dne(curr)))
rval = 1;
+   else if (vflag)
+   (void)fprintf(stdout, "'%s' -> '%s'\n",
+   curr->fts_path, to.p_path);
break;
}
}
diff --git bin/cp/utils.c bin/cp/utils.c
index 6a3c5178647..2189dd4be1f 100644
--- bin/cp/utils.c
+++ bin/cp/utils.c
@@ -307,9 +307,9 @@ void
 usage(void)
 {
(void)fprintf(stderr,
-   "usage: %s [-fip] [-R [-H | -L | -P]] source target\n", __progname);
+   "usage: %s [-fipv] [-R [-H | -L | -P]] source target\n", 
__progname);
(void)fprintf(stderr,
-   "   %s [-fip] [-R [-H | -L | -P]] source ... directory\n",
+   "   %s [-fipv] [-R [-H | -L | -P]] source ... directory\n",
__progname);
exit(1);
 }