quilt-dev
[Top][All Lists]
Advanced

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

[Quilt-dev] [PATCH 31/39] backup-files: New function for copy


From: Jean Delvare
Subject: [Quilt-dev] [PATCH 31/39] backup-files: New function for copy
Date: Sat, 19 Mar 2011 10:53:01 +0100
User-agent: quilt/0.48-17.1

We are abusing backup-files's "backup" function for quilt snapshot.
What we need is semantically different, and it works almost by
accident. We don't want linked copies of the files, we want real
copies, and the fact that "quilt snapshot" may touch the working
files is a little frightening IMHO.

So, implement a separate "copy" function which does what we need. Not
only it does the right thing, but it will also be somewhat faster
than "backup", as we can do straight copies of the files without
checking for their link count first.

Signed-off-by: Jean Delvare <address@hidden>
Reviewed-by: Raphael Hertzog <address@hidden>
---
 quilt/scripts/backup-files.in |   23 ++++++++++++++++++++++-
 quilt/snapshot.in             |    2 +-
 test/backup-files.test        |   29 +++++++++++++++++++++++++++++
 3 files changed, 52 insertions(+), 2 deletions(-)

--- a/quilt/scripts/backup-files.in
+++ b/quilt/scripts/backup-files.in
@@ -27,12 +27,13 @@ set -e
 # name prefix for the backup files must be specified with the -B option.
 
 usage () {
-       echo "Usage: $0 -B prefix [-s] [-k] [-t] [-L] [-b|-r|-x] {-f 
{file|-}|-|file ...}
+       echo "Usage: $0 -B prefix [-s] [-k] [-t] [-L] [-b|-r|-c|-x] {-f 
{file|-}|-|file ...}
 
        Create or restore backup copies of a list of files.
 
        -b      Create backup
        -r      Restore the backup
+       -c      Create simple copy
        -x      Remove backup files and empty parent directories
        -k      When doing a restore, keep the backup files
        -B      Path name prefix for backup files
@@ -220,6 +221,24 @@ noop_nolinks()
        fi
 }
 
+copy()
+{
+       local file=$1
+       local backup=$OPT_PREFIX$file
+       local dir
+
+       dir=$(dirname "$backup")
+       [ -d "$dir" ] || mkdir -p "$dir"
+
+       if [ -e "$file" ]; then
+               $ECHO "Copying $file"
+               cp -p "$file" "$backup"
+       else
+               $ECHO "New file $file"
+               : > "$backup"
+       fi
+}
+
 # Test if some backed up files have a link count greater than 1
 some_files_have_links()
 {
@@ -235,6 +254,8 @@ while [ $# -gt 0 ]; do
                ;;
        -r)     OPT_WHAT=restore
                ;;
+       -c)     OPT_WHAT=copy
+               ;;
        -x)     OPT_WHAT=remove
                ;;
        -B)     OPT_PREFIX=$2
--- a/quilt/snapshot.in
+++ b/quilt/snapshot.in
@@ -85,7 +85,7 @@ done \
        }
        { print }
 ' \
-| $QUILT_DIR/scripts/backup-files -b -s -L -f - -B "$QUILT_PC/$snap_subdir/"
+| $QUILT_DIR/scripts/backup-files -c -s -f - -B "$QUILT_PC/$snap_subdir/"
 
 ### Local Variables:
 ### mode: shell-script
--- a/test/backup-files.test
+++ b/test/backup-files.test
@@ -200,3 +200,32 @@ Unit test of the backup-files script.
        > Removing new
        > Restoring foo
        > Restoring space bar
+       $ rm "linked space"
+
+       # Test copy (as used by quilt snapshot)
+       $ %{QUILT_DIR}/scripts/backup-files -B snapshot/ -c -f -
+       < new
+       < foo
+       < space bar
+       < dir with spaces/space file
+       > New file new
+       > Copying foo
+       > Copying space bar
+       > Copying dir with spaces/space file
+       $ ls -l foo | awk '{ print $2 }'
+       > 2
+       $ ls -l "space bar" | awk '{ print $2 }'
+       > 1
+       $ ls -l "dir with spaces/space file" | awk '{ print $2 }'
+       > 1
+       $ [ ! -e new ] || echo "file new shouldn't exist"
+       $ ls -l snapshot/new | awk '{ print $2 }'
+       > 1
+       $ ls -l snapshot/foo | awk '{ print $2 }'
+       > 1
+       $ ls -l snapshot/"space bar" | awk '{ print $2 }'
+       > 1
+       $ ls -l snapshot/"dir with spaces/space file" | awk '{ print $2 }'
+       > 1
+       $ [ ! -s new ] || echo "file snapshot/new should be empty"
+       $ rm -rf snapshot




reply via email to

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