From 0dca065f3a35c7fb1c56629ab484691e6b22019f Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Tue, 8 Jun 2010 08:55:21 -0400 Subject: restore: handle directories separately * in the case of a directory, copy the contents of the restore target to a new directory and chown it back to the original UID:GID. * use %Y%m%d as a suffix on the restored file instead of seconds from epoch. --- squashfu | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/squashfu b/squashfu index 2c41f26..81ae906 100755 --- a/squashfu +++ b/squashfu @@ -356,6 +356,7 @@ action_restore () { IFS=$'\n' read -r -d $'\0' -a results < <(find $BINS_DIR/*/$(dirname $1)/$(basename $1) -maxdepth 0 2>/dev/null) [[ ${#results[@]} -eq 0 ]] && die "Target not found: '$1'" + local restore_type=$(stat -c %F ${results[0]}) declare -a snaps @@ -382,10 +383,16 @@ action_restore () { mount_squash || die "Failed to mount seed" mount_union_with_bins ${bin_list[@]:0:$num} || die "Failed to mount union" - # XXX: Move the contents, not the dir (avoid extra subdir) - rsync -a "$UNION_MOUNT/$1" "$(basename $1).${snaps[$reply]}" + local restore_name="$1.$(date --date=@${snaps[$reply]} +%Y%m%d)" - info "Your $(stat -c %F "$UNION_MOUNT/$1") has been restored as ${PWD}/$(basename $1).${snaps[$reply]}" + { + if [[ -d "$UNION_MOUNT/$1" ]]; then + rsync -a $UNION_MOUNT/$1/* "$restore_name" && + chown $(stat -c %u:%g "$UNION_MOUNT/$1") "$restore_name"; + else + rsync -a "$UNION_MOUNT/$1" "$restore_name"; + fi + } && info "Your ${restore_type##regular } has been restored as ${restore_name}" unmount_all -- cgit v1.2.3