quilt-dev
[Top][All Lists]
Advanced

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

[Quilt-dev] [PATCH 32/39] backup-files: Separate function copy_many


From: Jean Delvare
Subject: [Quilt-dev] [PATCH 32/39] backup-files: Separate function copy_many
Date: Sat, 19 Mar 2011 10:53:02 +0100
User-agent: quilt/0.48-17.1

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 <address@hidden>
Reviewed-by: Raphael Hertzog <address@hidden>
---
 quilt/scripts/backup-files.in |   33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

--- 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()
 {
@@ -306,6 +334,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"




reply via email to

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