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
commit4313f8222262def7e5042c87ac0c2722da2501c0 (patch)
treec8f4a43782b5843ba85e391161ea14d983375492
parentc954eb0f9f52967a9d3abd7aa260108765347162 (diff)
downloadquilt-4313f8222262def7e5042c87ac0c2722da2501c0.tar.gz
backup-files: Separate function copy_many
Create a dedicated function for mass-copying files. At the moment it isn't bringing any gain, but this will get improved next. Signed-off-by: Jean Delvare <jdelvare@suse.de> Reviewed-by: Raphael Hertzog <hertzog@debian.org>
-rw-r--r--quilt/scripts/backup-files.in33
1 files changed, 33 insertions, 0 deletions
diff --git a/quilt/scripts/backup-files.in b/quilt/scripts/backup-files.in
index 19bfa51..32d3d50 100644
--- a/quilt/scripts/backup-files.in
+++ b/quilt/scripts/backup-files.in
@@ -239,6 +239,34 @@ copy()
fi
}
+copy_many()
+{
+ local NONEMPTY_FILES
+
+ # Store the list of non-empty files to process
+ NONEMPTY_FILES=$(gen_tempfile)
+ trap "rm -f \"$NONEMPTY_FILES\"" EXIT
+
+ # Keep the temporary file opened to speed up the loop
+ exec 3> "$NONEMPTY_FILES"
+ cat "$OPT_FILE" \
+ | while read
+ do
+ if [ -e "$REPLY" ]; then
+ printf '%s\0' "$REPLY" >&3
+ else
+ # This is a rare case, not worth optimizing
+ copy "$REPLY"
+ fi
+ done
+ exec 3>&-
+
+ while read -d $'\0' -r
+ do
+ copy "$REPLY"
+ done < "$NONEMPTY_FILES"
+}
+
# Test if some backed up files have a link count greater than 1
some_files_have_links()
{
@@ -301,6 +329,11 @@ if [ -z "$OPT_WHAT" ]; then
fi
if [ -n "$OPT_FILE" ]; then
+ if [ "$OPT_WHAT" = copy ]; then
+ copy_many
+ exit
+ fi
+
cat "$OPT_FILE" \
| while read nextfile; do
$OPT_WHAT "$nextfile"