Permalink
Browse files

cmd/import-rsnapshot: eliminate use of readlink and stat commands.

These aren't portable across operating systems.

While we're here, catch some error cases that were revealed by these
commands failing.

Also reduce indentation by using 'continue' in places where the entire loop
iteration depends on a single conditional.

Signed-off-by: Avery Pennarun <apenwarr@gmail.com>
  • Loading branch information...
1 parent cc77fec commit 0ee1a48734ab97227255f29b77362028103ff49d @apenwarr apenwarr committed Jan 4, 2011
Showing with 30 additions and 37 deletions.
  1. +24 −27 cmd/import-rsnapshot-cmd.sh
  2. +6 −10 t/test.sh
@@ -30,31 +30,28 @@ if [ ! -e "$SNAPSHOT_ROOT/." ]; then
fi
-ABSPATH=$(readlink -f "$SNAPSHOT_ROOT")
-
-for SNAPSHOT in "$ABSPATH/"*; do
- if [ -e "$SNAPSHOT/." ]; then
- for BRANCH_PATH in "$SNAPSHOT/"*; do
- if [ -e "$BRANCH_PATH/." ]; then
- # Get the snapshot's ctime
- DATE=$(stat -c %Z "$BRANCH_PATH")
- BRANCH=$(basename "$BRANCH_PATH")
- TMPIDX=/tmp/$BRANCH
-
- if [ -z "$TARGET" -o "$TARGET" = "$BRANCH" ]; then
- bup index -ux \
- -f "$TMPIDX" \
- "$BRANCH_PATH/"
- bup save \
- --strip \
- --date=$DATE \
- -f "$TMPIDX" \
- -n $BRANCH \
- "$BRANCH_PATH/"
-
- rm -f "$TMPIDX"
- fi
- fi
- done
- fi
+cd "$SNAPSHOT_ROOT" || exit 2
+
+for SNAPSHOT in *; do
+ [ -e "$SNAPSHOT/." ] || continue
+ echo "snapshot='$SNAPSHOT'" >&2
+ for BRANCH_PATH in "$SNAPSHOT/"*; do
+ BRANCH=$(basename "$BRANCH_PATH")
+ [ -e "$BRANCH_PATH/." ] || continue
+ [ -z "$TARGET" -o "$TARGET" = "$BRANCH" ] || continue
+
+ echo "snapshot='$SNAPSHOT' branch='$BRANCH'" >&2
+
+ # Get the snapshot's ctime
+ DATE=$(perl -e '@a=stat($ARGV[0]) or die "$ARGV[0]: $!";
+ print $a[10];' "$BRANCH_PATH")
+ [ -n "$DATE" ] || exit 3
+
+ TMPIDX=bupindex.$BRANCH.tmp
+ bup index -ux -f "$TMPIDX" "$BRANCH_PATH/"
+ bup save --strip --date="$DATE" \
+ -f "$TMPIDX" -n "$BRANCH" \
+ "$BRANCH_PATH/"
+ rm -f "$TMPIDX"
+ done
done
View
@@ -359,22 +359,18 @@ bup save --strip -n indexfile -f $INDEXFILE $D
WVPASSEQ "$(bup ls indexfile/latest/)" "a
b"
-WVSTART "import-rsnapshot"
-
-#set -x
-rm -rf "$BUP_DIR"
-WVPASS bup init
-D=bupdata.tmp
+WVSTART "import-rsnapshot"
+D=rsnapshot.tmp
+export BUP_DIR="$TOP/$D/.bup"
rm -rf $D
mkdir $D
-
+WVPASS bup init
mkdir -p $D/hourly.0/buptest/a
touch $D/hourly.0/buptest/a/b
mkdir -p $D/hourly.0/buptest/c/d
touch $D/hourly.0/buptest/c/d/e
-
-bup import-rsnapshot $D/
-
+WVPASS true
+WVPASS bup import-rsnapshot $D/
WVPASSEQ "$(bup ls buptest/latest/)" "a/
c/"

0 comments on commit 0ee1a48

Please sign in to comment.