X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=restore.pl;h=ad1f5949840fc1ef9caa20e7a4816d6b6fff1e36;hb=27cae99a5071a5c9b5a91831ef0b81aa3a3f17f9;hp=3a600b1c0cf11187d37ad162ffffeed428cc8479;hpb=b735fd32081b00b0c94196cf77c9b465703d8da5;p=cumulus.git diff --git a/restore.pl b/restore.pl index 3a600b1..ad1f594 100755 --- a/restore.pl +++ b/restore.pl @@ -28,7 +28,7 @@ my $RECURSION_LIMIT = 3; # Bound on recursive object references my $VERBOSE = 0; # Set to 1 to enable debugging messages ############################ CHECKSUM VERIFICATION ############################ -# A very simple later for verifying checksums. Checksums may be used on object +# A very simple layer for verifying checksums. Checksums may be used on object # references directly, and can also be used to verify entire reconstructed # files. # @@ -140,6 +140,15 @@ sub load_ref { # iterate_objects is a helper function used to iterate over the set of object # references that contain the file data for a regular file. +sub parse_int { + my $str = shift; + if ($str =~ /^0/) { + return oct($str); + } else { + return $str + 0; + } +} + sub uri_decode { my $str = shift; $str =~ s/%([0-9a-f]{2})/chr(hex($1))/ge; @@ -197,6 +206,8 @@ sub unpack_file { die "File $name is missing checksum or size"; } + $info{size} = parse_int($info{size}); + # Open the file to be recreated. The data will be written out by the call # to iterate_objects. open FILE, ">", "$DEST_DIR/$name" @@ -274,17 +285,17 @@ sub process_file { my $gid = -1; if (defined $info{user}) { my @items = split /\s/, $info{user}; - $uid = $items[0] + 0 if exists $items[0]; + $uid = parse_int($items[0]) if exists $items[0]; } if (defined $info{group}) { my @items = split /\s/, $info{group}; - $gid = $items[0] + 0 if exists $items[0]; + $gid = parse_int($items[0]) if exists $items[0]; } chown $uid, $gid, $dest or warn "Unable to change ownership for $dest"; if (defined $info{mode}) { - my $mode = $info{mode}; + my $mode = parse_int($info{mode}); chmod $mode, $dest or warn "Unable to change permissions for $dest"; } @@ -337,7 +348,7 @@ sub process_metadata { # Try to parse the data as "key: value" pairs of file metadata. Also # handle continuation lines, which start with whitespace and continue # the previous "key: value" pair. - if ($line =~ m/^(\w+):\s+(.*)\s*$/) { + if ($line =~ m/^(\w+):\s*(.*)$/) { $info{$1} = $2; $last_key = $1; } elsif ($line =~/^\s/ && defined $last_key) {