X-Git-Url: http://git.vrable.net/?a=blobdiff_plain;f=restore.pl;h=309fb738677988678decb3aaa4451908b5419217;hb=bf947741ac8f65e74d594a1e14e94d90320b403e;hp=53b48dc4e2e2922e5f008100c477e304f60e8744;hpb=6240d91b29e35bed5308139eb63c9cac7c3578fd;p=cumulus.git diff --git a/restore.pl b/restore.pl index 53b48dc..309fb73 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. # @@ -337,7 +337,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) { @@ -374,14 +374,36 @@ if (defined($ARGV[1])) { $OBJECT_DIR = dirname($descriptor); print "Source directory: $OBJECT_DIR\n" if $VERBOSE; -# Read the snapshot descriptor to find the root object. +# Read the snapshot descriptor to find the root object. Parse it to get a set +# of key/value pairs. open DESCRIPTOR, "<", $descriptor or die "Cannot open backup descriptor file $descriptor: $!"; -my $line = ; -if ($line !~ m/^Root: (\S+)$/) { +my %descriptor = (); +my ($line, $last_key); +while (defined($line = )) { + # Any lines of the form "key: value" should be inserted into the + # %descriptor dictionary. Any continuation line (a line starting with + # whitespace) will append text to the previous key's value. Ignore other + # lines. + chomp $line; + + if ($line =~ m/^(\w+):\s*(.*)$/) { + $descriptor{$1} = $2; + $last_key = $1; + } elsif ($line =~/^\s/ && defined $last_key) { + $descriptor{$last_key} .= $line; + } else { + undef $last_key; + print STDERR "Ignoring line in backup descriptor: $line\n"; + } +} + +# A valid backup descriptor should at the very least specify the root metadata +# object. +if (!exists $descriptor{Root}) { die "Expected 'Root:' specification in backup descriptor file"; } -my $root = $1; +my $root = $descriptor{Root}; close DESCRIPTOR; # Set the umask to something restrictive. As we unpack files, we'll originally