backport changes to 8.32 patch

This commit is contained in:
Michael Wehr
2022-02-13 16:15:53 +01:00
parent b62cfd957e
commit 7fe882ec46

View File

@@ -1,7 +1,7 @@
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 2022-01-12 20:08:19.573923682 +0100 +++ coreutils-8.32-patched/src/copy.c 2022-02-13 16:14:31.534047672 +0100
@@ -129,6 +129,121 @@ @@ -129,6 +129,133 @@
dev_t dev; dev_t dev;
}; };
@@ -14,29 +14,41 @@ 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;
+}; +};
+ +
+char * escape_double_quotes ( char * _cUnescapedString ) +FILE * spawn( const char *cmd, char *const argv[] )
+{ +{
+ char * _cEscapedString; + FILE *ret = NULL;
+ _cEscapedString = (char *) calloc( sizeof(char) * strlen(_cUnescapedString) * 2, sizeof(char) ); + int pfd_read[2];
+ size_t ipos = 0; + pid_t pid;
+ size_t rpos = 0; +
+ for(rpos = 0, ipos = 0; _cUnescapedString[rpos] != '\0'; rpos++, ipos++) + if (cmd == NULL || argv == NULL)
+ { + return ret;
+ if(_cUnescapedString[rpos] == '"') +
+ { + if (pipe(pfd_read) < 0) {
+ _cEscapedString[ipos] = '\\'; + error(0, errno, "pipe: %s", cmd);
+ ipos++; + return ret;
+ } + }
+ if(_cUnescapedString[rpos] == '`') +
+ { + if ((pid = fork()) == 0) {
+ _cEscapedString[ipos] = '\\'; + int err = dup2(pfd_read[1], 1) < 0;
+ ipos++; + close(pfd_read[0]);
+ close(pfd_read[1]);
+
+ if (err)
+ error(EXIT_FAILURE, errno, "dup2: %s", cmd);
+ execvp(cmd, argv);
+ error(EXIT_FAILURE, errno, "exec: %s", cmd);
+ } + }
+ _cEscapedString[ipos] = _cUnescapedString[rpos]; +
+ close(pfd_read[1]);
+
+ if (pid < 0) {
+ close(pfd_read[0]);
+ error(0, errno, "fork: %s", cmd);
+ return ret;
+ } + }
+ ipos++; +
+ _cEscapedString[ipos] = '\0'; + ret = fdopen(pfd_read[0], "r");
+ return _cEscapedString; + return ret;
+} +}
+ +
+void format_time ( char * _cDest, double seconds, bool showall ) +void format_time ( char * _cDest, double seconds, bool showall )
@@ -123,7 +135,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. */ /* Initial size of the cp.dest_info hash table. */
#define DEST_INFO_INITIAL_CAPACITY 61 #define DEST_INFO_INITIAL_CAPACITY 61
@@ -259,17 +374,129 @@ @@ -259,17 +386,129 @@
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,
@@ -254,7 +266,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)); ssize_t n_read = read (src_fd, buf, MIN (max_n_read, buf_size));
if (n_read < 0) if (n_read < 0)
{ {
@@ -354,6 +581,14 @@ @@ -354,6 +593,14 @@
certain files in /proc or /sys with linux kernels. */ certain files in /proc or /sys with linux kernels. */
} }
@@ -269,7 +281,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))
@@ -421,8 +656,16 @@ @@ -421,8 +668,16 @@
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,
enum Sparse_type sparse_mode, enum Sparse_type sparse_mode,
@@ -287,7 +299,7 @@ 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 +796,26 @@ @@ -553,10 +808,26 @@
last_ext_len = ext_len; last_ext_len = ext_len;
bool read_hole; bool read_hole;
@@ -316,7 +328,7 @@ diff -aur coreutils-8.32/src/copy.c coreutils-8.32-patched/src/copy.c
goto fail; goto fail;
dest_pos = ext_start + n_read; dest_pos = ext_start + n_read;
@@ -1305,6 +1564,75 @@ @@ -1305,6 +1576,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);
@@ -392,7 +404,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 +1644,15 @@ @@ -1316,7 +1656,15 @@
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,
@@ -409,7 +421,7 @@ 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 +1664,24 @@ @@ -1328,11 +1676,24 @@
off_t n_read; off_t n_read;
bool wrote_hole_at_eof; bool wrote_hole_at_eof;
@@ -436,7 +448,7 @@ diff -aur coreutils-8.32/src/copy.c coreutils-8.32-patched/src/copy.c
{ {
return_val = false; return_val = false;
goto close_src_and_dst_desc; goto close_src_and_dst_desc;
@@ -1343,6 +1692,14 @@ @@ -1343,6 +1704,14 @@
return_val = false; return_val = false;
goto close_src_and_dst_desc; goto close_src_and_dst_desc;
} }
@@ -451,7 +463,7 @@ diff -aur coreutils-8.32/src/copy.c coreutils-8.32-patched/src/copy.c
} }
preserve_metadata: preserve_metadata:
@@ -1716,15 +2073,19 @@ @@ -1716,15 +2085,19 @@
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)
@@ -476,7 +488,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 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 2022-01-12 20:08:19.577923660 +0100 +++ coreutils-8.32-patched/src/copy.h 2022-02-13 16:14:31.538047737 +0100
@@ -234,6 +234,11 @@ @@ -234,6 +234,11 @@
Create destination directories as usual. */ Create destination directories as usual. */
bool symbolic_link; bool symbolic_link;
@@ -494,7 +506,7 @@ diff -aur coreutils-8.32/src/copy.h coreutils-8.32-patched/src/copy.h
mode_t cached_umask (void); mode_t cached_umask (void);
+/* BEGIN progress mod */ +/* BEGIN progress mod */
+char * escape_double_quotes ( char * _cUnescapedString ); +FILE * spawn( const char *cmd, char *const argv[] );
+void format_time ( char * _cDst, double seconds, bool showall ); +void format_time ( char * _cDst, double seconds, bool showall );
+ +
+int file_size_format ( char * _cDst, long _lSize, int _iCounter ); +int file_size_format ( char * _cDst, long _lSize, int _iCounter );
@@ -514,7 +526,7 @@ diff -aur coreutils-8.32/src/copy.h coreutils-8.32-patched/src/copy.h
#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 2022-01-12 20:08:19.577923660 +0100 +++ coreutils-8.32-patched/src/cp.c 2022-02-13 16:14:31.538047737 +0100
@@ -131,6 +131,9 @@ @@ -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'},
@@ -539,7 +551,7 @@ diff -aur coreutils-8.32/src/cp.c coreutils-8.32-patched/src/cp.c
-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 +645,83 @@ @@ -635,6 +645,84 @@
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]));
} }
@@ -573,33 +585,34 @@ diff -aur coreutils-8.32/src/cp.c coreutils-8.32-patched/src/cp.c
+ int j; + int j;
+ +
+ /* how many files are we copying */ + /* how many files are we copying */
+ char command[1024];
+ 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"); + char fcmd[] = "find";
+ if ( fp == NULL || fgets(output, sizeof(output)-1, fp) == NULL) + fp = spawn(fcmd, (char *[]){ fcmd, file[0], NULL, "-type", "f", NULL });
+ if ( fp == NULL)
+ printf("failed to run find\r"); + printf("failed to run find\r");
+ else + else
+ if ( atoi(output) > n_files ) + {
+ g_iTotalFiles = atoi( output ); + char *line_buf = NULL;
+ size_t line_buf_size = 0;
+ int line_count = 0;
+ ssize_t line_size;
+ line_size = getline(&line_buf, &line_buf_size, fp);
+ while (line_size > 0)
+ {
+ line_count++;
+ line_size = getline(&line_buf, &line_buf_size, fp);
+ }
+ free (line_buf);
+ if ( line_count > n_files )
+ g_iTotalFiles = line_count;
+ }
+ +
+ for (j = 0; j < iFiles; j++) + for (j = 0; j < iFiles; j++)
+ { + {
+ /* call du -s for each file */ + /* call du -s for each file */
+ /* create command */ + char dcmd[] = "du";
+ char command[1024]; + fp = spawn(dcmd, (char *[]){ dcmd, "-s", file[j], NULL });
+ char * _cEscapedString = escape_double_quotes( file[j] );
+ sprintf ( command, "du -s \"%s\"", _cEscapedString );
+ free( _cEscapedString );
+
+ FILE *fp;
+ char output[1024];
+
+ /* run command */
+ 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\r" ); + printf("failed to run du\r" );
+ } + }
@@ -623,7 +636,7 @@ diff -aur coreutils-8.32/src/cp.c coreutils-8.32-patched/src/cp.c
if (target_directory) if (target_directory)
{ {
@@ -777,6 +864,56 @@ @@ -777,6 +865,56 @@
ok = copy (source, new_dest, 0, x, &unused, NULL); ok = copy (source, new_dest, 0, x, &unused, NULL);
} }
@@ -671,7 +684,7 @@ diff -aur coreutils-8.32/src/cp.c coreutils-8.32-patched/src/cp.c
+ sprintf ( sFType, "%s", "file(s)" ); + sprintf ( sFType, "%s", "file(s)" );
+ +
+ char f_time[20]; + char f_time[20];
+ format_time(f_time, sec_elapsed, true); + format_time(f_time, sec_elapsed, false);
+ printf ( "%d %s (%s) copied in %s (%s/s).\n", g_iFilesCopied, sFType, + printf ( "%d %s (%s) copied in %s (%s/s).\n", g_iFilesCopied, sFType,
+ sTotalWritten, f_time, s_copy_speed ); + sTotalWritten, f_time, s_copy_speed );
+ } + }
@@ -680,7 +693,7 @@ diff -aur coreutils-8.32/src/cp.c coreutils-8.32-patched/src/cp.c
return ok; return ok;
} }
@@ -812,6 +949,11 @@ @@ -812,6 +950,11 @@
x->recursive = false; x->recursive = false;
x->sparse_mode = SPARSE_AUTO; x->sparse_mode = SPARSE_AUTO;
x->symbolic_link = false; x->symbolic_link = false;
@@ -692,7 +705,7 @@ 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 +1092,8 @@ @@ -950,7 +1093,8 @@
selinux_enabled = (0 < is_selinux_enabled ()); selinux_enabled = (0 < is_selinux_enabled ());
cp_option_init (&x); cp_option_init (&x);
@@ -702,7 +715,7 @@ diff -aur coreutils-8.32/src/cp.c coreutils-8.32-patched/src/cp.c
long_opts, NULL)) long_opts, NULL))
!= -1) != -1)
{ {
@@ -1007,6 +1150,12 @@ @@ -1007,6 +1151,12 @@
x.unlink_dest_after_failed_open = true; x.unlink_dest_after_failed_open = true;
break; break;
@@ -717,7 +730,7 @@ diff -aur coreutils-8.32/src/cp.c coreutils-8.32-patched/src/cp.c
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 2022-01-12 20:08:19.577923660 +0100 +++ coreutils-8.32-patched/src/mv.c 2022-02-13 16:14:31.542047802 +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'},
@@ -728,7 +741,7 @@ diff -aur coreutils-8.32/src/mv.c coreutils-8.32-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,124 @@ @@ -170,8 +173,130 @@
{ {
bool copy_into_self; bool copy_into_self;
bool rename_succeeded; bool rename_succeeded;
@@ -755,30 +768,36 @@ diff -aur coreutils-8.32/src/mv.c coreutils-8.32-patched/src/mv.c
+ g_oStartTime = start_time; + g_oStartTime = start_time;
+ +
+ /* how many files are we copying */ + /* how many files are we copying */
+ char command[1024];
+ char output[1024];
+ FILE *fp ; + FILE *fp ;
+ + char output[1024];
+ char * _cEscapedString = escape_double_quotes( (unsigned char *)(size_t)source ); + char fcmd[] = "find";
+ sprintf( command, "find \"%s\" -type f | wc -l", _cEscapedString ); + fp = spawn(fcmd, (char *[]){ fcmd, (unsigned char *)(size_t)source, NULL, "-type", "f", NULL });
+ free( _cEscapedString ); + if ( fp == NULL)
+ fp = popen(command,"r");
+ if ( fp == NULL || fgets(output, sizeof(output)-1, fp) == NULL)
+ printf("failed to run find\r"); + printf("failed to run find\r");
+ else + else
+ g_iTotalFiles = atoi( output ); + {
+ char *line_buf = NULL;
+ size_t line_buf_size = 0;
+ int line_count = 0;
+ ssize_t line_size;
+ line_size = getline(&line_buf, &line_buf_size, fp);
+ while (line_size > 0)
+ {
+ line_count++;
+ line_size = getline(&line_buf, &line_buf_size, fp);
+ }
+ free (line_buf);
+ g_iTotalFiles = line_count;
+ }
+ /* close */
+ pclose(fp);
+ +
+ 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 */ + char dcmd[] = "du";
+ _cEscapedString = escape_double_quotes( (unsigned char *)(size_t)source ); + fp = spawn(dcmd, (char *[]){ dcmd, "-s", (unsigned char *)(size_t)source, NULL });
+ sprintf ( command, "du -s \"%s\"", _cEscapedString );
+ free( _cEscapedString );
+
+ /* run command */
+ 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\r" ); + printf("failed to run du\r" );
+ } + }
@@ -843,7 +862,7 @@ diff -aur coreutils-8.32/src/mv.c coreutils-8.32-patched/src/mv.c
+ sprintf ( sFType, "%s", "file(s)" ); + sprintf ( sFType, "%s", "file(s)" );
+ +
+ char f_time[20]; + char f_time[20];
+ format_time(f_time, sec_elapsed, true); + format_time(f_time, sec_elapsed, false);
+ printf ( "%d %s (%s) moved in %s (%s/s).\n", g_iFilesCopied, sFType, + printf ( "%d %s (%s) moved in %s (%s/s).\n", g_iFilesCopied, sFType,
+ sTotalWritten, f_time, s_copy_speed ); + sTotalWritten, f_time, s_copy_speed );
+ } + }
@@ -853,7 +872,7 @@ diff -aur coreutils-8.32/src/mv.c coreutils-8.32-patched/src/mv.c
if (ok) if (ok)
{ {
char const *dir_to_remove; char const *dir_to_remove;
@@ -306,6 +425,11 @@ @@ -306,6 +431,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\
@@ -865,7 +884,7 @@ diff -aur coreutils-8.32/src/mv.c coreutils-8.32-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 +485,8 @@ @@ -361,7 +491,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 ();
@@ -875,7 +894,7 @@ diff -aur coreutils-8.32/src/mv.c coreutils-8.32-patched/src/mv.c
!= -1) != -1)
{ {
switch (c) switch (c)
@@ -407,6 +532,11 @@ @@ -407,6 +538,11 @@
case 'v': case 'v':
x.verbose = true; x.verbose = true;
break; break;