summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJean Delvare <jdelvare@suse.de>2012-02-01 18:08:49 +0100
committerJean Delvare <jdelvare@suse.de>2012-02-01 18:08:49 +0100
commit275532ad427f507ac6c4dcf08d41080cb57576b0 (patch)
treeb31f5349a65c0d5b6e616eca38ee7b9a67e61501
parentd3d890aefb064de543f15746fad4dc7229034f7d (diff)
downloadquilt-275532ad427f507ac6c4dcf08d41080cb57576b0.tar.gz
backup-files: Keep /dev/null opened
Keep /dev/null opened as we will need it repeatedly. Avoiding repeated calls to open brings a small performance boost. Signed-off-by: Jean Delvare <jdelvare@suse.de> Reviewed-by: Raphael Hertzog <hertzog@debian.org>
-rw-r--r--quilt/scripts/backup-files.in16
1 files changed, 9 insertions, 7 deletions
diff --git a/quilt/scripts/backup-files.in b/quilt/scripts/backup-files.in
index acca741..b0151b5 100644
--- a/quilt/scripts/backup-files.in
+++ b/quilt/scripts/backup-files.in
@@ -1,6 +1,8 @@
#! @BASH@
set -e
+# Keep /dev/null opened as we will need it repeatedly
+exec 4> /dev/null
# Copyright (C) 2006 Steve Langasek <vorlon@debian.org>
# Copyright (C) 2011 Jean Delvare <jdelvare@suse.de>
@@ -78,7 +80,7 @@ backup() {
if [ -n "$OPT_NOLINKS" -a "$(stat @STAT_HARDLINK@ "$file")" = 1 ]; then
cp -p "$file" "$backup"
else
- ln "$file" "$backup" 2> /dev/null || cp -p "$file" "$backup"
+ ln "$file" "$backup" 2>&4 || cp -p "$file" "$backup"
if [ -n "$OPT_NOLINKS" ]; then
ensure_nolinks "$file"
fi
@@ -104,7 +106,7 @@ restore()
else
mkdir -p "$(dirname "$file")"
fi
- ln "$backup" "$file" 2> /dev/null || cp -p "$backup" "$file"
+ ln "$backup" "$file" 2>&4 || cp -p "$backup" "$file"
if [ -n "$OPT_TOUCH" ]; then
touch "$file"
@@ -118,7 +120,7 @@ restore()
if [ -z "$OPT_KEEP_BACKUP" ]; then
rm "$backup"
- rmdir -p "${backup%/*}" 2> /dev/null || true
+ rmdir -p "${backup%/*}" 2>&4 || true
fi
}
@@ -154,7 +156,7 @@ restore_all()
if (cd "$OPT_PREFIX" && \
xargs -0 cp -l --parents --remove-destination \
--target-directory="$target_dir" \
- < "$NONEMPTY_FILES" 2> /dev/null); then
+ < "$NONEMPTY_FILES" 2>&4); then
while read -d $'\0' -r
do
$ECHO "Restoring ${REPLY#./}"
@@ -171,7 +173,7 @@ restore_all()
local backup=$OPT_PREFIX$file
$ECHO "Restoring $file"
- ln "$backup" "$file" 2> /dev/null || cp -p "$backup" "$file"
+ ln "$backup" "$file" 2>&4 || cp -p "$backup" "$file"
done < "$NONEMPTY_FILES"
fi
@@ -240,7 +242,7 @@ copy_many()
# fallback to per-file processing, which always works.
if xargs -0 cp -p --parents --target-directory="$OPT_PREFIX" \
- < "$NONEMPTY_FILES" 2> /dev/null; then
+ < "$NONEMPTY_FILES" 2>&4; then
while read -d $'\0' -r
do
$ECHO "Copying $REPLY"
@@ -258,7 +260,7 @@ copy_many()
some_files_have_links()
{
(cd "$OPT_PREFIX" && find . -type f -print0) \
- | xargs -0 stat @STAT_HARDLINK@ 2> /dev/null | grep -qv '^1$'
+ | xargs -0 stat @STAT_HARDLINK@ 2>&4 | grep -qv '^1$'
}