[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Quilt-dev] [PATCH 20/39] backup-files: Batch mass restore
From: |
Jean Delvare |
Subject: |
[Quilt-dev] [PATCH 20/39] backup-files: Batch mass restore |
Date: |
Sat, 19 Mar 2011 10:52:50 +0100 |
User-agent: |
quilt/0.48-17.1 |
When restoring all files, batch the first steps (directory creation
and target file removal) and last steps (optional touch and backup
file removal). This makes the typical restore case (quilt pop) much,
much faster.
Note: a similar optimization would be possible for the removal
function (-x), but quilt doesn't use this function at the moment.
Signed-off-by: Jean Delvare <address@hidden>
Reviewed-by: Raphael Hertzog <address@hidden>
---
configure.ac | 39 +++++++++++++++++++++++++++++++++++++
quilt/scripts/backup-files.in | 44 ++++++++++++++++++++++++++++++++++++++++++
test/delete.test | 2 -
3 files changed, 84 insertions(+), 1 deletion(-)
--- a/quilt/scripts/backup-files.in
+++ b/quilt/scripts/backup-files.in
@@ -83,6 +83,26 @@ backup() {
fi
}
+# Same as restore, but assume that required directories are already
+# created, target files are already removed, and don't bother removing
+# the backup files or touching target files after restoration.
+restore_fast()
+{
+ local file="$1"
+ local backup="${OPT_PREFIX}${file}"
+
+ if [ ! -s "$backup" ]; then
+ $ECHO "Removing $file"
+ else
+ $ECHO "Restoring $file"
+ if [ -n "$OPT_NOLINKS" ]; then
+ cp -p "$backup" "$file"
+ else
+ ln "$backup" "$file" 2> /dev/null || cp -p "$backup"
"$file"
+ fi
+ fi
+}
+
restore()
{
local file="$1"
@@ -194,6 +214,19 @@ if [ -n "$OPT_FILE" ]; then
fi
if [ "$1" = - ]; then
+ if [ "$OPT_WHAT" = restore ]; then
+ OPT_WHAT=restore_fast
+
+ (cd "$OPT_PREFIX" && find . -type d -print0) \
+ | xargs -0 mkdir -p
+ if [ ${PIPESTATUS[0]} != 0 ]; then
+ exit 1
+ fi
+
+ (cd "$OPT_PREFIX" && find . -type f -print0) \
+ | xargs -0 -r rm -f
+ fi
+
find "$OPT_PREFIX" -type f -print \
| while read
do
@@ -202,6 +235,17 @@ if [ "$1" = - ]; then
if [ ${PIPESTATUS[0]} != 0 ]; then
exit 1
fi
+
+ if [ "$OPT_WHAT" = restore_fast ]; then
+ if [ -n "$OPT_TOUCH" ]; then
+ (cd "$OPT_PREFIX" && find . -type f -size +0 -print0) \
+ | xargs -0 -r touch
+ fi
+
+ if [ -z "$OPT_KEEP_BACKUP" ]; then
+ rm -rf "$OPT_PREFIX"
+ fi
+ fi
exit
fi
--- a/configure.ac
+++ b/configure.ac
@@ -305,8 +305,47 @@ does understand -path, you can supply it
])
fi
+AC_MSG_CHECKING([whether $FIND -print0 works])
+if $FIND . -path '*' -print0 >/dev/null 2>&1; then
+ AC_MSG_RESULT(yes)
+else
+ AC_MSG_RESULT(no)
+ AC_MSG_ERROR([
+Sorry, you have a version of find which doesn't understand -print0.
+$PACKAGE_NAME needs it. If you have access to a version of find which
+does understand -print0, you can supply its path with the
+'--with-find=' option.
+])
+fi
+
QUILT_COMPAT_PROG_PATH(XARGS, xargs)
+AC_MSG_CHECKING([whether $XARGS -r works])
+if echo | $XARGS -r echo >/dev/null 2>&1; then
+ AC_MSG_RESULT(yes)
+else
+ AC_MSG_RESULT(no)
+ AC_MSG_ERROR([
+Sorry, you have a version of xargs which doesn't understand -r.
+$PACKAGE_NAME needs it. If you have access to a version of xargs which
+does understand -r, you can supply its path with the
+'--with-xargs=' option.
+])
+fi
+
+AC_MSG_CHECKING([whether $XARGS -0 works])
+if echo | $XARGS -0 echo >/dev/null 2>&1; then
+ AC_MSG_RESULT(yes)
+else
+ AC_MSG_RESULT(no)
+ AC_MSG_ERROR([
+Sorry, you have a version of xargs which doesn't understand -0.
+$PACKAGE_NAME needs it. If you have access to a version of xargs which
+does understand -0, you can supply its path with the
+'--with-xargs=' option.
+])
+fi
+
QUILT_COMPAT_PROG_PATH_OPT(DIFFSTAT, diffstat)
if test "$DIFFSTAT" != "diffstat"; then
--- a/test/delete.test
+++ b/test/delete.test
@@ -77,7 +77,7 @@ Test the delete command.
$ quilt delete "test3"
> Removing patch %{P}test3
- >~ find: `?\.pc/test3/dir'?: Permission denied
+ >~ find: `?\./dir'?: Permission denied
$ chmod a+rx .pc/test3/dir
- [Quilt-dev] [PATCH 05/39] Clean up legacy C code, (continued)
- [Quilt-dev] [PATCH 05/39] Clean up legacy C code, Jean Delvare, 2011/03/19
- [Quilt-dev] [PATCH 11/39] backup-files: Prefix must be a directory, Jean Delvare, 2011/03/19
- [Quilt-dev] [PATCH 30/39] backup-files: Skip first mkdir on restore, Jean Delvare, 2011/03/19
- [Quilt-dev] [PATCH 29/39] backup-files: Try mass link/copy first on restore, Jean Delvare, 2011/03/19
- [Quilt-dev] [PATCH 36/39] backup-files: Drop support for -L on restore, Jean Delvare, 2011/03/19
- [Quilt-dev] [PATCH 16/39] backup-files: Optimize backup, Jean Delvare, 2011/03/19
- [Quilt-dev] [PATCH 06/39] backup-files: Drop suffix option, Jean Delvare, 2011/03/19
- [Quilt-dev] [PATCH 28/39] backup-files: Separate lists for empty and non-empty files, Jean Delvare, 2011/03/19
- [Quilt-dev] [PATCH 10/39] backup-files: Speed up ensure_nolinks, Jean Delvare, 2011/03/19
- [Quilt-dev] [PATCH 35/39] backup-files: Inline restore_fast, Jean Delvare, 2011/03/19
- [Quilt-dev] [PATCH 20/39] backup-files: Batch mass restore,
Jean Delvare <=
- [Quilt-dev] [PATCH 31/39] backup-files: New function for copy, Jean Delvare, 2011/03/19
- [Quilt-dev] [PATCH 37/39] backup-files: Drop support for backup removal, Jean Delvare, 2011/03/19
- [Quilt-dev] [PATCH 08/39] backup-files: Drop variable progname, Jean Delvare, 2011/03/19
- [Quilt-dev] [PATCH 04/39] BSD compatibility: rmdir, Jean Delvare, 2011/03/19
- [Quilt-dev] [PATCH 32/39] backup-files: Separate function copy_many, Jean Delvare, 2011/03/19
- [Quilt-dev] [PATCH 39/39] backup-files: Skip echo-only loops in silent mode, Jean Delvare, 2011/03/19
- [Quilt-dev] [PATCH 34/39] backup-files: Clarify command line options, Jean Delvare, 2011/03/19
- [Quilt-dev] [PATCH 38/39] backup-files: Keep /dev/null opened, Jean Delvare, 2011/03/19