backport changes to 8.32 patch

This commit is contained in:
Michael Wehr
2022-01-12 20:10:44 +01:00
parent 8a8af288bb
commit fb08e1aba6

View File

@@ -1,7 +1,7 @@
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-patched/src/copy.c 2022-01-04 21:56:14.545035647 +0100
@@ -129,6 +129,119 @@
+++ coreutils-8.32-patched/src/copy.c 2022-01-12 20:08:19.573923682 +0100
@@ -129,6 +129,121 @@
dev_t dev;
};
@@ -39,28 +39,30 @@ diff -aur coreutils-8.32/src/copy.c coreutils-8.32-patched/src/copy.c
+ return _cEscapedString;
+}
+
+char * format_elapsed_time ( double sec_elapsed )
+void format_time ( char * _cDest, double seconds, bool showall )
+{
+ // hours
+ long hr = ( (int) sec_elapsed / (60 * 60)) % 24;
+ int hr = ( (int) seconds / (60 * 60)) % 24;
+ // minutes
+ int min = ( (int) sec_elapsed / 60) % 60;
+ int min = ( (int) seconds / 60) % 60;
+ // seconds
+ double sec = sec_elapsed - (hr * (60 * 60)) - (min * 60);
+ size_t maxneeded = snprintf(NULL, 0, "%ldh %dm %.1fs", hr, min, sec) + 1;
+ char * _cElapsedTimeString;
+ _cElapsedTimeString = (char *) calloc( sizeof(char) * maxneeded, sizeof(char) );
+ if ( sec_elapsed >= 3600 )
+ double sec = seconds - (hr * (60 * 60)) - (min * 60);
+ if ( showall )
+ {
+ sprintf(_cElapsedTimeString, "%ldh %dm %.1fs", hr, min, sec);
+ } else if ( sec_elapsed >= 60 )
+ if ( seconds < 0 )
+ sprintf(_cDest, "%2ch %2cm %2cs", '0', '0', '?');
+ else
+ sprintf(_cDest, "%2dh %2dm %2ds", hr, min, (int) sec);
+ } else if ( seconds >= 3600 )
+ {
+ sprintf(_cElapsedTimeString, "%dm %.1fs", min, sec);
+ sprintf(_cDest, "%2dh %2dm %4.1fs", hr, min, sec);
+ } else if ( seconds >= 60 )
+ {
+ sprintf(_cDest, "%2dm %4.1fs", min, sec);
+ } else
+ {
+ sprintf(_cElapsedTimeString, "%.1fs", sec);
+ sprintf(_cDest, "%4.1fs", sec);
+ }
+ return _cElapsedTimeString;
+}
+
+static void file_progress_bar ( char * _cDest, int _iBarLength, long _lProgress, long _lTotal )
@@ -121,7 +123,7 @@ diff -aur coreutils-8.32/src/copy.c coreutils-8.32-patched/src/copy.c
/* Initial size of the cp.dest_info hash table. */
#define DEST_INFO_INITIAL_CAPACITY 61
@@ -259,9 +372,16 @@
@@ -259,17 +374,129 @@
static bool
sparse_copy (int src_fd, int dest_fd, char *buf, size_t buf_size,
size_t hole_size, bool punch_holes,
@@ -139,8 +141,17 @@ diff -aur coreutils-8.32/src/copy.c coreutils-8.32-patched/src/copy.c
{
*last_write_made_hole = false;
*total_n_read = 0;
@@ -270,6 +390,85 @@
bool make_hole = false;
off_t psize = 0;
+ /* BEGIN progress mod */
+ gettimeofday ( & g_oFStartTime, NULL );
+ g_iFTotalWritten = 0;
+ struct stat st;
+ stat(src_name, &st);
+ g_iFTotalSize = st.st_size/1024;
+ /* END progress mod */
+
while (max_n_read)
{
+
@@ -159,6 +170,7 @@ diff -aur coreutils-8.32/src/copy.c coreutils-8.32-patched/src/copy.c
+ struct timeval cur_time;
+ gettimeofday ( & cur_time, NULL );
+ int cur_size = g_iTotalWritten + *total_n_read / 1024;
+ int cur_fsize = g_iFTotalWritten + *total_n_read / 1024;
+ int usec_elapsed = cur_time.tv_usec - s_progress->last_time.tv_usec;
+ double sec_elapsed = ( double ) usec_elapsed / 1000000.f;
+ sec_elapsed += ( double ) ( cur_time.tv_sec - s_progress->last_time.tv_sec );
@@ -172,18 +184,35 @@ diff -aur coreutils-8.32/src/copy.c coreutils-8.32-patched/src/copy.c
+
+ /* how many time has passed since the start? */
+ int isec_elapsed = cur_time.tv_sec - g_oStartTime.tv_sec;
+ int isec_felapsed = cur_time.tv_sec - g_oFStartTime.tv_sec;
+ int sec_remaining = ( int ) ( ( double ) isec_elapsed / cur_size
+ * g_iTotalSize ) - isec_elapsed;
+ int min_remaining = sec_remaining / 60;
+ sec_remaining -= min_remaining * 60;
+ int hours_remaining = min_remaining / 60;
+ min_remaining -= hours_remaining * 60;
+ int sec_fremaining = ( int ) ( ( double ) isec_felapsed / cur_fsize
+ * g_iFTotalSize ) - isec_felapsed;
+ /* print out */
+
+ char f_ttime[20];
+ char f_ftime[20];
+ format_time(f_ttime, sec_remaining, true);
+ format_time(f_ftime, sec_fremaining, true);
+
+ sprintf ( s_progress->cProgressField[1],
+ move_mode
+ ? "%d of %d files moved (about %s remaining) "
+ : "%d of %d files copied (about %s remaining) ",
+ g_iFilesCopied, g_iTotalFiles, f_ttime );
+
+ char s_ftime[40] = "";
+
+ if (g_iTotalFiles > 1)
+ sprintf ( s_ftime, "(about %s remaining)", f_ftime );
+ else
+ sprintf ( s_ftime, "(about %s remaining)", f_ttime );
+
+ sprintf ( s_progress->cProgressField[3],
+ move_mode
+ ? "moving at %s/s (about %uh %um %us remaining)"
+ : "copying at %s/s (about %uh %um %us remaining)", s_copy_speed,
+ hours_remaining, min_remaining, sec_remaining );
+ ? "moving at %s/s %s"
+ : "copying at %s/s %s", s_copy_speed, s_ftime );
+
+ int fs_len;
+ if ( g_iTotalFiles > 1 )
@@ -225,7 +254,7 @@ diff -aur coreutils-8.32/src/copy.c coreutils-8.32-patched/src/copy.c
ssize_t n_read = read (src_fd, buf, MIN (max_n_read, buf_size));
if (n_read < 0)
{
@@ -354,6 +553,14 @@
@@ -354,6 +581,14 @@
certain files in /proc or /sys with linux kernels. */
}
@@ -240,7 +269,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
calls of sparse_copy() start at the correct offset. */
if (make_hole && ! create_hole (dest_fd, dst_name, punch_holes, psize))
@@ -421,8 +628,16 @@
@@ -421,8 +656,16 @@
extent_copy (int src_fd, int dest_fd, char *buf, size_t buf_size,
size_t hole_size, off_t src_total_size,
enum Sparse_type sparse_mode,
@@ -258,7 +287,7 @@ diff -aur coreutils-8.32/src/copy.c coreutils-8.32-patched/src/copy.c
{
struct extent_scan scan;
off_t last_ext_start = 0;
@@ -553,10 +768,26 @@
@@ -553,10 +796,26 @@
last_ext_len = ext_len;
bool read_hole;
@@ -287,7 +316,7 @@ diff -aur coreutils-8.32/src/copy.c coreutils-8.32-patched/src/copy.c
goto fail;
dest_pos = ext_start + n_read;
@@ -1305,6 +1536,75 @@
@@ -1305,6 +1564,75 @@
buf_alloc = xmalloc (buf_size + buf_alignment);
buf = ptr_align (buf_alloc, buf_alignment);
@@ -327,10 +356,10 @@ diff -aur coreutils-8.32/src/copy.c coreutils-8.32-patched/src/copy.c
+
+ /* show how many files were written */
+ 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 );
+ sum_length = sprintf ( cProgressField[1],
+ x->move_mode
+ ? "%d of %d files moved so far"
+ : "%d of %d files copied so far", g_iFilesCopied, g_iTotalFiles );
+ cProgressField[1][sum_length] = ' ';
+ }
+
@@ -363,7 +392,7 @@ diff -aur coreutils-8.32/src/copy.c coreutils-8.32-patched/src/copy.c
if (sparse_src)
{
bool normal_copy_required;
@@ -1316,7 +1616,15 @@
@@ -1316,7 +1644,15 @@
if (extent_copy (source_desc, dest_desc, buf, buf_size, hole_size,
src_open_sb.st_size,
make_holes ? x->sparse_mode : SPARSE_NEVER,
@@ -380,7 +409,7 @@ diff -aur coreutils-8.32/src/copy.c coreutils-8.32-patched/src/copy.c
goto preserve_metadata;
if (! normal_copy_required)
@@ -1328,11 +1636,24 @@
@@ -1328,11 +1664,24 @@
off_t n_read;
bool wrote_hole_at_eof;
@@ -407,7 +436,7 @@ diff -aur coreutils-8.32/src/copy.c coreutils-8.32-patched/src/copy.c
{
return_val = false;
goto close_src_and_dst_desc;
@@ -1343,6 +1664,14 @@
@@ -1343,6 +1692,14 @@
return_val = false;
goto close_src_and_dst_desc;
}
@@ -422,7 +451,7 @@ diff -aur coreutils-8.32/src/copy.c coreutils-8.32-patched/src/copy.c
}
preserve_metadata:
@@ -1716,15 +2045,19 @@
@@ -1716,15 +2073,19 @@
fprintf (stderr,
(x->move_mode || x->unlink_dest_before_opening
|| x->unlink_dest_after_failed_open)
@@ -447,7 +476,7 @@ 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
--- coreutils-8.32/src/copy.h 2020-01-01 15:13:12.000000000 +0100
+++ coreutils-8.32-patched/src/copy.h 2022-01-04 21:56:14.545035647 +0100
+++ coreutils-8.32-patched/src/copy.h 2022-01-12 20:08:19.577923660 +0100
@@ -234,6 +234,11 @@
Create destination directories as usual. */
bool symbolic_link;
@@ -460,21 +489,24 @@ diff -aur coreutils-8.32/src/copy.h coreutils-8.32-patched/src/copy.h
/* If true, do not copy a nondirectory that has an existing destination
with the same or newer modification time. */
bool update;
@@ -304,4 +309,19 @@
@@ -304,4 +309,22 @@
bool chown_failure_ok (struct cp_options const *) _GL_ATTRIBUTE_PURE;
mode_t cached_umask (void);
+/* BEGIN progress mod */
+char * escape_double_quotes ( char * _cUnescapedString );
+char * format_elapsed_time ( double sec_elapsed );
+void format_time ( char * _cDst, double seconds, bool showall );
+
+int file_size_format ( char * _cDst, long _lSize, int _iCounter );
+
+__attribute__((__common__)) long g_iTotalSize;
+__attribute__((__common__)) long g_iFTotalSize;
+__attribute__((__common__)) long g_iTotalWritten;
+__attribute__((__common__)) long g_iFTotalWritten;
+__attribute__((__common__)) int g_iFilesCopied;
+__attribute__((__common__)) int g_iDirectoriesCopied;
+__attribute__((__common__)) struct timeval g_oStartTime;
+__attribute__((__common__)) struct timeval g_oFStartTime;
+__attribute__((__common__)) int g_iTotalFiles;
+__attribute__((__common__)) bool progress;
+/* END progress mod */
@@ -482,7 +514,7 @@ diff -aur coreutils-8.32/src/copy.h coreutils-8.32-patched/src/copy.h
#endif
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-patched/src/cp.c 2022-01-04 21:56:14.545035647 +0100
+++ coreutils-8.32-patched/src/cp.c 2022-01-12 20:08:19.577923660 +0100
@@ -131,6 +131,9 @@
{"symbolic-link", no_argument, NULL, 's'},
{"target-directory", required_argument, NULL, 't'},
@@ -591,7 +623,7 @@ diff -aur coreutils-8.32/src/cp.c coreutils-8.32-patched/src/cp.c
if (target_directory)
{
@@ -777,6 +864,53 @@
@@ -777,6 +864,56 @@
ok = copy (source, new_dest, 0, x, &unused, NULL);
}
@@ -637,25 +669,30 @@ diff -aur coreutils-8.32/src/cp.c coreutils-8.32-patched/src/cp.c
+ sprintf ( sFType, "%s", "folder(s)/file(s)" );
+ else
+ sprintf ( sFType, "%s", "file(s)" );
+
+ char f_time[20];
+ format_time(f_time, sec_elapsed, true);
+ printf ( "%d %s (%s) copied in %s (%s/s).\n", g_iFilesCopied, sFType,
+ sTotalWritten, format_elapsed_time(sec_elapsed), s_copy_speed );
+ sTotalWritten, f_time, s_copy_speed );
+ }
+ /* END progress mod */
+
return ok;
}
@@ -812,6 +946,9 @@
@@ -812,6 +949,11 @@
x->recursive = false;
x->sparse_mode = SPARSE_AUTO;
x->symbolic_link = false;
+
+ /* BEGIN progress mod */
+ x->progress_bar = false;
+ /* END progress mod */
+
x->set_mode = false;
x->mode = 0;
@@ -950,7 +1087,8 @@
@@ -950,7 +1092,8 @@
selinux_enabled = (0 < is_selinux_enabled ());
cp_option_init (&x);
@@ -665,7 +702,7 @@ diff -aur coreutils-8.32/src/cp.c coreutils-8.32-patched/src/cp.c
long_opts, NULL))
!= -1)
{
@@ -1007,6 +1145,12 @@
@@ -1007,6 +1150,12 @@
x.unlink_dest_after_failed_open = true;
break;
@@ -680,7 +717,7 @@ diff -aur coreutils-8.32/src/cp.c coreutils-8.32-patched/src/cp.c
break;
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-patched/src/mv.c 2022-01-04 21:56:14.549035719 +0100
+++ coreutils-8.32-patched/src/mv.c 2022-01-12 20:08:19.577923660 +0100
@@ -66,6 +66,9 @@
{"target-directory", required_argument, NULL, 't'},
{"update", no_argument, NULL, 'u'},
@@ -691,7 +728,7 @@ diff -aur coreutils-8.32/src/mv.c coreutils-8.32-patched/src/mv.c
{GETOPT_HELP_OPTION_DECL},
{GETOPT_VERSION_OPTION_DECL},
{NULL, 0, NULL, 0}
@@ -170,8 +173,121 @@
@@ -170,8 +173,124 @@
{
bool copy_into_self;
bool rename_succeeded;
@@ -804,8 +841,11 @@ diff -aur coreutils-8.32/src/mv.c coreutils-8.32-patched/src/mv.c
+ sprintf ( sFType, "%s", "folder(s)/file(s)" );
+ else
+ sprintf ( sFType, "%s", "file(s)" );
+
+ char f_time[20];
+ format_time(f_time, sec_elapsed, true);
+ printf ( "%d %s (%s) moved in %s (%s/s).\n", g_iFilesCopied, sFType,
+ sTotalWritten, format_elapsed_time(sec_elapsed), s_copy_speed );
+ sTotalWritten, f_time, s_copy_speed );
+ }
+ }
+ /* END progress mod */
@@ -813,7 +853,7 @@ diff -aur coreutils-8.32/src/mv.c coreutils-8.32-patched/src/mv.c
if (ok)
{
char const *dir_to_remove;
@@ -306,6 +422,11 @@
@@ -306,6 +425,11 @@
\n\
-b like --backup but does not accept an argument\n\
-f, --force do not prompt before overwriting\n\
@@ -825,7 +865,7 @@ diff -aur coreutils-8.32/src/mv.c coreutils-8.32-patched/src/mv.c
-i, --interactive prompt before overwrite\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\
@@ -361,7 +482,8 @@
@@ -361,7 +485,8 @@
/* Try to disable the ability to unlink a directory. */
priv_set_remove_linkdir ();
@@ -835,7 +875,7 @@ diff -aur coreutils-8.32/src/mv.c coreutils-8.32-patched/src/mv.c
!= -1)
{
switch (c)
@@ -407,6 +529,11 @@
@@ -407,6 +532,11 @@
case 'v':
x.verbose = true;
break;