lib/backup-files.c | 24 +++++++++++++++++------- quilt/pop.in | 14 ++++---------- quilt/scripts/patchfns.in | 20 +++++--------------- 3 files changed, 26 insertions(+), 32 deletions(-) -- Index: lib/backup-files.c =================================================================== --- lib/backup-files.c +++ lib/backup-files.c @@ -1,7 +1,7 @@ /* File: backup-files.c - Copyright (C) 2003, 2004, 2005, 2006 + Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Andreas Gruenbacher
, SuSE Labs This program is free software; you can redistribute it and/or @@ -68,6 +68,7 @@ const char *opt_prefix="", *opt_suffix="", *opt_file; int opt_silent, opt_what=what_noop; int opt_nolinks, opt_touch; +int opt_keep_backup; #define LINE_LENGTH 1024 @@ -75,7 +76,7 @@ static void usage(void) { - printf("Usage: %s [-B prefix] [-z suffix] [-f {file|-}] [-s] [-b|-r|-x] [-t] [-L] {file|-} ...\n" + printf("Usage: %s [-B prefix] [-z suffix] [-f {file|-}] [-sktL] [-b|-r|-x] {file|-} ...\n" "\n" "\tCreate hard linked backup copies of a list of files\n" "\tread from standard input.\n" @@ -83,6 +84,7 @@ "\t-b\tCreate backup\n" "\t-r\tRestore the backup\n" "\t-x\tRemove backup files and empty parent directories\n" + "\t-k\tWhen doing a restore, keep the backup files\n" "\t-B\tPath name prefix for backup files\n" "\t-z\tPath name suffix for backup files\n" "\t-s\tSilent operation; only print error messages\n" @@ -353,8 +355,10 @@ perror(file); goto fail; } - unlink(backup); - remove_parents(backup); + if (!opt_keep_backup) { + unlink(backup); + remove_parents(backup); + } } else { if (!opt_silent) printf("Restoring %s\n", file); @@ -368,8 +372,10 @@ if (opt_nolinks && ensure_nolinks(file)) goto fail; } - unlink(backup); - remove_parents(backup); + if (!opt_keep_backup) { + unlink(backup); + remove_parents(backup); + } if (opt_touch) (void) utime(file, NULL); else { @@ -487,7 +493,7 @@ progname = argv[0]; - while ((opt = getopt(argc, argv, "brxB:z:f:shLt")) != -1) { + while ((opt = getopt(argc, argv, "brkxB:z:f:shLt")) != -1) { switch(opt) { case 'b': opt_what = what_backup; @@ -497,6 +503,10 @@ opt_what = what_restore; break; + case 'k': + opt_keep_backup = 1; + break; + case 'x': opt_what = what_remove; break; Index: quilt/pop.in =================================================================== --- quilt/pop.in +++ quilt/pop.in @@ -92,21 +92,15 @@ if [ -d $QUILT_PC/$patch ] then - if ! rmdir $workdir || # note that this is racey... - ! cp -rl $QUILT_PC/$patch $workdir + local prefix=$QUILT_PC/$patch/ + [ ${prefix:0:1} == / ] || prefix=$PWD/$prefix + if ! ( cd $workdir && \ + $QUILT_LIB/backup-files -B $prefix -rks - ) then printf $"Failed to copy files to temporary directory\n" >&2 rm -rf $workdir return 1 fi - - # Now we may have some zero-size files that have no - # permissions (which represent files that the patch - # creates). Those may have been created in the meantime, - # but patch would refuse to touch them: We must remove - # them here. - find $workdir -type f -size 0 -exec rm -f '{}' ';' - fi if [ -s $patch_file ] Index: quilt/scripts/patchfns.in =================================================================== --- quilt/scripts/patchfns.in +++ quilt/scripts/patchfns.in @@ -874,31 +874,21 @@ apply_patch_temporarily() { - local workdir=$1 patch=$2 patch_file patch_args files + local workdir=$1 patch=$2 patch_file patch_args patch_file=$(patch_file_name "$patch") patch_args=$(patch_args "$patch") shift 2 - if [ $# -gt 0 ] - then - files=( "$@" ) - else - files=( $(files_in_patch "$patch") ) - fi - if [ address@hidden -gt 0 ] \ - && ! ( cd $QUILT_PC/$patch && - cp -l --parents "address@hidden" $workdir/ ) + local prefix=$QUILT_PC/$patch/ + [ ${prefix:0:1} == / ] || prefix=$PWD/$prefix + if ! ( cd $workdir && \ + $QUILT_LIB/backup-files -B $prefix -rks ${@:--} ) then printf $"Failed to copy files to temporary directory\n" >&2 return 1 fi - # Now we may have some zero-size files that have no permissions - # (which represent files that the patch creates). Those may have - # been created in the meantime, but patch would refuse to touch - # them: We must remove them here. - find $workdir -type f -size 0 -exec rm -f '{}' ';' if [ -s $patch_file ] then