show global progressbar when moving files in copy mode (between devices)

This commit is contained in:
Michael Wehr
2021-12-23 19:21:33 +01:00
parent e529e310ea
commit 3ac56d553f

View File

@@ -1,6 +1,6 @@
diff -aur coreutils-9.0/src/copy.c coreutils-9.0-patched/src/copy.c diff -aur coreutils-9.0/src/copy.c coreutils-9.0-patched/src/copy.c
--- coreutils-9.0/src/copy.c 2021-09-24 13:31:05.000000000 +0200 --- coreutils-9.0/src/copy.c 2021-09-24 13:31:05.000000000 +0200
+++ coreutils-9.0-patched/src/copy.c 2021-12-23 18:50:20.771131070 +0100 +++ coreutils-9.0-patched/src/copy.c 2021-12-23 19:13:54.313100934 +0100
@@ -129,6 +129,101 @@ @@ -129,6 +129,101 @@
dev_t dev; dev_t dev;
}; };
@@ -269,7 +269,7 @@ diff -aur coreutils-9.0/src/copy.c coreutils-9.0-patched/src/copy.c
return false; return false;
dest_pos = ext_start + n_read; dest_pos = ext_start + n_read;
@@ -1374,8 +1587,78 @@ @@ -1374,8 +1587,82 @@
buf_alloc = xmalloc (buf_size + buf_alignment); buf_alloc = xmalloc (buf_size + buf_alignment);
buf = ptr_align (buf_alloc, buf_alignment); buf = ptr_align (buf_alloc, buf_alignment);
@@ -308,7 +308,11 @@ diff -aur coreutils-9.0/src/copy.c coreutils-9.0-patched/src/copy.c
+ file_size_format ( cProgressField[1] + iBarLength - 9, g_iTotalSize, 1 ); + file_size_format ( cProgressField[1] + iBarLength - 9, g_iTotalSize, 1 );
+ +
+ /* show how many files were written */ + /* show how many files were written */
+ int sum_length = sprintf ( cProgressField[1], "%d files copied so far...", g_iFilesCopied ); + int sum_length = 0;
+ if ( x->move_mode )
+ sum_length = sprintf ( cProgressField[1], "%d files moved so far...", g_iFilesCopied );
+ else
+ sum_length = sprintf ( cProgressField[1], "%d files copied so far...", g_iFilesCopied );
+ cProgressField[1][sum_length] = ' '; + cProgressField[1][sum_length] = ' ';
+ } + }
+ +
@@ -348,7 +352,7 @@ diff -aur coreutils-9.0/src/copy.c coreutils-9.0-patched/src/copy.c
if (! ( if (! (
#ifdef SEEK_HOLE #ifdef SEEK_HOLE
scantype == LSEEK_SCANTYPE scantype == LSEEK_SCANTYPE
@@ -1383,15 +1666,30 @@ @@ -1383,15 +1670,30 @@
scan_inference.ext_start, src_open_sb.st_size, scan_inference.ext_start, src_open_sb.st_size,
make_holes ? x->sparse_mode : SPARSE_NEVER, make_holes ? x->sparse_mode : SPARSE_NEVER,
x->reflink_mode != REFLINK_NEVER, x->reflink_mode != REFLINK_NEVER,
@@ -381,7 +385,7 @@ diff -aur coreutils-9.0/src/copy.c coreutils-9.0-patched/src/copy.c
{ {
return_val = false; return_val = false;
goto close_src_and_dst_desc; goto close_src_and_dst_desc;
@@ -1402,6 +1700,14 @@ @@ -1402,6 +1704,14 @@
return_val = false; return_val = false;
goto close_src_and_dst_desc; goto close_src_and_dst_desc;
} }
@@ -623,7 +627,7 @@ diff -aur coreutils-9.0/src/cp.c coreutils-9.0-patched/src/cp.c
version_control_string) version_control_string)
diff -aur coreutils-9.0/src/mv.c coreutils-9.0-patched/src/mv.c diff -aur coreutils-9.0/src/mv.c coreutils-9.0-patched/src/mv.c
--- coreutils-9.0/src/mv.c 2021-09-24 13:31:05.000000000 +0200 --- coreutils-9.0/src/mv.c 2021-09-24 13:31:05.000000000 +0200
+++ coreutils-9.0-patched/src/mv.c 2021-12-23 18:47:22.480010369 +0100 +++ coreutils-9.0-patched/src/mv.c 2021-12-23 19:15:58.867551600 +0100
@@ -66,6 +66,9 @@ @@ -66,6 +66,9 @@
{"target-directory", required_argument, NULL, 't'}, {"target-directory", required_argument, NULL, 't'},
{"update", no_argument, NULL, 'u'}, {"update", no_argument, NULL, 'u'},
@@ -634,7 +638,7 @@ diff -aur coreutils-9.0/src/mv.c coreutils-9.0-patched/src/mv.c
{GETOPT_HELP_OPTION_DECL}, {GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL}, {GETOPT_VERSION_OPTION_DECL},
{NULL, 0, NULL, 0} {NULL, 0, NULL, 0}
@@ -170,8 +173,106 @@ @@ -170,8 +173,121 @@
{ {
bool copy_into_self; bool copy_into_self;
bool rename_succeeded; bool rename_succeeded;
@@ -645,6 +649,8 @@ diff -aur coreutils-9.0/src/mv.c coreutils-9.0-patched/src/mv.c
+ if(progress && x->rename_errno != 0) { + if(progress && x->rename_errno != 0) {
+ if (g_iTotalSize == 0) + if (g_iTotalSize == 0)
+ g_iTotalSize = 0; + g_iTotalSize = 0;
+ if (g_iTotalFiles == 0)
+ g_iTotalFiles = 0;
+ if (g_iFilesCopied == 0) + if (g_iFilesCopied == 0)
+ g_iFilesCopied = 0; + g_iFilesCopied = 0;
+ if (g_iDirectoriesCopied == 0) + if (g_iDirectoriesCopied == 0)
@@ -658,19 +664,29 @@ diff -aur coreutils-9.0/src/mv.c coreutils-9.0-patched/src/mv.c
+ gettimeofday (& start_time, NULL); + gettimeofday (& start_time, NULL);
+ g_oStartTime = start_time; + g_oStartTime = start_time;
+ +
+ /* how many files are we copying */
+ char command[1024];
+ char output[1024];
+ FILE *fp ;
+
+ char * _cEscapedString = escape_double_quotes( (unsigned char *)(size_t)source );
+ sprintf( command, "find \"%s\" -type f | wc -l", _cEscapedString );
+ free( _cEscapedString );
+ fp = popen(command,"r");
+ if ( fp == NULL || fgets(output, sizeof(output)-1, fp) == NULL)
+ printf("failed to run find\r");
+ else
+ g_iTotalFiles = atoi( output );
+
+ printf ("calculating total size... \r"); + printf ("calculating total size... \r");
+ fflush (stdout); + fflush (stdout);
+ long iTotalSize = 0; + long iTotalSize = 0;
+ /* call du -s for each file */ + /* call du -s for each file */
+ /* create command */ + /* create command */
+ char command[1024]; + _cEscapedString = escape_double_quotes( (unsigned char *)(size_t)source );
+ char * _cEscapedString = escape_double_quotes( (unsigned char *)(size_t)source );
+ sprintf ( command, "du -s \"%s\"", _cEscapedString ); + sprintf ( command, "du -s \"%s\"", _cEscapedString );
+ free( _cEscapedString ); + free( _cEscapedString );
+ +
+ FILE *fp;
+ char output[1024];
+
+ /* run command */ + /* run command */
+ fp = popen(command, "r"); + fp = popen(command, "r");
+ if (fp == NULL || fgets(output, sizeof(output)-1, fp) == NULL) { + if (fp == NULL || fgets(output, sizeof(output)-1, fp) == NULL) {
@@ -698,9 +714,12 @@ diff -aur coreutils-9.0/src/mv.c coreutils-9.0-patched/src/mv.c
+ /* remove everything */ + /* remove everything */
+ int i; + int i;
+ int limit = (g_iTotalFiles > 1 ? 6 : 3); + int limit = (g_iTotalFiles > 1 ? 6 : 3);
+ if (!rename_succeeded)
+ {
+ for ( i = 0; i < limit; i++ ) + for ( i = 0; i < limit; i++ )
+ printf ( "\033[K\n" ); + printf ( "\033[K\n" );
+ printf ( "\r\033[3A" ); + printf ( "\r\033[3A" );
+ }
+ +
+ /* save time */ + /* save time */
+ struct timeval end_time; + struct timeval end_time;
@@ -741,7 +760,7 @@ diff -aur coreutils-9.0/src/mv.c coreutils-9.0-patched/src/mv.c
if (ok) if (ok)
{ {
char const *dir_to_remove; char const *dir_to_remove;
@@ -306,6 +407,11 @@ @@ -306,6 +422,11 @@
\n\ \n\
-b like --backup but does not accept an argument\n\ -b like --backup but does not accept an argument\n\
-f, --force do not prompt before overwriting\n\ -f, --force do not prompt before overwriting\n\
@@ -753,7 +772,7 @@ diff -aur coreutils-9.0/src/mv.c coreutils-9.0-patched/src/mv.c
-i, --interactive prompt before overwrite\n\ -i, --interactive prompt before overwrite\n\
-n, --no-clobber do not overwrite an existing file\n\ -n, --no-clobber do not overwrite an existing file\n\
If you specify more than one of -i, -f, -n, only the final one takes effect.\n\ If you specify more than one of -i, -f, -n, only the final one takes effect.\n\
@@ -361,7 +467,8 @@ @@ -361,7 +482,8 @@
/* Try to disable the ability to unlink a directory. */ /* Try to disable the ability to unlink a directory. */
priv_set_remove_linkdir (); priv_set_remove_linkdir ();
@@ -763,7 +782,7 @@ diff -aur coreutils-9.0/src/mv.c coreutils-9.0-patched/src/mv.c
!= -1) != -1)
{ {
switch (c) switch (c)
@@ -407,6 +514,11 @@ @@ -407,6 +529,11 @@
case 'v': case 'v':
x.verbose = true; x.verbose = true;
break; break;