Optimize restore: * Don't call mkdir if we know the directory already exists. * Don't try to optimize the -L case, quilt doesn't use it anyway and the current optimization is broken. * Move common code at the end of the function.
Signed-off-by: Jean Delvare <[email protected]> Reviewed-by: Raphael Hertzog <[email protected]> --- quilt/scripts/backup-files.in | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) --- a/quilt/scripts/backup-files.in +++ b/quilt/scripts/backup-files.in @@ -91,8 +91,6 @@ restore() local file="$1" local backup="${OPT_PREFIX}${file}" - mkdir -p "$(dirname "$file")" - if [ ! -e "$backup" ]; then return 1 fi @@ -101,32 +99,28 @@ restore() if [ -e "$file" ]; then rm "$file" fi - if [ -z "$OPT_KEEP_BACKUP" ]; then - rm "$backup" - rmdir -p "${backup%/*}" 2> /dev/null || true - fi else $ECHO "Restoring $file" if [ -e "$file" ]; then rm "$file" + else + mkdir -p "$(dirname "$file")" fi - if [ -n "$OPT_NOLINKS" -a "$(stat @STAT_HARDLINK@ "$backup")" != "1" ]; then + if [ -n "$OPT_NOLINKS" ]; then cp -p "$backup" "$file" else ln "$backup" "$file" 2> /dev/null || cp -p "$backup" "$file" - if [ -n "$OPT_NOLINKS" ]; then - ensure_nolinks "$file" - fi fi - if [ -z "$OPT_KEEP_BACKUP" ]; then - rm "$backup" - rmdir -p "${backup%/*}" 2> /dev/null || true - fi if [ -n "$OPT_TOUCH" ]; then touch "$file" fi fi + + if [ -z "$OPT_KEEP_BACKUP" ]; then + rm "$backup" + rmdir -p "${backup%/*}" 2> /dev/null || true + fi } remove() _______________________________________________ Quilt-dev mailing list [email protected] http://lists.nongnu.org/mailman/listinfo/quilt-dev
