bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[patch] extra verbose


From: Alexander Nyberg
Subject: [patch] extra verbose
Date: Sun, 15 Feb 2004 00:07:27 +0100

I've always wanted some kind of indicator of time remaining on copying
files. This patch adds a 20 '.' long counter to show progress on files
larger than 500kb with -v flag (maybe should be -vv?).

I couldn't really follow the indentation though, I think it needs some
clean up.

--- src/copy_orig.c     2003-08-30 17:57:32.000000000 +0200
+++ src/copy.c  2004-02-14 23:48:30.000000000 +0100
@@ -216,6 +216,8 @@
   off_t n_read_total = 0;
   int last_write_made_hole = 0;
   int make_holes = (x->sparse_mode == SPARSE_ALWAYS);
+  /* for extensive verbose, 20 dots printed out */
+  int times, itimes, iterationcount, icount, do_vv = 0;

   source_desc = open (src_path, O_RDONLY);
   if (source_desc < 0)
@@ -313,11 +315,29 @@

   buf = (char *) alloca (buf_size + sizeof (int));

+  /* File has to be larger than 500kB and not a device file */
+  if (src_open_sb.st_size > 500000 && src_open_sb.st_rdev == 0 &&
x->verbose) {
+    do_vv = 1;  /* we shall run extensive verbose later */
+    itimes = src_open_sb.st_size / buf_size;
+    times = itimes / 20;
+    iterationcount = icount = 0;
+  }
+
   for (;;)
     {
       ssize_t n_read = read (source_desc, buf, buf_size);
-      if (n_read < 0)
-       {
+
+      if ((iterationcount % times == 0) && do_vv == 1)
+        {
+        printf ("\r[%-20.*s]", icount, "....................");
+        icount++;
+        fflush (stdout);
+        }
+      iterationcount++;
+
+
+  if (n_read < 0)
+  {
 #ifdef EINTR
          if (errno == EINTR)
            continue;
@@ -327,8 +347,11 @@
          goto close_src_and_dst_desc;
        }
       if (n_read == 0)
+    {
+    if (do_vv == 1)
+      printf("\n");
        break;
-
+  }
       n_read_total += n_read;

       ip = 0;





reply via email to

[Prev in Thread] Current Thread [Next in Thread]