mirror of
https://github.com/jarun/advcpmv.git
synced 2026-02-01 13:17:41 +01:00
backport changes to 8.32 patch
This commit is contained in:
@@ -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-12 20:08:19.573923682 +0100
|
||||
@@ -129,6 +129,121 @@
|
||||
+++ coreutils-8.32-patched/src/copy.c 2022-02-13 16:14:31.534047672 +0100
|
||||
@@ -129,6 +129,133 @@
|
||||
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;
|
||||
+};
|
||||
+
|
||||
+char * escape_double_quotes ( char * _cUnescapedString )
|
||||
+FILE * spawn( const char *cmd, char *const argv[] )
|
||||
+{
|
||||
+ char * _cEscapedString;
|
||||
+ _cEscapedString = (char *) calloc( sizeof(char) * strlen(_cUnescapedString) * 2, sizeof(char) );
|
||||
+ size_t ipos = 0;
|
||||
+ size_t rpos = 0;
|
||||
+ for(rpos = 0, ipos = 0; _cUnescapedString[rpos] != '\0'; rpos++, ipos++)
|
||||
+ {
|
||||
+ if(_cUnescapedString[rpos] == '"')
|
||||
+ {
|
||||
+ _cEscapedString[ipos] = '\\';
|
||||
+ ipos++;
|
||||
+ FILE *ret = NULL;
|
||||
+ int pfd_read[2];
|
||||
+ pid_t pid;
|
||||
+
|
||||
+ if (cmd == NULL || argv == NULL)
|
||||
+ return ret;
|
||||
+
|
||||
+ if (pipe(pfd_read) < 0) {
|
||||
+ error(0, errno, "pipe: %s", cmd);
|
||||
+ return ret;
|
||||
+ }
|
||||
+ if(_cUnescapedString[rpos] == '`')
|
||||
+ {
|
||||
+ _cEscapedString[ipos] = '\\';
|
||||
+ ipos++;
|
||||
+
|
||||
+ if ((pid = fork()) == 0) {
|
||||
+ int err = dup2(pfd_read[1], 1) < 0;
|
||||
+ 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];
|
||||
+ }
|
||||
+ ipos++;
|
||||
+ _cEscapedString[ipos] = '\0';
|
||||
+ return _cEscapedString;
|
||||
+
|
||||
+ close(pfd_read[1]);
|
||||
+
|
||||
+ if (pid < 0) {
|
||||
+ close(pfd_read[0]);
|
||||
+ error(0, errno, "fork: %s", cmd);
|
||||
+ return ret;
|
||||
+ }
|
||||
+
|
||||
+ ret = fdopen(pfd_read[0], "r");
|
||||
+ return ret;
|
||||
+}
|
||||
+
|
||||
+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. */
|
||||
#define DEST_INFO_INITIAL_CAPACITY 61
|
||||
|
||||
@@ -259,17 +374,129 @@
|
||||
@@ -259,17 +386,129 @@
|
||||
static bool
|
||||
sparse_copy (int src_fd, int dest_fd, char *buf, size_t buf_size,
|
||||
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));
|
||||
if (n_read < 0)
|
||||
{
|
||||
@@ -354,6 +581,14 @@
|
||||
@@ -354,6 +593,14 @@
|
||||
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
|
||||
calls of sparse_copy() start at the correct offset. */
|
||||
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,
|
||||
size_t hole_size, off_t src_total_size,
|
||||
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;
|
||||
off_t last_ext_start = 0;
|
||||
@@ -553,10 +796,26 @@
|
||||
@@ -553,10 +808,26 @@
|
||||
last_ext_len = ext_len;
|
||||
bool read_hole;
|
||||
|
||||
@@ -316,7 +328,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 +1564,75 @@
|
||||
@@ -1305,6 +1576,75 @@
|
||||
buf_alloc = xmalloc (buf_size + 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)
|
||||
{
|
||||
bool normal_copy_required;
|
||||
@@ -1316,7 +1644,15 @@
|
||||
@@ -1316,7 +1656,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,
|
||||
@@ -409,7 +421,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 +1664,24 @@
|
||||
@@ -1328,11 +1676,24 @@
|
||||
|
||||
off_t n_read;
|
||||
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;
|
||||
goto close_src_and_dst_desc;
|
||||
@@ -1343,6 +1692,14 @@
|
||||
@@ -1343,6 +1704,14 @@
|
||||
return_val = false;
|
||||
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:
|
||||
@@ -1716,15 +2073,19 @@
|
||||
@@ -1716,15 +2085,19 @@
|
||||
fprintf (stderr,
|
||||
(x->move_mode || x->unlink_dest_before_opening
|
||||
|| 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
|
||||
--- 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 @@
|
||||
Create destination directories as usual. */
|
||||
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);
|
||||
|
||||
+/* 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 );
|
||||
+
|
||||
+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
|
||||
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-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 @@
|
||||
{"symbolic-link", no_argument, NULL, 's'},
|
||||
{"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\
|
||||
\n\
|
||||
option)\n\
|
||||
@@ -635,6 +645,83 @@
|
||||
@@ -635,6 +645,84 @@
|
||||
die (EXIT_FAILURE, 0, _("target %s is not a directory"),
|
||||
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;
|
||||
+
|
||||
+ /* 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 ;
|
||||
+ char output[1024];
|
||||
+ fp = popen(command,"r");
|
||||
+ if ( fp == NULL || fgets(output, sizeof(output)-1, fp) == NULL)
|
||||
+ char fcmd[] = "find";
|
||||
+ fp = spawn(fcmd, (char *[]){ fcmd, file[0], NULL, "-type", "f", NULL });
|
||||
+ if ( fp == NULL)
|
||||
+ printf("failed to run find\r");
|
||||
+ 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++)
|
||||
+ {
|
||||
+ /* call du -s for each file */
|
||||
+ /* create command */
|
||||
+ char command[1024];
|
||||
+ 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");
|
||||
+ char dcmd[] = "du";
|
||||
+ fp = spawn(dcmd, (char *[]){ dcmd, "-s", file[j], NULL });
|
||||
+ if (fp == NULL || fgets(output, sizeof(output)-1, fp) == NULL) {
|
||||
+ 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)
|
||||
{
|
||||
@@ -777,6 +864,56 @@
|
||||
@@ -777,6 +865,56 @@
|
||||
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)" );
|
||||
+
|
||||
+ 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,
|
||||
+ 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;
|
||||
}
|
||||
|
||||
@@ -812,6 +949,11 @@
|
||||
@@ -812,6 +950,11 @@
|
||||
x->recursive = false;
|
||||
x->sparse_mode = SPARSE_AUTO;
|
||||
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->mode = 0;
|
||||
|
||||
@@ -950,7 +1092,8 @@
|
||||
@@ -950,7 +1093,8 @@
|
||||
selinux_enabled = (0 < is_selinux_enabled ());
|
||||
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))
|
||||
!= -1)
|
||||
{
|
||||
@@ -1007,6 +1150,12 @@
|
||||
@@ -1007,6 +1151,12 @@
|
||||
x.unlink_dest_after_failed_open = true;
|
||||
break;
|
||||
|
||||
@@ -717,7 +730,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-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 @@
|
||||
{"target-directory", required_argument, NULL, 't'},
|
||||
{"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_VERSION_OPTION_DECL},
|
||||
{NULL, 0, NULL, 0}
|
||||
@@ -170,8 +173,124 @@
|
||||
@@ -170,8 +173,130 @@
|
||||
{
|
||||
bool copy_into_self;
|
||||
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;
|
||||
+
|
||||
+ /* 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)
|
||||
+ char output[1024];
|
||||
+ char fcmd[] = "find";
|
||||
+ fp = spawn(fcmd, (char *[]){ fcmd, (unsigned char *)(size_t)source, NULL, "-type", "f", NULL });
|
||||
+ if ( fp == NULL)
|
||||
+ printf("failed to run find\r");
|
||||
+ 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");
|
||||
+ fflush (stdout);
|
||||
+ long iTotalSize = 0;
|
||||
+ /* call du -s for each file */
|
||||
+ /* create command */
|
||||
+ _cEscapedString = escape_double_quotes( (unsigned char *)(size_t)source );
|
||||
+ sprintf ( command, "du -s \"%s\"", _cEscapedString );
|
||||
+ free( _cEscapedString );
|
||||
+
|
||||
+ /* run command */
|
||||
+ fp = popen(command, "r");
|
||||
+ char dcmd[] = "du";
|
||||
+ fp = spawn(dcmd, (char *[]){ dcmd, "-s", (unsigned char *)(size_t)source, NULL });
|
||||
+ if (fp == NULL || fgets(output, sizeof(output)-1, fp) == NULL) {
|
||||
+ 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)" );
|
||||
+
|
||||
+ 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,
|
||||
+ 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)
|
||||
{
|
||||
char const *dir_to_remove;
|
||||
@@ -306,6 +425,11 @@
|
||||
@@ -306,6 +431,11 @@
|
||||
\n\
|
||||
-b like --backup but does not accept an argument\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\
|
||||
-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 +485,8 @@
|
||||
@@ -361,7 +491,8 @@
|
||||
/* Try to disable the ability to unlink a directory. */
|
||||
priv_set_remove_linkdir ();
|
||||
|
||||
@@ -875,7 +894,7 @@ diff -aur coreutils-8.32/src/mv.c coreutils-8.32-patched/src/mv.c
|
||||
!= -1)
|
||||
{
|
||||
switch (c)
|
||||
@@ -407,6 +532,11 @@
|
||||
@@ -407,6 +538,11 @@
|
||||
case 'v':
|
||||
x.verbose = true;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user