From owner-freebsd-bugs@FreeBSD.ORG Fri Oct 22 05:10:09 2010 Return-Path: Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C0619106566C for ; Fri, 22 Oct 2010 05:10:09 +0000 (UTC) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (freefall.freebsd.org [IPv6:2001:4f8:fff6::28]) by mx1.freebsd.org (Postfix) with ESMTP id 8EC1B8FC15 for ; Fri, 22 Oct 2010 05:10:09 +0000 (UTC) Received: from freefall.freebsd.org (localhost [127.0.0.1]) by freefall.freebsd.org (8.14.4/8.14.4) with ESMTP id o9M5A9un031364 for ; Fri, 22 Oct 2010 05:10:09 GMT (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.14.4/8.14.4/Submit) id o9M5A9Tn031363; Fri, 22 Oct 2010 05:10:09 GMT (envelope-from gnats) Date: Fri, 22 Oct 2010 05:10:09 GMT Message-Id: <201010220510.o9M5A9Tn031363@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org From: jhell Cc: Subject: Re: bin/144531: [patch] cp(1) show percentage complete X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: jhell List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Oct 2010 05:10:09 -0000 The following reply was made to PR bin/144531; it has been noted by GNATS. From: jhell To: bug-followup@FreeBSD.org, phil@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--