backport changes to 8.32 patch

This commit is contained in:
Michael Wehr
2021-12-23 19:35:38 +01:00
parent 3ac56d553f
commit 04bae585e6

View File

@@ -1,10 +1,11 @@
diff -aur coreutils-8.32/src/copy.c coreutils-8.32-patched/src/copy.c diff -aur coreutils-8.32/src/copy.c coreutils-8.32-patched/src/copy.c
--- coreutils-8.32/src/copy.c 2020-01-01 15:13:12.000000000 +0100 --- coreutils-8.32/src/copy.c 2020-01-01 15:13:12.000000000 +0100
+++ coreutils-8.32-patched/src/copy.c 2021-08-11 19:48:19.008225844 +0200 +++ coreutils-8.32-patched/src/copy.c 2021-12-23 19:26:40.665650895 +0100
@@ -129,6 +129,72 @@ @@ -129,6 +129,101 @@
dev_t dev; dev_t dev;
}; };
+/* BEGIN progress mod */
+struct progress_status { +struct progress_status {
+ int iCountDown; + int iCountDown;
+ char ** cProgressField; + char ** cProgressField;
@@ -13,7 +14,37 @@ diff -aur coreutils-8.32/src/copy.c coreutils-8.32-patched/src/copy.c
+ struct stat src_open_sb; + struct stat src_open_sb;
+}; +};
+ +
+/* Begin progress Mod*/ +char * escape_double_quotes ( char * _cUnescapedString )
+{
+ int pos = 0;
+ int count = 0;
+ for(pos = 0; _cUnescapedString[pos] != '\0'; pos++)
+ {
+ if(_cUnescapedString[pos] == '"')
+ ++count;
+ }
+
+ char * _cEscapedString;
+ _cEscapedString = calloc( sizeof(char) * ( pos + 1 + count * 2 ), sizeof(char) );
+
+ int epos = 0;
+ for(pos = 0; _cUnescapedString[pos] != '\0'; pos++)
+ {
+ if(_cUnescapedString[pos] == '"')
+ {
+ _cEscapedString[epos] = '\\';
+ epos++;
+ _cEscapedString[epos] = _cUnescapedString[pos];
+ }
+ else
+ _cEscapedString[epos] = _cUnescapedString[pos];
+ epos++;
+ }
+ epos++;
+ _cEscapedString[epos] = '\0';
+ return _cEscapedString;
+}
+
+static void file_progress_bar ( char * _cDest, int _iBarLength, long _lProgress, long _lTotal ) +static void file_progress_bar ( char * _cDest, int _iBarLength, long _lProgress, long _lTotal )
+{ +{
+ double dPercent = (double) _lProgress / (double) _lTotal * 100.f; + double dPercent = (double) _lProgress / (double) _lTotal * 100.f;
@@ -68,33 +99,35 @@ diff -aur coreutils-8.32/src/copy.c coreutils-8.32-patched/src/copy.c
+ return sprintf ( _cDst, "%5.1f %s", dSize, sUnit ); + return sprintf ( _cDst, "%5.1f %s", dSize, sUnit );
+} +}
+/* END progress mod */ +/* END progress mod */
+
+
+ +
/* Initial size of the cp.dest_info hash table. */ /* Initial size of the cp.dest_info hash table. */
#define DEST_INFO_INITIAL_CAPACITY 61 #define DEST_INFO_INITIAL_CAPACITY 61
@@ -258,10 +324,11 @@ @@ -259,9 +354,16 @@
bytes read. */
static bool static bool
sparse_copy (int src_fd, int dest_fd, char *buf, size_t buf_size, sparse_copy (int src_fd, int dest_fd, char *buf, size_t buf_size,
- size_t hole_size, bool punch_holes, size_t hole_size, bool punch_holes,
+ size_t hole_size, bool punch_holes, bool move_mode, + /* BEGIN progress mod */
+ bool move_mode,
+ /* END progress mod */
char const *src_name, char const *dst_name, char const *src_name, char const *dst_name,
uintmax_t max_n_read, off_t *total_n_read, uintmax_t max_n_read, off_t *total_n_read,
- bool *last_write_made_hole) - bool *last_write_made_hole)
+ bool *last_write_made_hole, + bool *last_write_made_hole
+ struct progress_status *s_progress) + /* BEGIN progress mod */
+ , struct progress_status *s_progress
+ /* END progress mod */
+ )
{ {
*last_write_made_hole = false; *last_write_made_hole = false;
*total_n_read = 0; *total_n_read = 0;
@@ -270,6 +337,85 @@ @@ -270,6 +372,85 @@
while (max_n_read) while (max_n_read)
{ {
+ +
+ if (progress) {
+ /* BEGIN progress mod */ + /* BEGIN progress mod */
+ if (progress) {
+ /* update countdown */ + /* update countdown */
+ s_progress->iCountDown--; + s_progress->iCountDown--;
+ char * sProgressBar = s_progress->cProgressField[5]; + char * sProgressBar = s_progress->cProgressField[5];
@@ -130,8 +163,8 @@ diff -aur coreutils-8.32/src/copy.c coreutils-8.32-patched/src/copy.c
+ /* print out */ + /* print out */
+ sprintf ( s_progress->cProgressField[3], + sprintf ( s_progress->cProgressField[3],
+ move_mode + move_mode
+ ? "Moving at %s/s (about %uh %um %us remaining)" + ? "moving at %s/s (about %uh %um %us remaining)"
+ : "Copying at %s/s (about %uh %um %us remaining)", s_copy_speed, + : "copying at %s/s (about %uh %um %us remaining)", s_copy_speed,
+ hours_remaining, min_remaining, sec_remaining ); + hours_remaining, min_remaining, sec_remaining );
+ +
+ int fs_len; + int fs_len;
@@ -168,13 +201,13 @@ diff -aur coreutils-8.32/src/copy.c coreutils-8.32-patched/src/copy.c
+ printf ( "\r\033[3A" ); + printf ( "\r\033[3A" );
+ fflush ( stdout ); + fflush ( stdout );
+ } + }
+ /* END progress mod */
+ } + }
+ /* END progress mod */
+ +
ssize_t n_read = read (src_fd, buf, MIN (max_n_read, buf_size)); ssize_t n_read = read (src_fd, buf, MIN (max_n_read, buf_size));
if (n_read < 0) if (n_read < 0)
{ {
@@ -354,6 +500,14 @@ @@ -354,6 +535,14 @@
certain files in /proc or /sys with linux kernels. */ certain files in /proc or /sys with linux kernels. */
} }
@@ -189,7 +222,7 @@ diff -aur coreutils-8.32/src/copy.c coreutils-8.32-patched/src/copy.c
/* Ensure a trailing hole is created, so that subsequent /* Ensure a trailing hole is created, so that subsequent
calls of sparse_copy() start at the correct offset. */ calls of sparse_copy() start at the correct offset. */
if (make_hole && ! create_hole (dest_fd, dst_name, punch_holes, psize)) if (make_hole && ! create_hole (dest_fd, dst_name, punch_holes, psize))
@@ -420,9 +574,11 @@ @@ -420,9 +609,11 @@
static bool static bool
extent_copy (int src_fd, int dest_fd, char *buf, size_t buf_size, extent_copy (int src_fd, int dest_fd, char *buf, size_t buf_size,
size_t hole_size, off_t src_total_size, size_t hole_size, off_t src_total_size,
@@ -203,26 +236,36 @@ diff -aur coreutils-8.32/src/copy.c coreutils-8.32-patched/src/copy.c
{ {
struct extent_scan scan; struct extent_scan scan;
off_t last_ext_start = 0; off_t last_ext_start = 0;
@@ -553,10 +709,16 @@ @@ -553,10 +744,26 @@
last_ext_len = ext_len; last_ext_len = ext_len;
bool read_hole; bool read_hole;
+ /* BEGIN progress mod */
+ struct timeval a; + struct timeval a;
+ struct stat b; + struct stat b;
+ +
+ struct progress_status s_progress={iCountDown, cProgressField, last_time, last_size, iBarLength, src_open_sb}; + struct progress_status s_progress={iCountDown, cProgressField, last_time, last_size, iBarLength, src_open_sb};
+ /* END progress mod */
+ +
+ +
if ( ! sparse_copy (src_fd, dest_fd, buf, buf_size, if ( ! sparse_copy (src_fd, dest_fd, buf, buf_size,
sparse_mode == SPARSE_ALWAYS ? hole_size: 0, sparse_mode == SPARSE_ALWAYS ? hole_size: 0,
- true, src_name, dst_name, ext_len, &n_read, - true, src_name, dst_name, ext_len, &n_read,
- &read_hole)) - &read_hole))
+ true, move_mode, src_name, dst_name, ext_len, + true,
+ &n_read, &read_hole,&s_progress)) + /* BEGIN progress mod */
+ move_mode,
+ /* END progress mod */
+ src_name, dst_name, ext_len, &n_read,
+ &read_hole
+ /* BEGIN progress mod */
+ ,&s_progress
+ /* END progress mod */
+ ))
goto fail; goto fail;
dest_pos = ext_start + n_read; dest_pos = ext_start + n_read;
@@ -1305,6 +1467,71 @@ @@ -1305,6 +1512,75 @@
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);
@@ -261,7 +304,11 @@ diff -aur coreutils-8.32/src/copy.c coreutils-8.32-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] = ' ';
+ } + }
+ +
@@ -294,7 +341,7 @@ diff -aur coreutils-8.32/src/copy.c coreutils-8.32-patched/src/copy.c
if (sparse_src) if (sparse_src)
{ {
bool normal_copy_required; bool normal_copy_required;
@@ -1316,7 +1543,9 @@ @@ -1316,7 +1592,9 @@
if (extent_copy (source_desc, dest_desc, buf, buf_size, hole_size, if (extent_copy (source_desc, dest_desc, buf, buf_size, hole_size,
src_open_sb.st_size, src_open_sb.st_size,
make_holes ? x->sparse_mode : SPARSE_NEVER, make_holes ? x->sparse_mode : SPARSE_NEVER,
@@ -305,23 +352,34 @@ diff -aur coreutils-8.32/src/copy.c coreutils-8.32-patched/src/copy.c
goto preserve_metadata; goto preserve_metadata;
if (! normal_copy_required) if (! normal_copy_required)
@@ -1328,11 +1557,12 @@ @@ -1328,11 +1606,23 @@
off_t n_read; off_t n_read;
bool wrote_hole_at_eof; bool wrote_hole_at_eof;
+
+ /* BEGIN progress mod */
+ struct progress_status s_progress = { iCountDown, cProgressField, last_time, last_size, iBarLength, src_open_sb}; + struct progress_status s_progress = { iCountDown, cProgressField, last_time, last_size, iBarLength, src_open_sb};
+ /* END progress mod */
+
if (! sparse_copy (source_desc, dest_desc, buf, buf_size, if (! sparse_copy (source_desc, dest_desc, buf, buf_size,
make_holes ? hole_size : 0, make_holes ? hole_size : 0,
- x->sparse_mode == SPARSE_ALWAYS, src_name, dst_name, - x->sparse_mode == SPARSE_ALWAYS, src_name, dst_name,
- UINTMAX_MAX, &n_read, - UINTMAX_MAX, &n_read,
- &wrote_hole_at_eof)) - &wrote_hole_at_eof))
+ x->sparse_mode == SPARSE_ALWAYS, x->move_mode, + x->sparse_mode == SPARSE_ALWAYS,
+ /* BEGIN progress mod */
+ x->move_mode,
+ /* END progress mod */
+ src_name, dst_name, UINTMAX_MAX, &n_read, + src_name, dst_name, UINTMAX_MAX, &n_read,
+ &wrote_hole_at_eof, &s_progress)) + &wrote_hole_at_eof
+ /* BEGIN progress mod */
+ , &s_progress
+ /* END progress mod */
+ ))
{ {
return_val = false; return_val = false;
goto close_src_and_dst_desc; goto close_src_and_dst_desc;
@@ -1343,6 +1573,14 @@ @@ -1343,6 +1633,14 @@
return_val = false; return_val = false;
goto close_src_and_dst_desc; goto close_src_and_dst_desc;
} }
@@ -336,7 +394,7 @@ diff -aur coreutils-8.32/src/copy.c coreutils-8.32-patched/src/copy.c
} }
preserve_metadata: preserve_metadata:
@@ -1716,15 +1954,15 @@ @@ -1716,15 +2014,15 @@
fprintf (stderr, fprintf (stderr,
(x->move_mode || x->unlink_dest_before_opening (x->move_mode || x->unlink_dest_before_opening
|| x->unlink_dest_after_failed_open) || x->unlink_dest_after_failed_open)
@@ -357,59 +415,72 @@ diff -aur coreutils-8.32/src/copy.c coreutils-8.32-patched/src/copy.c
diff -aur coreutils-8.32/src/copy.h coreutils-8.32-patched/src/copy.h diff -aur coreutils-8.32/src/copy.h coreutils-8.32-patched/src/copy.h
--- coreutils-8.32/src/copy.h 2020-01-01 15:13:12.000000000 +0100 --- coreutils-8.32/src/copy.h 2020-01-01 15:13:12.000000000 +0100
+++ coreutils-8.32-patched/src/copy.h 2021-08-11 19:40:37.729820358 +0200 +++ coreutils-8.32-patched/src/copy.h 2021-12-23 12:24:33.256775516 +0100
@@ -234,6 +234,9 @@ @@ -234,6 +234,11 @@
Create destination directories as usual. */ Create destination directories as usual. */
bool symbolic_link; bool symbolic_link;
+ /* BEGIN progress mod */
+ /* If true, draw a nice progress bar on screen */ + /* If true, draw a nice progress bar on screen */
+ bool progress_bar; + bool progress_bar;
+ /* END progress mod */
+ +
/* If true, do not copy a nondirectory that has an existing destination /* If true, do not copy a nondirectory that has an existing destination
with the same or newer modification time. */ with the same or newer modification time. */
bool update; bool update;
@@ -304,4 +307,15 @@ @@ -304,4 +309,18 @@
bool chown_failure_ok (struct cp_options const *) _GL_ATTRIBUTE_PURE; bool chown_failure_ok (struct cp_options const *) _GL_ATTRIBUTE_PURE;
mode_t cached_umask (void); mode_t cached_umask (void);
+/* BEGIN OF PROGRESS MOD */ +/* BEGIN progress mod */
+char * escape_double_quotes ( char * _cUnescapedString );
+
+int file_size_format ( char * _cDst, long _lSize, int _iCounter ); +int file_size_format ( char * _cDst, long _lSize, int _iCounter );
+ +
+__attribute__((__common__)) long g_iTotalSize; +__attribute__((__common__)) long g_iTotalSize;
+__attribute__((__common__)) long g_iTotalWritten; +__attribute__((__common__)) long g_iTotalWritten;
+__attribute__((__common__)) int g_iFilesCopied; +__attribute__((__common__)) int g_iFilesCopied;
+__attribute__((__common__)) int g_iDirectoriesCopied;
+__attribute__((__common__)) struct timeval g_oStartTime; +__attribute__((__common__)) struct timeval g_oStartTime;
+__attribute__((__common__)) int g_iTotalFiles; +__attribute__((__common__)) int g_iTotalFiles;
+__attribute__((__common__)) bool progress; +__attribute__((__common__)) bool progress;
+/* END OF PROGRESS MOD */ +/* END progress mod */
+ +
#endif #endif
diff -aur coreutils-8.32/src/cp.c coreutils-8.32-patched/src/cp.c diff -aur coreutils-8.32/src/cp.c coreutils-8.32-patched/src/cp.c
--- coreutils-8.32/src/cp.c 2020-01-01 15:13:12.000000000 +0100 --- coreutils-8.32/src/cp.c 2020-01-01 15:13:12.000000000 +0100
+++ coreutils-8.32-patched/src/cp.c 2021-08-11 19:40:37.729820358 +0200 +++ coreutils-8.32-patched/src/cp.c 2021-12-23 19:29:20.521195377 +0100
@@ -131,6 +131,7 @@ @@ -131,6 +131,9 @@
{"symbolic-link", no_argument, NULL, 's'}, {"symbolic-link", no_argument, NULL, 's'},
{"target-directory", required_argument, NULL, 't'}, {"target-directory", required_argument, NULL, 't'},
{"update", no_argument, NULL, 'u'}, {"update", no_argument, NULL, 'u'},
+ /* BEGIN progress mod */
+ {"progress-bar", no_argument, NULL, 'g'}, + {"progress-bar", no_argument, NULL, 'g'},
+ /* END progress mod */
{"verbose", no_argument, NULL, 'v'}, {"verbose", no_argument, NULL, 'v'},
{GETOPT_SELINUX_CONTEXT_OPTION_DECL}, {GETOPT_SELINUX_CONTEXT_OPTION_DECL},
{GETOPT_HELP_OPTION_DECL}, {GETOPT_HELP_OPTION_DECL},
@@ -170,6 +171,7 @@ @@ -170,6 +173,13 @@
-f, --force if an existing destination file cannot be\n\ -f, --force if an existing destination file cannot be\n\
opened, remove it and try again (this option\n\ opened, remove it and try again (this option\n\
is ignored when the -n option is also used)\n\ is ignored when the -n option is also used)\n\
+ -g, --progress-bar add a progress bar\n\ +"), stdout); /* BEGIN progress mod - remove the complete line!*/
+ fputs (_("\
+ -g, --progress-bar add a progress bar.\n\
+ Note that this doesn't work with reflink,\n\
+ reflink will be automatically disabled\n\
+"), stdout);
+/* END progress mod - remove the complete line!*/ fputs (_("\
-i, --interactive prompt before overwrite (overrides a previous -n\ -i, --interactive prompt before overwrite (overrides a previous -n\
\n\ \n\
option)\n\ option)\n\
@@ -635,6 +637,70 @@ @@ -635,6 +645,73 @@
die (EXIT_FAILURE, 0, _("target %s is not a directory"), die (EXIT_FAILURE, 0, _("target %s is not a directory"),
quoteaf (file[n_files - 1])); quoteaf (file[n_files - 1]));
} }
+ /* BEGIN progress mod */
+ struct timeval start_time; + struct timeval start_time;
+ if (progress) { + if (progress) {
+ /* BEGIN progress mod */
+ g_iTotalSize = 0; + g_iTotalSize = 0;
+ g_iTotalFiles = 0; + g_iTotalFiles = 0;
+ g_iFilesCopied = 0; + g_iFilesCopied = 0;
@@ -419,7 +490,7 @@ diff -aur coreutils-8.32/src/cp.c coreutils-8.32-patched/src/cp.c
+ gettimeofday ( & start_time, NULL ); + gettimeofday ( & start_time, NULL );
+ g_oStartTime = start_time; + g_oStartTime = start_time;
+ +
+ printf ( "Calculating total size... \r" ); + printf ( "calculating total size... \r" );
+ fflush ( stdout ); + fflush ( stdout );
+ long iTotalSize = 0; + long iTotalSize = 0;
+ int iFiles = n_files; + int iFiles = n_files;
@@ -429,12 +500,14 @@ diff -aur coreutils-8.32/src/cp.c coreutils-8.32-patched/src/cp.c
+ +
+ /* how many files are we copying */ + /* how many files are we copying */
+ char command[1024]; + char command[1024];
+ sprintf( command, "find \"%s\" -type f | wc -l", file[0]); + char * _cEscapedString = escape_double_quotes( file[0] );
+ sprintf( command, "find \"%s\" -type f | wc -l", _cEscapedString );
+ free( _cEscapedString );
+ FILE *fp ; + FILE *fp ;
+ char output[1024]; + char output[1024];
+ 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)
+ printf("failed to run find.\n"); + printf("failed to run find\r");
+ else + else
+ g_iTotalFiles = atoi( output ); + g_iTotalFiles = atoi( output );
+ +
@@ -443,8 +516,9 @@ diff -aur coreutils-8.32/src/cp.c coreutils-8.32-patched/src/cp.c
+ /* call du -s for each file */ + /* call du -s for each file */
+ /* create command */ + /* create command */
+ char command[1024]; + char command[1024];
+ sprintf ( command, "du -s \"%s\"", file[j] ); + char * _cEscapedString = escape_double_quotes( file[j] );
+ /* TODO: replace all quote signs in file[i] */ + sprintf ( command, "du -s \"%s\"", _cEscapedString );
+ free( _cEscapedString );
+ +
+ FILE *fp; + FILE *fp;
+ char output[1024]; + char output[1024];
@@ -452,7 +526,7 @@ diff -aur coreutils-8.32/src/cp.c coreutils-8.32-patched/src/cp.c
+ /* 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) {
+ printf("failed to run du.\n" ); + printf("failed to run du\r" );
+ } + }
+ else + else
+ { + {
@@ -460,7 +534,7 @@ diff -aur coreutils-8.32/src/cp.c coreutils-8.32-patched/src/cp.c
+ strchr ( output, '\t' )[0] = '\0'; + strchr ( output, '\t' )[0] = '\0';
+ iTotalSize += atol ( output ); + iTotalSize += atol ( output );
+ +
+ printf ( "Calculating total size... %ld\r", iTotalSize ); + printf ( "calculating total size... %ld\r", iTotalSize );
+ fflush ( stdout ); + fflush ( stdout );
+ } + }
+ +
@@ -468,18 +542,18 @@ diff -aur coreutils-8.32/src/cp.c coreutils-8.32-patched/src/cp.c
+ pclose(fp); + pclose(fp);
+ } + }
+ g_iTotalSize = iTotalSize; + g_iTotalSize = iTotalSize;
+ /* END progress mod */
+ } + }
+ /* END progress mod */
+ +
if (target_directory) if (target_directory)
{ {
@@ -777,6 +843,46 @@ @@ -777,6 +854,46 @@
ok = copy (source, new_dest, 0, x, &unused, NULL); ok = copy (source, new_dest, 0, x, &unused, NULL);
} }
+ if (progress) {
+ /* BEGIN progress mod */ + /* BEGIN progress mod */
+ if (progress) {
+ /* remove everything */ + /* remove everything */
+ int i; + int i;
+ if ( g_iTotalFiles > 1 ) + if ( g_iTotalFiles > 1 )
@@ -515,13 +589,13 @@ diff -aur coreutils-8.32/src/cp.c coreutils-8.32-patched/src/cp.c
+ /* good-bye message */ + /* good-bye message */
+ printf ( "%d files (%s) copied in %.1f seconds (%s/s).\n", g_iFilesCopied, sTotalWritten, + printf ( "%d files (%s) copied in %.1f seconds (%s/s).\n", g_iFilesCopied, sTotalWritten,
+ sec_elapsed, s_copy_speed ); + sec_elapsed, s_copy_speed );
+ /* END progress mod */
+ } + }
+ /* END progress mod */
+ +
return ok; return ok;
} }
@@ -812,6 +918,7 @@ @@ -812,6 +929,7 @@
x->recursive = false; x->recursive = false;
x->sparse_mode = SPARSE_AUTO; x->sparse_mode = SPARSE_AUTO;
x->symbolic_link = false; x->symbolic_link = false;
@@ -529,97 +603,124 @@ diff -aur coreutils-8.32/src/cp.c coreutils-8.32-patched/src/cp.c
x->set_mode = false; x->set_mode = false;
x->mode = 0; x->mode = 0;
@@ -950,7 +1057,7 @@ @@ -950,7 +1068,8 @@
selinux_enabled = (0 < is_selinux_enabled ()); selinux_enabled = (0 < is_selinux_enabled ());
cp_option_init (&x); cp_option_init (&x);
- while ((c = getopt_long (argc, argv, "abdfHilLnprst:uvxPRS:TZ", - while ((c = getopt_long (argc, argv, "abdfHilLnprst:uvxPRS:TZ",
+ /* BEGIN and END progress mod - remove the g in the next line!*/
+ while ((c = getopt_long (argc, argv, "abdfgHilLnprst:uvxPRS:TZ", + while ((c = getopt_long (argc, argv, "abdfgHilLnprst:uvxPRS:TZ",
long_opts, NULL)) long_opts, NULL))
!= -1) != -1)
{ {
@@ -1007,6 +1114,10 @@ @@ -1007,6 +1126,12 @@
x.unlink_dest_after_failed_open = true; x.unlink_dest_after_failed_open = true;
break; break;
+ /* BEGIN progress mod */
+ case 'g': + case 'g':
+ progress = true; + progress = true;
+ break; + break;
+ /* END progress mod */
+ +
case 'H': case 'H':
x.dereference = DEREF_COMMAND_LINE_ARGUMENTS; x.dereference = DEREF_COMMAND_LINE_ARGUMENTS;
break; break;
diff -aur coreutils-8.32/src/mv.c coreutils-8.32-patched/src/mv.c diff -aur coreutils-8.32/src/mv.c coreutils-8.32-patched/src/mv.c
--- coreutils-8.32/src/mv.c 2020-01-01 15:13:12.000000000 +0100 --- coreutils-8.32/src/mv.c 2020-01-01 15:13:12.000000000 +0100
+++ coreutils-8.32-patched/src/mv.c 2021-08-11 19:40:37.729820358 +0200 +++ coreutils-8.32-patched/src/mv.c 2021-12-23 19:31:05.335749444 +0100
@@ -66,6 +66,7 @@ @@ -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'},
{"verbose", no_argument, NULL, 'v'}, {"verbose", no_argument, NULL, 'v'},
+ {"progress-ar", no_argument, NULL, 'g'}, + /* BEGIN progress mod */
+ {"progress-bar", no_argument, NULL, 'g'},
+ /* END progress mod */
{GETOPT_HELP_OPTION_DECL}, {GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL}, {GETOPT_VERSION_OPTION_DECL},
{NULL, 0, NULL, 0} {NULL, 0, NULL, 0}
@@ -168,10 +169,86 @@ @@ -170,8 +173,121 @@
static bool
do_move (const char *source, const char *dest, const struct cp_options *x)
{ {
+ struct timeval start_time;
+
bool copy_into_self; bool copy_into_self;
bool rename_succeeded; bool rename_succeeded;
+ if(progress && x->rename_errno != 0) { +
+ /* BEGIN progress mod */ + /* BEGIN progress mod */
+ struct timeval start_time;
+
+ if(progress && x->rename_errno != 0) {
+ if (g_iTotalSize == 0)
+ g_iTotalSize = 0; + g_iTotalSize = 0;
+ if (g_iTotalFiles == 0)
+ g_iTotalFiles = 0;
+ if (g_iFilesCopied == 0)
+ g_iFilesCopied = 0; + g_iFilesCopied = 0;
+ if (g_iDirectoriesCopied == 0)
+ g_iDirectoriesCopied = 0;
+ if (g_iTotalWritten == 0)
+ g_iTotalWritten = 0; + g_iTotalWritten = 0;
+ +
+ if (target_directory_operand (source))
+ g_iDirectoriesCopied++;
+
+ gettimeofday (& start_time, NULL); + gettimeofday (& start_time, NULL);
+ g_oStartTime = start_time; + g_oStartTime = start_time;
+ +
+ printf ("Calculating total size... \r"); + /* 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");
+ 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 );
+ sprintf ( command, "du -s '%s'", source ); + sprintf ( command, "du -s \"%s\"", _cEscapedString );
+ /* TODO: replace all quote signs in file[i] */ + 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) {
+ //printf("failed to run du.\n" ); + printf("failed to run du\r" );
+ } + }
+ else + else
+ { + {
+ /* isolate size */ + /* isolate size */
+ strchr ( output, '\t' )[0] = '\0'; + strchr ( output, '\t' )[0] = '\0';
+ iTotalSize += atol ( output ); + iTotalSize += atol ( output );
+ printf ( "Calculating total size... %ld\r", iTotalSize ); + printf ( "calculating total size... %ld\r", iTotalSize );
+ fflush ( stdout ); + fflush ( stdout );
+ } + }
+ +
+ /* close */ + /* close */
+ pclose(fp); + pclose(fp);
+ g_iTotalSize = iTotalSize; + g_iTotalSize += iTotalSize;
+ /* END progress mod */
+
+ } + }
+ /* END progress mod */
+ +
bool ok = copy (source, dest, false, x, &copy_into_self, &rename_succeeded); bool ok = copy (source, dest, false, x, &copy_into_self, &rename_succeeded);
+ if (progress && (x->rename_errno != 0 && ok)) {
+ /* BEGIN progress mod */ + /* BEGIN progress mod */
+ if (progress && (x->rename_errno != 0 && ok)) {
+ /* 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;
@@ -638,41 +739,59 @@ diff -aur coreutils-8.32/src/mv.c coreutils-8.32-patched/src/mv.c
+ char s_copy_speed[20]; + char s_copy_speed[20];
+ file_size_format ( s_copy_speed, copy_speed, 1 ); + file_size_format ( s_copy_speed, copy_speed, 1 );
+ +
+ /* increase counter */
+ g_iFilesCopied++;
+
+ /* good-bye message */ + /* good-bye message */
+ printf ( "%d files (%s) moved in %.1f seconds (%s/s).\n", g_iFilesCopied, sTotalWritten, + if ( x->last_file )
+ sec_elapsed, s_copy_speed ); + {
+ /* END progress mod */ + char sFType[20];
+ if ( g_iDirectoriesCopied > 0 && g_iDirectoriesCopied == g_iFilesCopied )
+ sprintf ( sFType, "%s", "folder(s)" );
+ else if ( g_iDirectoriesCopied > 0 && g_iDirectoriesCopied < g_iFilesCopied )
+ sprintf ( sFType, "%s", "folder(s)/file(s)" );
+ else
+ sprintf ( sFType, "%s", "file(s)" );
+ printf ( "%d %s (%s) moved in %.1f seconds (%s/s).\n", g_iFilesCopied, sFType,
+ sTotalWritten, sec_elapsed, s_copy_speed );
+ } + }
+ }
+ /* END progress mod */
+ +
if (ok) if (ok)
{ {
char const *dir_to_remove; char const *dir_to_remove;
@@ -306,6 +383,7 @@ @@ -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\
+"), stdout); /* BEGIN progress mod - remove the complete line!*/
+fputs (_("\
+ -g, --progress-bar add progress-bar\n\ + -g, --progress-bar add progress-bar\n\
+"), stdout);
+/* END progress mod - remove the complete line!*/ fputs (_("\
-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 +439,7 @@ @@ -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 ();
- while ((c = getopt_long (argc, argv, "bfint:uvS:TZ", long_options, NULL)) - while ((c = getopt_long (argc, argv, "bfint:uvS:TZ", long_options, NULL))
+ /* BEGIN and END progress mod - remove the g in the next line!*/
+ while ((c = getopt_long (argc, argv, "bfint:uvgS:TZ", long_options, NULL)) + while ((c = getopt_long (argc, argv, "bfint:uvgS:TZ", long_options, NULL))
!= -1) != -1)
{ {
switch (c) switch (c)
@@ -407,6 +485,11 @@ @@ -407,6 +529,11 @@
case 'v': case 'v':
x.verbose = true; x.verbose = true;
break; break;
+ + /* BEGIN progress mod */
+ case 'g': + case 'g':
+ progress = true; + progress = true;
+ break; + break;
+ + /* END progress mod */
case 'S': case 'S':
make_backups = true; make_backups = true;
backup_suffix = optarg; backup_suffix = optarg;