The different actions don't have much code in common, so it would be more efficient to let different functions handle them.
Signed-off-by: Jean Delvare <[email protected]> Reviewed-by: Raphael Hertzog <[email protected]> --- quilt/scripts/backup-files.in | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) --- a/quilt/scripts/backup-files.in +++ b/quilt/scripts/backup-files.in @@ -57,11 +57,10 @@ ensure_nolinks() { fi } -process_file() { +backup() { local file="$1" local backup="${OPT_PREFIX}${file}" - if [ "$OPT_WHAT" == "backup" ]; then if [ -e "$backup" ]; then rm "$backup" else @@ -84,7 +83,13 @@ process_file() { touch "$backup" fi fi - elif [ "$OPT_WHAT" == "restore" ]; then +} + +restore() +{ + local file="$1" + local backup="${OPT_PREFIX}${file}" + mkdir -p "$(dirname "$file")" if [ ! -e "$backup" ]; then @@ -121,22 +126,31 @@ process_file() { touch "$file" fi fi - elif [ "$OPT_WHAT" == "remove" ]; then +} + +remove() +{ + local file="$1" + local backup="${OPT_PREFIX}${file}" + if [ -e "$backup" ]; then rm "$backup" fi rmdir -p "${backup%/*}" 2> /dev/null || true - elif [ -z "$OPT_WHAT" ]; then +} + +noop() +{ + local file="$1" + if [ -e "$file" ] && [ -n "$OPT_NOLINKS" ]; then ensure_nolinks "$file" fi - else - return 1 - fi } ECHO=echo +OPT_WHAT=noop declare -a FILELIST while [ $# -gt 0 ]; do case $1 in @@ -184,7 +198,7 @@ fi if [ -n "$OPT_FILE" ]; then cat "$OPT_FILE" \ | while read nextfile; do - process_file "$nextfile" + $OPT_WHAT "$nextfile" done fi @@ -196,14 +210,14 @@ while [ $I -lt ${#FILELIST[@]} ]; do find "$OPT_PREFIX" -type f -print \ | while read do - process_file "${REPLY#$OPT_PREFIX}" + $OPT_WHAT "${REPLY#$OPT_PREFIX}" done if [ ${PIPESTATUS[0]} != 0 ]; then exit 1 fi ;; *) - process_file "${FILELIST[$I]}" + $OPT_WHAT "${FILELIST[$I]}" ;; esac _______________________________________________ Quilt-dev mailing list [email protected] http://lists.nongnu.org/mailman/listinfo/quilt-dev
