diff options
author | Edinaldo P. Silva <edps.mundognu@gmail.com> | 2015-10-23 02:47:35 +0700 |
---|---|---|
committer | Willy Sudiarto Raharjo <willysr@slackbuilds.org> | 2015-10-23 02:47:35 +0700 |
commit | 31938001a00a9bc76e42e1af02875f68aeb414e6 (patch) | |
tree | 7ef519a068aa9e2191721791b22ba52e6d8a9028 /system/advcopy | |
parent | 560194f80ef2a6437f26dbd0fda11cd6c1ebd364 (diff) | |
download | slackbuilds-31938001a00a9bc76e42e1af02875f68aeb414e6.tar.gz |
system/advcopy: Added (mod for the GNU cp and GNU mv tools).
Signed-off-by: Willy Sudiarto Raharjo <willysr@slackbuilds.org>
Diffstat (limited to 'system/advcopy')
-rw-r--r-- | system/advcopy/README | 6 | ||||
-rw-r--r-- | system/advcopy/advcopy.SlackBuild | 107 | ||||
-rw-r--r-- | system/advcopy/advcopy.info | 10 | ||||
-rw-r--r-- | system/advcopy/advcopy.sh | 2 | ||||
-rw-r--r-- | system/advcopy/advcpmv-0.5-8.23.patch | 608 | ||||
-rw-r--r-- | system/advcopy/slack-desc | 19 |
6 files changed, 752 insertions, 0 deletions
diff --git a/system/advcopy/README b/system/advcopy/README new file mode 100644 index 0000000000..1c3f3e151d --- /dev/null +++ b/system/advcopy/README @@ -0,0 +1,6 @@ +advcopy (Advanced Copy is a mod for the GNU cp and GNU mv tools) + +Advanced Copy is a mod for the GNU cp and GNU mv tools which adds a +progress bar and provides some info on what's going on. + +This package does not replace standard cp and mv programs. diff --git a/system/advcopy/advcopy.SlackBuild b/system/advcopy/advcopy.SlackBuild new file mode 100644 index 0000000000..76ecdb86dc --- /dev/null +++ b/system/advcopy/advcopy.SlackBuild @@ -0,0 +1,107 @@ +#!/bin/sh +# +# Slackware build script for advcopy. +# +# Copyright 2015 Edinaldo P. Silva, Rio de Janeiro, Brazil. +# All rights reserved. +# +# Redistribution and use of this script, with or without modification, is +# permitted provided that the following conditions are met: +# +# 1. Redistributions of this script must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED +# WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO +# EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; +# OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, +# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR +# OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF +# ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +PRGNAM=advcopy +VERSION=${VERSION:-0.5} +BUILD=${BUILD:-1} +TAG=${TAG:-_SBo} + +if [ -z "$ARCH" ]; then + case "$( uname -m )" in + i?86) ARCH=i486 ;; + arm*) ARCH=arm ;; + *) ARCH=$( uname -m ) ;; + esac +fi + +CWD=$(pwd) +TMP=${TMP:-/tmp/SBo} +PKG=$TMP/package-$PRGNAM +OUTPUT=${OUTPUT:-/tmp} + +if [ "$ARCH" = "i486" ]; then + SLKCFLAGS="-O2 -march=i486 -mtune=i686" + LIBDIRSUFFIX="" +elif [ "$ARCH" = "i686" ]; then + SLKCFLAGS="-O2 -march=i686 -mtune=i686" + LIBDIRSUFFIX="" +elif [ "$ARCH" = "x86_64" ]; then + SLKCFLAGS="-O2 -fPIC" + LIBDIRSUFFIX="64" +else + SLKCFLAGS="-O2" + LIBDIRSUFFIX="" +fi + +set -e + +SRCNAM="coreutils" +SRCVER="8.23" + +rm -rf $PKG +mkdir -p $TMP $PKG $OUTPUT +cd $TMP +rm -rf $PRGNAM-$VERSION +tar xvf $CWD/$SRCNAM-$SRCVER.tar.xz +mv $SRCNAM-$SRCVER $PRGNAM-$VERSION +cd $PRGNAM-$VERSION +chown -R root:root . +find -L . \ + \( -perm 777 -o -perm 775 -o -perm 750 -o -perm 711 -o -perm 555 \ + -o -perm 511 \) -exec chmod 755 {} \; -o \ + \( -perm 666 -o -perm 664 -o -perm 640 -o -perm 600 -o -perm 444 \ + -o -perm 440 -o -perm 400 \) -exec chmod 644 {} \; + +patch -p1 < $CWD/advcpmv-0.5-8.23.patch + +FORCE_UNSAFE_CONFIGURE=1 \ +CFLAGS="$SLKCFLAGS" \ +DEFAULT_POSIX2_VERSION=199209 \ +./configure \ + --prefix=/usr \ + --bindir=/usr/bin \ + --libdir=/usr/lib${LIBDIRSUFFIX} \ + --sysconfdir=/etc \ + --localstatedir=/var \ + --mandir=/usr/man \ + --infodir=/usr/info \ + --docdir=/usr/doc/$PRGNAM-$VERSION \ + --enable-no-install-program=groups,hostname,kill,uptime \ + --without-gmp \ + --build=$ARCH-slackware-linux + +make + +mkdir -p $PKG/usr/bin +install -Dm755 src/cp $PKG/usr/bin/vcp +install -Dm755 src/mv $PKG/usr/bin/vmv + +mkdir -p $PKG/etc/profile.d/ +cp -a $CWD/advcopy.sh $PKG/etc/profile.d/ + +mkdir -p $PKG/install +cat $CWD/slack-desc > $PKG/install/slack-desc + +cd $PKG +/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.${PKGTYPE:-tgz} diff --git a/system/advcopy/advcopy.info b/system/advcopy/advcopy.info new file mode 100644 index 0000000000..97075dd52e --- /dev/null +++ b/system/advcopy/advcopy.info @@ -0,0 +1,10 @@ +PRGNAM="advcopy" +VERSION="0.5" +HOMEPAGE="http://beatex.org/web/advancedcopy.html" +DOWNLOAD="ftp://ftp.gnu.org/gnu/coreutils/coreutils-8.23.tar.xz" +MD5SUM="abed135279f87ad6762ce57ff6d89c41" +DOWNLOAD_x86_64="" +MD5SUM_x86_64="" +REQUIRES="" +MAINTAINER="Edinaldo P. Silva" +EMAIL="edps.mundognu@gmail.com" diff --git a/system/advcopy/advcopy.sh b/system/advcopy/advcopy.sh new file mode 100644 index 0000000000..a5b323ae80 --- /dev/null +++ b/system/advcopy/advcopy.sh @@ -0,0 +1,2 @@ +alias vcp='vcp -g' +alias vmv='vmv -g' diff --git a/system/advcopy/advcpmv-0.5-8.23.patch b/system/advcopy/advcpmv-0.5-8.23.patch new file mode 100644 index 0000000000..1b476c34b6 --- /dev/null +++ b/system/advcopy/advcpmv-0.5-8.23.patch @@ -0,0 +1,608 @@ +diff -crB coreutils-8.21/src/copy.c coreutils-8.21-patch0.5/src/copy.c +*** coreutils-8.21/src/copy.c 2013-02-07 10:37:05.000000000 +0100 +--- coreutils-8.21-patch0.5/src/copy.c 2013-02-23 12:53:51.000000000 +0100 +*************** +*** 135,140 **** +--- 135,190 ---- + return err; + } + ++ /* BEGIN progress mod */ ++ static void file_progress_bar ( char * _cDest, int _iBarLength, int _iProgress, int _iTotal ) ++ { ++ // write number to progress bar ++ float fPercent = ( float ) _iProgress / ( float ) _iTotal * 100.f; ++ sprintf ( _cDest + ( _iBarLength - 6 ), "%4.1f", fPercent ); ++ // remove zero ++ _cDest[_iBarLength - 2] = ' '; ++ ++ // fill rest with '-' ++ int i; ++ for ( i = 1; i <= _iBarLength - 9; i++ ) ++ { ++ if ( fPercent > ( float ) ( i - 1 ) / ( _iBarLength - 10 ) * 100.f ) ++ _cDest[i] = '|'; ++ else ++ _cDest[i] = '-'; ++ } ++ } ++ ++ int file_size_format ( char * _cDst, int _iSize, int _iCounter ) ++ { ++ int iCounter = _iCounter; ++ double dSize = ( double ) _iSize; ++ while ( dSize >= 1000. ) ++ { ++ dSize /= 1024.; ++ iCounter++; ++ } ++ ++ /* get unit */ ++ char * sUnit; ++ if ( iCounter == 0 ) ++ sUnit = "B"; ++ else if ( iCounter == 1 ) ++ sUnit = "KiB"; ++ else if ( iCounter == 2 ) ++ sUnit = "MiB"; ++ else if ( iCounter == 3 ) ++ sUnit = "GiB"; ++ else if ( iCounter == 4 ) ++ sUnit = "TiB"; ++ else ++ sUnit = "N/A"; ++ ++ /* write number */ ++ return sprintf ( _cDst, "%5.1f %s", dSize, sUnit ); ++ } ++ /* END progress mod */ ++ + /* Copy the regular file open on SRC_FD/SRC_NAME to DST_FD/DST_NAME, + honoring the MAKE_HOLES setting and using the BUF_SIZE-byte buffer + BUF for temporary storage. Copy no more than MAX_N_READ bytes. +*************** +*** 151,163 **** + bool make_holes, + char const *src_name, char const *dst_name, + uintmax_t max_n_read, off_t *total_n_read, +! bool *last_write_made_hole) + { + *last_write_made_hole = false; + *total_n_read = 0; + + while (max_n_read) + { + bool make_hole = false; + + ssize_t n_read = read (src_fd, buf, MIN (max_n_read, buf_size)); +--- 201,369 ---- + bool make_holes, + char const *src_name, char const *dst_name, + uintmax_t max_n_read, off_t *total_n_read, +! bool *last_write_made_hole +! ) + { ++ /* BEGIN progress mod */ ++ /* create a field of 6 lines */ ++ char ** cProgressField = ( char ** ) calloc ( 6, sizeof ( char * ) ); ++ /* get console width */ ++ int iBarLength = 80; ++ struct winsize win; ++ if ( ioctl (STDOUT_FILENO, TIOCGWINSZ, (char *) &win) == 0 && win.ws_col > 0 ) ++ iBarLength = win.ws_col; ++ /* create rows */ ++ int it; ++ for ( it = 0; it < 6; it++ ) ++ { ++ cProgressField[it] = ( char * ) malloc ( iBarLength + 1 ); ++ /* init with spaces */ ++ int j; ++ for ( j = 0; j < iBarLength; j++ ) ++ cProgressField[it][j] = ' '; ++ cProgressField[it][iBarLength] = '\0'; ++ } ++ ++ /* global progress bar? */ ++ if ( g_iTotalSize ) ++ { ++ /* init global progress bar */ ++ cProgressField[2][0] = '['; ++ cProgressField[2][iBarLength - 8] = ']'; ++ cProgressField[2][iBarLength - 7] = ' '; ++ cProgressField[2][iBarLength - 1] = '%'; ++ ++ /* total size */ ++ cProgressField[1][iBarLength - 11] = '/'; ++ file_size_format ( cProgressField[1] + iBarLength - 9, g_iTotalSize, 1 ); ++ ++ /* show how many files were written */ ++ int sum_length = sprintf ( cProgressField[1], "%d files copied so far...", g_iFilesCopied ); ++ cProgressField[1][sum_length] = ' '; ++ } ++ ++ /* truncate filename? */ ++ int fn_length; ++ if ( strlen ( src_name ) > iBarLength - 22 ) ++ fn_length = ++ sprintf ( cProgressField[4], "...%s", src_name + ( strlen ( src_name ) - iBarLength + 25 ) ); ++ else ++ fn_length = sprintf ( cProgressField[4], "%s", src_name ); ++ cProgressField[4][fn_length] = ' '; ++ ++ /* filesize */ ++ int file_size = max_n_read; ++ struct stat file_stat; ++ if (fstat(src_fd, & file_stat) == 0) ++ file_size = file_stat.st_size; ++ cProgressField[4][iBarLength - 11] = '/'; ++ file_size_format ( cProgressField[4] + iBarLength - 9, file_size, 0 ); ++ ++ int iCountDown = 1; ++ char * sProgressBar = cProgressField[5]; ++ sProgressBar[0] = '['; ++ sProgressBar[iBarLength - 8] = ']'; ++ sProgressBar[iBarLength - 7] = ' '; ++ sProgressBar[iBarLength - 1] = '%'; ++ ++ /* this will always save the time in between */ ++ struct timeval last_time; ++ gettimeofday ( & last_time, NULL ); ++ int last_size = g_iTotalWritten; ++ /* END progress mod */ ++ + *last_write_made_hole = false; + *total_n_read = 0; + + while (max_n_read) + { ++ /* BEGIN progress mod */ ++ if (progress) { ++ /* update countdown */ ++ iCountDown--; ++ if ( iCountDown < 0 ) ++ { ++ /* average copy speed is assumed to be around 10 MiB/s, just to be safe. ++ * the status should be updated about 10 times per second, or approximately ++ * once per 1 MiB transferred. */ ++ iCountDown = 1024 * 1024 / buf_size; ++ /* must be greater than 0 */ ++ if (iCountDown < 1) ++ iCountDown = 1; ++ /* limit */ ++ if (iCountDown > 100) ++ iCountDown = 100; ++ } ++ ++ /* just print one line with the percentage, but not always */ ++ if ( iCountDown == 0 ) ++ { ++ /* calculate current speed */ ++ struct timeval cur_time; ++ gettimeofday ( & cur_time, NULL ); ++ int cur_size = g_iTotalWritten + *total_n_read / 1024; ++ int usec_elapsed = cur_time.tv_usec - last_time.tv_usec; ++ double sec_elapsed = ( double ) usec_elapsed / 1000000.f; ++ sec_elapsed += ( double ) ( cur_time.tv_sec - last_time.tv_sec ); ++ int copy_speed = ( int ) ( ( double ) ( cur_size - last_size ) ++ / sec_elapsed ); ++ if (copy_speed < 0) ++ copy_speed = 0; ++ char s_copy_speed[20]; ++ file_size_format ( s_copy_speed, copy_speed, 1 ); ++ /* update vars */ ++ last_time = cur_time; ++ last_size = cur_size; ++ ++ /* how much time has passed since the start? */ ++ int isec_elapsed = cur_time.tv_sec - g_oStartTime.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; ++ /* print out */ ++ sprintf ( cProgressField[3], ++ "Copying at %s/s (about %dh %dm %ds remaining)", s_copy_speed, ++ hours_remaining, min_remaining, sec_remaining ); ++ ++ int fs_len; ++ if ( g_iTotalSize ) ++ { ++ /* global progress bar */ ++ file_progress_bar ( cProgressField[2], iBarLength, ++ g_iTotalWritten + *total_n_read / 1024, g_iTotalSize ); ++ ++ /* print the global status */ ++ fs_len = file_size_format ( cProgressField[1] + iBarLength - 21, ++ g_iTotalWritten + *total_n_read / 1024, 1 ); ++ cProgressField[1][iBarLength - 21 + fs_len] = ' '; ++ } ++ ++ /* current progress bar */ ++ file_progress_bar ( sProgressBar, iBarLength, *total_n_read, file_size ); ++ ++ /* print the status */ ++ fs_len = file_size_format ( cProgressField[4] + iBarLength - 21, *total_n_read, 0 ); ++ cProgressField[4][iBarLength - 21 + fs_len] = ' '; ++ ++ /* print the field */ ++ for ( it = g_iTotalSize ? 0 : 3; it < 6; it++ ) ++ { ++ printf ( "\033[K%s\n", cProgressField[it] ); ++ if ( strlen ( cProgressField[it] ) < iBarLength ) ++ printf ( "" ); ++ } ++ if ( g_iTotalSize ) ++ printf ( "\r\033[6A" ); ++ else ++ printf ( "\r\033[3A" ); ++ fflush ( stdout ); ++ } ++ } ++ /* END progress mod */ ++ + bool make_hole = false; + + ssize_t n_read = read (src_fd, buf, MIN (max_n_read, buf_size)); +*************** +*** 215,220 **** +--- 421,439 ---- + + *last_write_made_hole = make_hole; + } ++ ++ if (progress) { ++ /* BEGIN progress mod */ ++ /* update total size */ ++ g_iTotalWritten += *total_n_read / 1024; ++ g_iFilesCopied++; ++ ++ int i; ++ for ( i = 0; i < 6; i++ ) ++ free ( cProgressField[i] ); ++ free ( cProgressField ); ++ /* END progress mod */ ++ } + + return true; + } +diff -crB coreutils-8.21/src/copy.h coreutils-8.21-patch0.5/src/copy.h +*** coreutils-8.21/src/copy.h 2013-01-31 01:46:24.000000000 +0100 +--- coreutils-8.21-patch0.5/src/copy.h 2013-02-23 12:53:51.000000000 +0100 +*************** +*** 227,232 **** +--- 227,235 ---- + /* If true, create symbolic links instead of copying files. + Create destination directories as usual. */ + bool symbolic_link; ++ ++ /* If true, draw a nice progress bar on screen */ ++ bool progress_bar; + + /* If true, do not copy a nondirectory that has an existing destination + with the same or newer modification time. */ +*************** +*** 286,289 **** +--- 289,303 ---- + bool chown_failure_ok (struct cp_options const *) _GL_ATTRIBUTE_PURE; + mode_t cached_umask (void); + ++ /* BEGIN progress mod */ ++ int file_size_format ( char * _cDst, int _iSize, int _iCounter ); ++ ++ long g_iTotalSize; ++ long g_iTotalWritten; ++ int g_iFilesCopied; ++ struct timeval g_oStartTime; ++ int g_iTotalFiles; ++ bool progress; ++ /* END progress mod */ ++ + #endif +diff --git a/src/cp.c.orig b/src/cp.c +index 99cafa7..07b5228 100644 +--- a/src/cp.c.orig ++++ b/src/cp.c +@@ -141,6 +141,7 @@ static struct option const long_opts[] = + {"target-directory", required_argument, NULL, 't'}, + {"update", no_argument, NULL, 'u'}, + {"verbose", no_argument, NULL, 'v'}, ++ {"progress-bar", no_argument, NULL, 'g'}, + {GETOPT_SELINUX_CONTEXT_OPTION_DECL}, + {GETOPT_HELP_OPTION_DECL}, + {GETOPT_VERSION_OPTION_DECL}, +@@ -179,6 +180,7 @@ Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.\n\ + -f, --force if an existing destination file cannot be\n\ + opened, remove it and try again (this option\n\ + is ignored when the -n option is also used)\n\ ++ -g, --progress-bar add progress-bar\n\ + -i, --interactive prompt before overwrite (overrides a previous -n\ + \n\ + option)\n\ +@@ -624,6 +626,57 @@ do_copy (int n_files, char **file, const char *target_directory, + error (EXIT_FAILURE, 0, _("target %s is not a directory"), + quote (file[n_files - 1])); + } ++ ++ /* BEGIN progress mod */ ++ struct timeval start_time; ++ if (progress) { ++ g_iTotalSize = 0; ++ g_iFilesCopied = 0; ++ g_iTotalWritten = 0; ++ ++ /* save time */ ++ gettimeofday ( & start_time, NULL ); ++ g_oStartTime = start_time; ++ ++ printf ( "Calculating total size... \r" ); ++ fflush ( stdout ); ++ long iTotalSize = 0; ++ int iFiles = n_files; ++ if ( ! target_directory ) ++ iFiles = n_files - 1; ++ int j; ++ for (j = 0; j < iFiles; j++) ++ { ++ /* call du -s for each file */ ++ /* create command */ ++ char command[1024]; ++ sprintf ( command, "du -s \"%s\"", file[j] ); ++ /* TODO: replace all quote signs in file[i] */ ++ ++ FILE *fp; ++ char output[1024]; ++ ++ /* run command */ ++ fp = popen(command, "r"); ++ if (fp == NULL || fgets(output, sizeof(output)-1, fp) == NULL) { ++ printf("failed to run du.\n" ); ++ } ++ else ++ { ++ /* isolate size */ ++ strchr ( output, '\t' )[0] = '\0'; ++ iTotalSize += atol ( output ); ++ ++ printf ( "Calculating total size... %ld\r", iTotalSize ); ++ fflush ( stdout ); ++ } ++ ++ /* close */ ++ pclose(fp); ++ } ++ g_iTotalSize = iTotalSize; ++ } ++ /* END progress mod */ + + if (target_directory) + { +@@ -766,6 +819,46 @@ do_copy (int n_files, char **file, const char *target_directory, + + ok = copy (source, new_dest, 0, x, &unused, NULL); + } ++ ++ /* BEGIN progress mod */ ++ if (progress) { ++ /* remove everything */ ++ int i; ++ if ( g_iTotalSize ) ++ { ++ for ( i = 0; i < 6; i++ ) ++ printf ( "\033[K\n" ); ++ printf ( "\r\033[6A" ); ++ } ++ else ++ { ++ for ( i = 0; i < 3; i++ ) ++ printf ( "\033[K\n" ); ++ printf ( "\r\033[3A" ); ++ } ++ ++ /* save time */ ++ struct timeval end_time; ++ gettimeofday ( & end_time, NULL ); ++ int usec_elapsed = end_time.tv_usec - start_time.tv_usec; ++ double sec_elapsed = ( double ) usec_elapsed / 1000000.f; ++ sec_elapsed += ( double ) ( end_time.tv_sec - start_time.tv_sec ); ++ ++ /* get total size */ ++ char sTotalWritten[20]; ++ file_size_format ( sTotalWritten, g_iTotalSize, 1 ); ++ /* TODO: using g_iTotalWritten would be more correct, but is less accurate */ ++ ++ /* calculate speed */ ++ int copy_speed = ( int ) ( ( double ) g_iTotalWritten / sec_elapsed ); ++ char s_copy_speed[20]; ++ file_size_format ( s_copy_speed, copy_speed, 1 ); ++ ++ /* good-bye message */ ++ printf ( "%d files (%s) copied in %.1f seconds (%s/s).\n", g_iFilesCopied, sTotalWritten, ++ sec_elapsed, s_copy_speed ); ++ } ++ /* END progress mod */ + + return ok; + } +@@ -801,6 +894,7 @@ cp_option_init (struct cp_options *x) + x->recursive = false; + x->sparse_mode = SPARSE_AUTO; + x->symbolic_link = false; ++ x->progress_bar = false; + x->set_mode = false; + x->mode = 0; + +@@ -943,7 +1037,7 @@ main (int argc, char **argv) + we'll actually use backup_suffix_string. */ + backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX"); + +- while ((c = getopt_long (argc, argv, "abdfHilLnprst:uvxPRS:TZ", ++ while ((c = getopt_long (argc, argv, "abdfgHilLnprst:uvxPRS:TZ", + long_opts, NULL)) + != -1) + { +@@ -1000,6 +1094,10 @@ main (int argc, char **argv) + x.unlink_dest_after_failed_open = true; + break; + ++ case 'g': ++ progress = true; ++ break; ++ + case 'H': + x.dereference = DEREF_COMMAND_LINE_ARGUMENTS; + break; +diff --git a/src/mv.c.orig b/src/mv.c +index 1db404f..5665e7f 100644 +--- a/src/mv.c.orig ++++ b/src/mv.c +@@ -65,6 +65,7 @@ static struct option const long_options[] = + {"target-directory", required_argument, NULL, 't'}, + {"update", no_argument, NULL, 'u'}, + {"verbose", no_argument, NULL, 'v'}, ++ {"progress-bar", no_argument, NULL, 'g'}, + {GETOPT_HELP_OPTION_DECL}, + {GETOPT_VERSION_OPTION_DECL}, + {NULL, 0, NULL, 0} +@@ -167,7 +168,7 @@ do_move (const char *source, const char *dest, const struct cp_options *x) + bool copy_into_self; + bool rename_succeeded; + bool ok = copy (source, dest, false, x, ©_into_self, &rename_succeeded); +- ++ + if (ok) + { + char const *dir_to_remove; +@@ -302,6 +303,7 @@ Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.\n\ + \n\ + -b like --backup but does not accept an argument\n\ + -f, --force do not prompt before overwriting\n\ ++ -g, --progress-bar add progress-bar\n\ + -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\ +@@ -373,7 +375,7 @@ main (int argc, char **argv) + we'll actually use backup_suffix_string. */ + backup_suffix_string = getenv ("SIMPLE_BACKUP_SUFFIX"); + +- while ((c = getopt_long (argc, argv, "bfint:uvS:TZ", long_options, NULL)) ++ while ((c = getopt_long (argc, argv, "bfint:uvgS:TZ", long_options, NULL)) + != -1) + { + switch (c) +@@ -419,6 +421,9 @@ main (int argc, char **argv) + case 'v': + x.verbose = true; + break; ++ case 'g': ++ progress = true; ++ break; + case 'S': + make_backups = true; + backup_suffix_string = optarg; +@@ -490,6 +495,57 @@ main (int argc, char **argv) + : no_backups); + + hash_init (); ++ ++ /* BEGIN progress mod */ ++ struct timeval start_time; ++ ++ if(progress) { ++ g_iTotalSize = 0; ++ g_iFilesCopied = 0; ++ g_iTotalWritten = 0; ++ ++ gettimeofday (& start_time, NULL); ++ g_oStartTime = start_time; ++ ++ printf ("Calculating total size... \r"); ++ fflush (stdout); ++ long iTotalSize = 0; ++ int iFiles = n_files; ++ if ( !target_directory ) ++ iFiles = 1; ++ int j; ++ for (j = 0; j < iFiles; j++) ++ { ++ /* call du -s for each file */ ++ /* create command */ ++ char command[1024]; ++ sprintf ( command, "du -s \"%s\"", file[j] ); ++ /* TODO: replace all quote signs in file[i] */ ++ ++ FILE *fp; ++ char output[1024]; ++ ++ /* run command */ ++ fp = popen(command, "r"); ++ if (fp == NULL || fgets(output, sizeof(output)-1, fp) == NULL) { ++ printf("failed to run du.\n" ); ++ } ++ else ++ { ++ /* isolate size */ ++ strchr ( output, '\t' )[0] = '\0'; ++ iTotalSize += atol ( output ); ++ ++ printf ( "Calculating total size... %ld\r", iTotalSize ); ++ fflush ( stdout ); ++ } ++ ++ /* close */ ++ pclose(fp); ++ } ++ g_iTotalSize = iTotalSize; ++ } ++ /* END progress mod */ + + if (target_directory) + { +@@ -507,6 +563,46 @@ main (int argc, char **argv) + } + else + ok = movefile (file[0], file[1], false, &x); ++ ++ /* BEGIN progress mod */ ++ if (progress) { ++ /* remove everything */ ++ int i; ++ if ( g_iTotalSize ) ++ { ++ for ( i = 0; i < 6; i++ ) ++ printf ( "\033[K\n" ); ++ printf ( "\r\033[6A" ); ++ } ++ else ++ { ++ for ( i = 0; i < 3; i++ ) ++ printf ( "\033[K\n" ); ++ printf ( "\r\033[3A" ); ++ } ++ ++ /* save time */ ++ struct timeval end_time; ++ gettimeofday ( & end_time, NULL ); ++ int usec_elapsed = end_time.tv_usec - start_time.tv_usec; ++ double sec_elapsed = ( double ) usec_elapsed / 1000000.f; ++ sec_elapsed += ( double ) ( end_time.tv_sec - start_time.tv_sec ); ++ ++ /* get total size */ ++ char sTotalWritten[20]; ++ file_size_format ( sTotalWritten, g_iTotalSize, 1 ); ++ /* TODO: using g_iTotalWritten would be more correct, but is less accurate */ ++ ++ /* calculate speed */ ++ int copy_speed = ( int ) ( ( double ) g_iTotalWritten / sec_elapsed ); ++ char s_copy_speed[20]; ++ file_size_format ( s_copy_speed, copy_speed, 1 ); ++ ++ /* good-bye message */ ++ printf ( "%d files (%s) moved in %.1f seconds (%s/s).\n", g_iFilesCopied, sTotalWritten, ++ sec_elapsed, s_copy_speed ); ++ } ++ /* END progress mod */ + + exit (ok ? EXIT_SUCCESS : EXIT_FAILURE); + } diff --git a/system/advcopy/slack-desc b/system/advcopy/slack-desc new file mode 100644 index 0000000000..52f17893f0 --- /dev/null +++ b/system/advcopy/slack-desc @@ -0,0 +1,19 @@ +# HOW TO EDIT THIS FILE: +# The "handy ruler" below makes it easier to edit a package description. +# Line up the first '|' above the ':' following the base package name, and +# the '|' on the right side marks the last column you can put a character in. +# You must make exactly 11 lines for the formatting to be correct. It's also +# customary to leave one space after the ':' except on otherwise blank lines. + + |-----handy-ruler------------------------------------------------------| +advcopy: advcopy (mod for the GNU cp and GNU mv tools) +advcopy: +advcopy: Advanced Copy is a mod for the GNU cp and GNU mv tools which adds a +advcopy: progress bar and provides some info on what's going on. +advcopy: +advcopy: Homepage: http://beatex.org/web/advancedcopy.html +advcopy: +advcopy: +advcopy: +advcopy: +advcopy: |