[Top][All Lists]
[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
- [Quilt-dev] [PATCH 00/39] Reimplement backup-files in bash, Jean Delvare, 2011/03/19
- [Quilt-dev] [PATCH 03/39] BSD compatibility: cp, Jean Delvare, 2011/03/19
- [Quilt-dev] [PATCH 02/39] BSD compatibility: stat, Jean Delvare, 2011/03/19
- [Quilt-dev] [PATCH 21/39] backup-files: Drop curly braces, Jean Delvare, 2011/03/19
- [Quilt-dev] [PATCH 07/39] backup-files: Skip test for file presence, Jean Delvare, 2011/03/19
- [Quilt-dev] [PATCH 18/39] backup-files: Make input methods mutually exclusive, Jean Delvare, 2011/03/19
- [Quilt-dev] [PATCH 25/39] backup-files: Separate function restore_all, Jean Delvare, 2011/03/19
- [Quilt-dev] [PATCH 26/39] backup-files: Quick exit when unlinking is not needed, Jean Delvare, 2011/03/19
- [Quilt-dev] [PATCH 13/39] backup-files: Split code to sparate functions,
Jean Delvare <=
- [Quilt-dev] [PATCH 24/39] backup-files: Avoid negations, Jean Delvare, 2011/03/19
- [Quilt-dev] [PATCH 14/39] backup-files: Mass reindent, Jean Delvare, 2011/03/19
- [Quilt-dev] [PATCH 01/39] Make backup-files a shell script, Jean Delvare, 2011/03/19
- [Quilt-dev] [PATCH 22/39] backup-files: Check if backup exists, Jean Delvare, 2011/03/19
- [Quilt-dev] [PATCH 12/39] backup-files: Simplify find loop, Jean Delvare, 2011/03/19
- [Quilt-dev] [PATCH 15/39] backup-files: Optimize restore, Jean Delvare, 2011/03/19
- [Quilt-dev] [PATCH 23/39] backup-files: Optimize noop, Jean Delvare, 2011/03/19
- [Quilt-dev] [PATCH 27/39] backup-files: Remember the list of files, Jean Delvare, 2011/03/19
- [Quilt-dev] [PATCH 17/39] backup-files: Drop variable filelist, Jean Delvare, 2011/03/19