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
commitc954eb0f9f52967a9d3abd7aa260108765347162 (patch)
tree3448e028fb58dc0d44b3444624d7a2cd8166e1dc
parent4aeec070f74344edcaaf5efb72f39749bd812961 (diff)
downloadquilt-c954eb0f9f52967a9d3abd7aa260108765347162.tar.gz
backup-files: New function for copy
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 <jdelvare@suse.de> Reviewed-by: Raphael Hertzog <hertzog@debian.org>
-rw-r--r--quilt/scripts/backup-files.in23
-rw-r--r--quilt/snapshot.in2
-rw-r--r--test/backup-files.test29
3 files changed, 52 insertions, 2 deletions
diff --git a/quilt/scripts/backup-files.in b/quilt/scripts/backup-files.in
index 184c237..19bfa51 100644
--- 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
diff --git a/quilt/snapshot.in b/quilt/snapshot.in
index 0554fa6..ccddd0a 100644
--- a/quilt/snapshot.in
+++ b/quilt/snapshot.in
@@ -86,7 +86,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
diff --git a/test/backup-files.test b/test/backup-files.test
index b57374e..405341d 100644
--- 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