bin/144531: [patch] cp(1) show percentage complete

jhell jhell at DataIX.net
Fri Oct 22 05:10:09 UTC 2010


The following reply was made to PR bin/144531; it has been noted by GNATS.

From: jhell <jhell at DataIX.net>
To: bug-followup at FreeBSD.org, phil at philpep.org
Cc:  
Subject: Re: bin/144531: [patch] cp(1) show percentage complete
Date: Fri, 22 Oct 2010 01:04:03 -0400

 This is a multi-part message in MIME format.
 --------------060607040004000800040604
 Content-Type: text/plain; charset=ISO-8859-1
 Content-Transfer-Encoding: 7bit
 
 
 Just for the record, I had adjusted this for local use. And while being
 a useful feature especially when it comes to doing simple operations
 such as cp(1), I also find this to be very handy as standard cp(1) does
 not let you see what it is actually copying until after the copy has
 completed.
 
 Also for the record "The -v and -n options are non-standard and their
 use in scripts is not recommended."
 
 I don't see a reason why there should/could not be another non-standard
 feature added as -v as I stated is not really useful until the actual
 copy of the file has completed.
 
 The local mods that I made for this patch was to make it take '-V' as a
 argument instead of defaulting to '-v' and adjusting the manual page to
 properly document it.
 
 Patch is attached for archive sake.
 
 It is a shame it couldn't be incorporated.
 
 -- 
 
  jhell,v
 
 --------------060607040004000800040604
 Content-Type: text/plain;
  name="cp-show-progress.patch"
 Content-Transfer-Encoding: 7bit
 Content-Disposition: attachment;
  filename="cp-show-progress.patch"
 
 Index: bin/cp/cp.1
 ===================================================================
 --- bin/cp/cp.1	(revision 214190)
 +++ bin/cp/cp.1	(working copy)
 @@ -45,7 +45,7 @@
  .Op Fl H | Fl L | Fl P
  .Oc
  .Op Fl f | i | n
 -.Op Fl alpvx
 +.Op Fl alpvVx
  .Ar source_file target_file
  .Nm
  .Oo
 @@ -53,7 +53,7 @@
  .Op Fl H | Fl L | Fl P
  .Oc
  .Op Fl f | i | n
 -.Op Fl alpvx
 +.Op Fl alpvVx
  .Ar source_file ... target_directory
  .Sh DESCRIPTION
  In the first synopsis form, the
 @@ -183,6 +183,11 @@
  Cause
  .Nm
  to be verbose, showing files as they are copied.
 +.It Fl V
 +Cause
 +.Nm
 +to be very verbose, showing files as they are copied and printing a
 +percentage of its progress while copying.
  .It Fl x
  File system mount points are not traversed.
  .El
 @@ -278,6 +283,7 @@
  .Pp
  The
  .Fl v
 +.Fl V
  and
  .Fl n
  options are non-standard and their use in scripts is not recommended.
 Index: bin/cp/utils.c
 ===================================================================
 --- bin/cp/utils.c	(revision 214190)
 +++ bin/cp/utils.c	(working copy)
 @@ -216,6 +216,11 @@
  						    entp->fts_path, to.p_path,
  						    cp_pct(wtotal, fs->st_size));
  					}
 +					if (vflag == 2)
 +						(void)fprintf(stderr,
 +							"%s -> %s %3d%%\033[0G",
 +							entp->fts_path, to.p_path,
 +							cp_pct(wtotal, fs->st_size));
  					if (wcount >= (ssize_t)wresid)
  						break;
  				}
 @@ -518,8 +523,8 @@
  {
  
  	(void)fprintf(stderr, "%s\n%s\n",
 -"usage: cp [-R [-H | -L | -P]] [-f | -i | -n] [-alpvx] source_file target_file",
 -"       cp [-R [-H | -L | -P]] [-f | -i | -n] [-alpvx] source_file ... "
 +"usage: cp [-R [-H | -L | -P]] [-f | -i | -n] [-alpvVx] source_file target_file",
 +"       cp [-R [-H | -L | -P]] [-f | -i | -n] [-alpvVx] source_file ... "
  "target_directory");
  	exit(EX_USAGE);
  }
 Index: bin/cp/cp.c
 ===================================================================
 --- bin/cp/cp.c	(revision 214190)
 +++ bin/cp/cp.c	(working copy)
 @@ -103,7 +103,7 @@
  
  	fts_options = FTS_NOCHDIR | FTS_PHYSICAL;
  	Hflag = Lflag = Pflag = 0;
 -	while ((ch = getopt(argc, argv, "HLPRafilnprvx")) != -1)
 +	while ((ch = getopt(argc, argv, "HLPRVafilnprvx")) != -1)
  		switch (ch) {
  		case 'H':
  			Hflag = 1;
 @@ -151,6 +151,9 @@
  		case 'v':
  			vflag = 1;
  			break;
 +		case 'V':
 +			vflag = 2;
 +			break;
  		case 'x':
  			fts_options |= FTS_XDEV;
  			break;
 @@ -480,8 +483,10 @@
  				badcp = rval = 1;
  			break;
  		}
 -		if (vflag && !badcp)
 +		if (vflag == 1 && !badcp)
  			(void)printf("%s -> %s\n", curr->fts_path, to.p_path);
 +		if (vflag == 2 && !badcp)
 +			(void)printf("%s -> %s 100%%\n", curr->fts_path, to.p_path);
  	}
  	if (errno)
  		err(1, "fts_read");
 
 --------------060607040004000800040604--


More information about the freebsd-bugs mailing list