quilt-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Quilt-dev] [PATCH 13/39] backup-files: Split code to sparate functions


From: Jean Delvare
Subject: [Quilt-dev] [PATCH 13/39] backup-files: Split code to sparate functions
Date: Sat, 19 Mar 2011 10:52:43 +0100
User-agent: quilt/0.48-17.1

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 <address@hidden>
Reviewed-by: Raphael Hertzog <address@hidden>
---
 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 address@hidden ]; 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
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]