Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 146964 | Differences between
and this patch

Collapse All | Expand All

(-)coreutils-8.4/src/copy.c (+161 lines)
Lines 16-21 Link Here
16
16
17
/* Extracted from cp.c and librarified by Jim Meyering.  */
17
/* Extracted from cp.c and librarified by Jim Meyering.  */
18
18
19
/* Progress bar support added by Miika Pekkarinen. miipekk@ihme.org */
20
19
#include <config.h>
21
#include <config.h>
20
#include <stdio.h>
22
#include <stdio.h>
21
#include <assert.h>
23
#include <assert.h>
Lines 29-34 Link Here
29
# include <priv.h>
31
# include <priv.h>
30
#endif
32
#endif
31
33
34
#ifdef GWINSZ_IN_SYS_IOCTL
35
# include <sys/ioctl.h>
36
#endif
37
32
#include "system.h"
38
#include "system.h"
33
#include "acl.h"
39
#include "acl.h"
34
#include "backupfile.h"
40
#include "backupfile.h"
Lines 53-58 Link Here
53
#include "write-any-file.h"
59
#include "write-any-file.h"
54
#include "areadlink.h"
60
#include "areadlink.h"
55
#include "yesno.h"
61
#include "yesno.h"
62
#include "xstrtol.h"
63
#include "human.h"
64
#include "quotearg.h"
56
65
57
#if USE_XATTR
66
#if USE_XATTR
58
# include <attr/error_context.h>
67
# include <attr/error_context.h>
Lines 103-108 Link Here
103
/* Initial size of the cp.dest_info hash table.  */
112
/* Initial size of the cp.dest_info hash table.  */
104
#define DEST_INFO_INITIAL_CAPACITY 61
113
#define DEST_INFO_INITIAL_CAPACITY 61
105
114
115
#define SAMPLE_MAX 10
116
106
static bool copy_internal (char const *src_name, char const *dst_name,
117
static bool copy_internal (char const *src_name, char const *dst_name,
107
                           bool new_dst, dev_t device,
118
                           bool new_dst, dev_t device,
108
                           struct dir_list *ancestors,
119
                           struct dir_list *ancestors,
Lines 457-462 Link Here
457
  return lchmod (name, mode);
468
  return lchmod (name, mode);
458
}
469
}
459
470
471
/* Shorten a string '/long path/long file' to 'long fi...'
472
   Also adds padding bytes to end of the string if necessary */
473
char *shorten_name(const char *str, size_t max_width)
474
{
475
  char *shortname;
476
  const char *filename;
477
  size_t len;
478
479
  filename = base_name (str);
480
  len = strlen(filename);
481
  shortname = (char *) xmalloc (max_width + 1);
482
  strncpy (shortname, filename, max_width);
483
  shortname[max_width] = '\0';
484
  if (len > max_width)
485
    {
486
      memset(shortname + max_width - 3, '.', 3);
487
    }
488
  else
489
    {
490
      memset(shortname + len, ' ', max_width - len);
491
    }
492
493
  return shortname;
494
}
495
460
/* Copy a regular file from SRC_NAME to DST_NAME.
496
/* Copy a regular file from SRC_NAME to DST_NAME.
461
   If the source file contains holes, copies holes and blocks of zeros
497
   If the source file contains holes, copies holes and blocks of zeros
462
   in the source file as holes in the destination file.
498
   in the source file as holes in the destination file.
Lines 486-491 Link Here
486
  struct stat src_open_sb;
522
  struct stat src_open_sb;
487
  bool return_val = true;
523
  bool return_val = true;
488
  bool data_copy_required = true;
524
  bool data_copy_required = true;
525
  time_t t_start;
526
  time_t t_last;
527
  time_t t_now;
528
  off_t last_bytes = 0;
529
  int progress_bar_printed = 0;
530
  char *shortname = NULL;
531
  off_t sample_window[SAMPLE_MAX];
532
  off_t sample_sum = 0;
533
  int sample_count = 0;
534
  long int line_length = 0;
535
#ifdef TIOCGWINSZ
536
  struct winsize ws;
537
#endif
489
538
490
  source_desc = open (src_name,
539
  source_desc = open (src_name,
491
                      (O_RDONLY | O_BINARY
540
                      (O_RDONLY | O_BINARY
Lines 706-711 Link Here
706
      buf_alloc = xmalloc (buf_size + buf_alignment_slop);
755
      buf_alloc = xmalloc (buf_size + buf_alignment_slop);
707
      buf = ptr_align (buf_alloc, buf_alignment);
756
      buf = ptr_align (buf_alloc, buf_alignment);
708
757
758
      time (&t_start);
759
      t_last = t_start;
760
709
      for (;;)
761
      for (;;)
710
        {
762
        {
711
          word *wp = NULL;
763
          word *wp = NULL;
Lines 787-792 Link Here
787
                 file.  Unfortunately that doesn't work for certain files in
839
                 file.  Unfortunately that doesn't work for certain files in
788
                 /proc with linux kernels from at least 2.6.9 .. 2.6.29.  */
840
                 /proc with linux kernels from at least 2.6.9 .. 2.6.29.  */
789
            }
841
            }
842
843
      time (&t_now);
844
845
      /* Progress bar stuff */
846
      if (! x->pbar_show || t_now - t_start < x->pbar_delay)
847
	{
848
	  continue;
849
	}
850
851
      if (! progress_bar_printed)
852
	{
853
	  /* Column width check code copied from ls.c */
854
	  char const *p = getenv ("COLUMNS");
855
	  if (p && *p)
856
	    {
857
	      long int tmp_long;
858
	      if (xstrtol (p, NULL, 0, &tmp_long, NULL) == LONGINT_OK
859
		  && 0 < tmp_long && tmp_long <= INT_MAX)
860
		{
861
		  line_length = tmp_long;
862
		}
863
	      else
864
		{
865
		  error (0, 0,
866
			 _("ignoring invalid width in environment \
867
			 variable COLUMNS: %s"),
868
			 quotearg (p));
869
		}
870
	    }
871
872
#ifdef TIOCGWINSZ
873
	  if (ioctl (STDOUT_FILENO, TIOCGWINSZ, &ws) != -1 && ws.ws_col != 0)
874
	    {
875
	      line_length = ws.ws_col;
876
	    }
877
#endif
878
	  if (line_length < 50)
879
	    {
880
	      continue;
881
	    }
882
883
	  /* Take a short filename for progress bar */
884
	  shortname = shorten_name(src_name, line_length - 48);
885
	  progress_bar_printed = 1;
886
        }
887
888
      if (t_now == t_last)
889
        {
890
          continue;
891
        }
892
893
      if (sample_count == SAMPLE_MAX)
894
        {
895
          int i;
896
897
          sample_sum -= sample_window[0];
898
          for (i = 0; i < SAMPLE_MAX - 1; i++)
899
	    {
900
	      sample_window[i] = sample_window[i + 1];
901
	    }
902
	}
903
      else
904
	{
905
	  sample_count++;
906
	}
907
908
      {
909
	char str_size[LONGEST_HUMAN_READABLE + 1];
910
	char str_speed[LONGEST_HUMAN_READABLE + 1];
911
	char etabuf[64];
912
	time_t t_temp;
913
914
	sample_window[sample_count - 1] = (n_read_total - last_bytes) /
915
	                                  (t_now - t_last);
916
	sample_sum += sample_window[sample_count - 1];
917
918
	/* Calculate the remaining time */
919
	t_temp = (src_open_sb.st_size - n_read_total) / (sample_sum / sample_count);
920
921
	/* Don't print the progress bar if the estimated remaining
922
	   time is low. */
923
	if (progress_bar_printed == 1 && t_temp < x->pbar_min_est)
924
	  {
925
	    continue;
926
	  }
927
	progress_bar_printed = 2;
928
929
	strftime(etabuf, sizeof etabuf, "%H:%M.%S", 
930
	         gmtime(&t_temp));
931
	printf (_("%s | %3lu%% | %9s | %9s/s | ETA %s\r"), shortname,
932
	        (unsigned long)(n_read_total * 100 / src_open_sb.st_size),
933
	        human_readable(src_open_sb.st_size, str_size, human_autoscale|human_base_1024|human_space_before_unit|human_SI|human_B, 1, 1),
934
	        human_readable(sample_sum / sample_count, str_speed, human_autoscale|human_base_1024|human_space_before_unit|human_SI|human_B, 1, 1),
935
	        etabuf);
936
	fflush (stdout);
937
	t_last = t_now;
938
	last_bytes = n_read_total;
939
      }
940
    }
941
942
  /* Print a newline if progress bar is enabled and has been shown */
943
  if (progress_bar_printed == 2)
944
    {
945
      printf ("%s | 100%%\n", shortname);
790
        }
946
        }
791
947
792
      /* If the file ends with a `hole', we need to do something to record
948
      /* If the file ends with a `hole', we need to do something to record
Lines 900-905 Link Here
900
      return_val = false;
1056
      return_val = false;
901
    }
1057
    }
902
1058
1059
  if (shortname != NULL)
1060
    {
1061
      free (shortname);
1062
    }
1063
903
  free (buf_alloc);
1064
  free (buf_alloc);
904
  free (name_alloc);
1065
  free (name_alloc);
905
  return return_val;
1066
  return return_val;
(-)coreutils-8.4/src/copy.h (-1 / +11 lines)
Lines 228-234 Link Here
228
228
229
  /* If true, display the names of the files before copying them. */
229
  /* If true, display the names of the files before copying them. */
230
  bool verbose;
230
  bool verbose;
231
231
  
232
  /* If true, display a progress bar when the following conditions are
233
   * met:
234
     - pbar_delay defines how many seconds to wait before considering to
235
       display the progress bar
236
     - pbar_min_est defines how many seconds estimated operation complete
237
       time should be at least to show the progress bar. */
238
  bool pbar_show;
239
  int pbar_delay;
240
  int pbar_min_est;
241
  
232
  /* If true, stdin is a tty.  */
242
  /* If true, stdin is a tty.  */
233
  bool stdin_tty;
243
  bool stdin_tty;
234
244
(-)coreutils-8.4/src/cp.c (-1 / +20 lines)
Lines 49-54 Link Here
49
    }							\
49
    }							\
50
  while (0)
50
  while (0)
51
51
52
/* Initial settings for progress bar when it's enabled.
53
   PROGRESS_DELAY defines how many seconds to wait before even
54
   considering to display a proggress bar.
55
   PROGRESS_MIN_EST defines how many seconds estimated operation
56
   complete time should be at least to show the progress bar. */
57
#define PROGRESS_DELAY    5
58
#define PROGRESS_MIN_EST  5
59
52
/* The official name of this program (e.g., no `g' prefix).  */
60
/* The official name of this program (e.g., no `g' prefix).  */
53
#define PROGRAM_NAME "cp"
61
#define PROGRAM_NAME "cp"
54
62
Lines 119-124 Link Here
119
  {"copy-contents", no_argument, NULL, COPY_CONTENTS_OPTION},
127
  {"copy-contents", no_argument, NULL, COPY_CONTENTS_OPTION},
120
  {"dereference", no_argument, NULL, 'L'},
128
  {"dereference", no_argument, NULL, 'L'},
121
  {"force", no_argument, NULL, 'f'},
129
  {"force", no_argument, NULL, 'f'},
130
  {"progress", no_argument, NULL, 'g'},
122
  {"interactive", no_argument, NULL, 'i'},
131
  {"interactive", no_argument, NULL, 'i'},
123
  {"link", no_argument, NULL, 'l'},
132
  {"link", no_argument, NULL, 'l'},
124
  {"no-clobber", no_argument, NULL, 'n'},
133
  {"no-clobber", no_argument, NULL, 'n'},
Lines 176-181 Link Here
176
  -f, --force                  if an existing destination file cannot be\n\
185
  -f, --force                  if an existing destination file cannot be\n\
177
                                 opened, remove it and try again (redundant if\n\
186
                                 opened, remove it and try again (redundant if\n\
178
                                 the -n option is used)\n\
187
                                 the -n option is used)\n\
188
  -g, --progress               show a progress bar if operation is going to\n\
189
                                 take a long time\n\
179
  -i, --interactive            prompt before overwrite (overrides a previous -n\n\
190
  -i, --interactive            prompt before overwrite (overrides a previous -n\n\
180
                                  option)\n\
191
                                  option)\n\
181
  -H                           follow command-line symbolic links in SOURCE\n\
192
  -H                           follow command-line symbolic links in SOURCE\n\
Lines 793-798 Link Here
793
804
794
  x->update = false;
805
  x->update = false;
795
  x->verbose = false;
806
  x->verbose = false;
807
  
808
  x->pbar_show = false;
809
  x->pbar_delay = PROGRESS_DELAY;
810
  x->pbar_min_est = PROGRESS_MIN_EST;
796
811
797
  /* By default, refuse to open a dangling destination symlink, because
812
  /* By default, refuse to open a dangling destination symlink, because
798
     in general one cannot do that safely, give the current semantics of
813
     in general one cannot do that safely, give the current semantics of
Lines 923-929 Link Here
923
     we'll actually use backup_suffix_string.  */
938
     we'll actually use backup_suffix_string.  */
924
  backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX");
939
  backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX");
925
940
926
  while ((c = getopt_long (argc, argv, "abdfHilLnprst:uvxPRS:T",
941
  while ((c = getopt_long (argc, argv, "abdfgHilLnprst:uvxPRS:T",
927
                           long_opts, NULL))
942
                           long_opts, NULL))
928
         != -1)
943
         != -1)
929
    {
944
    {
Lines 975-980 Link Here
975
          x.unlink_dest_after_failed_open = true;
990
          x.unlink_dest_after_failed_open = true;
976
          break;
991
          break;
977
992
993
        case 'g':
994
          x.pbar_show = true;
995
          break;
996
  
978
        case 'H':
997
        case 'H':
979
          x.dereference = DEREF_COMMAND_LINE_ARGUMENTS;
998
          x.dereference = DEREF_COMMAND_LINE_ARGUMENTS;
980
          break;
999
          break;
(-)coreutils-8.4/src/mv.c (-1 / +24 lines)
Lines 34-39 Link Here
34
#include "root-dev-ino.h"
34
#include "root-dev-ino.h"
35
#include "priv-set.h"
35
#include "priv-set.h"
36
36
37
/* Initial settings for progress bar when it's enabled.
38
   PROGRESS_DELAY defines how many seconds to wait before even
39
   considering to display a proggress bar.
40
   PROGRESS_MIN_EST defines how many seconds estimated operation
41
   complete time should be at least to show the progress bar. */
42
#define PROGRESS_DELAY    5
43
#define PROGRESS_MIN_EST  5
44
37
/* The official name of this program (e.g., no `g' prefix).  */
45
/* The official name of this program (e.g., no `g' prefix).  */
38
#define PROGRAM_NAME "mv"
46
#define PROGRAM_NAME "mv"
39
47
Lines 56-61 Link Here
56
{
64
{
57
  {"backup", optional_argument, NULL, 'b'},
65
  {"backup", optional_argument, NULL, 'b'},
58
  {"force", no_argument, NULL, 'f'},
66
  {"force", no_argument, NULL, 'f'},
67
  {"progress", no_argument, NULL, 'g'},
59
  {"interactive", no_argument, NULL, 'i'},
68
  {"interactive", no_argument, NULL, 'i'},
60
  {"no-clobber", no_argument, NULL, 'n'},
69
  {"no-clobber", no_argument, NULL, 'n'},
61
  {"no-target-directory", no_argument, NULL, 'T'},
70
  {"no-target-directory", no_argument, NULL, 'T'},
Lines 83-88 Link Here
83
92
84
  x->verbose = false;
93
  x->verbose = false;
85
94
95
  x->pbar_show = false;
96
  x->pbar_delay = PROGRESS_DELAY;
97
  x->pbar_min_est = PROGRESS_MIN_EST;
98
  
86
  /* Since this program may well have to process additional command
99
  /* Since this program may well have to process additional command
87
     line arguments after any call to `rm', that function must preserve
100
     line arguments after any call to `rm', that function must preserve
88
     the initial working directory, in case one of those is a
101
     the initial working directory, in case one of those is a
Lines 133-138 Link Here
133
  x->open_dangling_dest_symlink = false;
146
  x->open_dangling_dest_symlink = false;
134
  x->update = false;
147
  x->update = false;
135
  x->verbose = false;
148
  x->verbose = false;
149
  
150
  x->pbar_show = false;
151
  x->pbar_delay = PROGRESS_DELAY;
152
  x->pbar_min_est = PROGRESS_MIN_EST;
153
   
136
  x->dest_info = NULL;
154
  x->dest_info = NULL;
137
  x->src_info = NULL;
155
  x->src_info = NULL;
138
}
156
}
Lines 298-303 Link Here
298
      --backup[=CONTROL]       make a backup of each existing destination file\n\
316
      --backup[=CONTROL]       make a backup of each existing destination file\n\
299
  -b                           like --backup but does not accept an argument\n\
317
  -b                           like --backup but does not accept an argument\n\
300
  -f, --force                  do not prompt before overwriting\n\
318
  -f, --force                  do not prompt before overwriting\n\
319
  -g, --progress               show a progress bar if operation is going to\n\
320
                                  take a long time\n\
301
  -i, --interactive            prompt before overwrite\n\
321
  -i, --interactive            prompt before overwrite\n\
302
  -n, --no-clobber             do not overwrite an existing file\n\
322
  -n, --no-clobber             do not overwrite an existing file\n\
303
If you specify more than one of -i, -f, -n, only the final one takes effect.\n\
323
If you specify more than one of -i, -f, -n, only the final one takes effect.\n\
Lines 366-372 Link Here
366
     we'll actually use backup_suffix_string.  */
386
     we'll actually use backup_suffix_string.  */
367
  backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX");
387
  backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX");
368
388
369
  while ((c = getopt_long (argc, argv, "bfint:uvS:T", long_options, NULL))
389
  while ((c = getopt_long (argc, argv, "bfgint:uvS:T", long_options, NULL))
370
         != -1)
390
         != -1)
371
    {
391
    {
372
      switch (c)
392
      switch (c)
Lines 379-384 Link Here
379
        case 'f':
399
        case 'f':
380
          x.interactive = I_ALWAYS_YES;
400
          x.interactive = I_ALWAYS_YES;
381
          break;
401
          break;
402
        case 'g':
403
          x.pbar_show = true;
404
          break;
382
        case 'i':
405
        case 'i':
383
          x.interactive = I_ASK_USER;
406
          x.interactive = I_ASK_USER;
384
          break;
407
          break;
(-)coreutils-8.4/src/remove.h (+10 lines)
Lines 58-63 Link Here
58
58
59
  /* If true, display the name of each file removed.  */
59
  /* If true, display the name of each file removed.  */
60
  bool verbose;
60
  bool verbose;
61
   
62
  /* If true, display a progress bar when the following conditions are
63
   * met:
64
     - pbar_delay defines how many seconds to wait before considering to
65
       display the progress bar
66
     - pbar_min_est defines how many seconds estimated operation complete
67
       time should be at least to show the progress bar. */
68
  bool pbar_show;
69
  int pbar_delay;
70
  int pbar_min_est;
61
71
62
  /* If true, treat the failure by the rm function to restore the
72
  /* If true, treat the failure by the rm function to restore the
63
     current working directory as a fatal error.  I.e., if this field
73
     current working directory as a fatal error.  I.e., if this field

Return to bug 146964