]> arthur.barton.de Git - bup.git/commitdiff
cmd/import-rsnapshot: eliminate use of readlink and stat commands.
authorAvery Pennarun <apenwarr@gmail.com>
Tue, 4 Jan 2011 08:21:32 +0000 (00:21 -0800)
committerAvery Pennarun <apenwarr@gmail.com>
Tue, 4 Jan 2011 08:50:05 +0000 (00:50 -0800)
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>
cmd/import-rsnapshot-cmd.sh
t/test.sh

index 760fd00ec048ef22f8c03c37801cdda59da5a580..d594c31d969d19117c3529594ff74405848f152c 100755 (executable)
@@ -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
index 832770f1619be0239e3e471f925933abca5edd58..f9a633a3500582849ce6736a404bdd9105fe6fcc 100755 (executable)
--- a/t/test.sh
+++ b/t/test.sh
@@ -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/"