Changeset cb34270e0e1f3d870bd65f6fe1cc7f193c774ee7

Show
Ignore:
Timestamp:
02/28/07 04:38:30 (7 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1172637510 +0000
git-parent:

[00791d891a6e10ae6578d058c9ead7544c5f1fa6]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1172637510 +0000
Message:

closes #5

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • zetaback

    r00791d8 rcb34270  
    396396} 
    397397 
    398 sub choose($@) { 
    399   my($name, @list) = @_; 
     398sub __default_sort($$) { return $_[0] cmp $_[1]; } 
     399     
     400sub choose($$;$) { 
     401  my($name, $obj, $sort) = @_; 
     402  $sort ||= \&__default_sort;; 
     403  my @list; 
     404  my $hash; 
     405  if(ref $obj eq 'ARRAY') { 
     406    @list = sort { $sort->($a,$b); } (@$obj); 
     407    map { $hash->{$_} = $_; } @list; 
     408  } 
     409  elsif(ref $obj eq 'HASH') { 
     410    @list = sort { $sort->($a,$b); } (keys %$obj); 
     411    $hash = $obj; 
     412  } 
     413  else { 
     414    die "choose passed bad object: " . ref($obj) . "\n"; 
     415  } 
    400416  return $list[0] if(scalar(@list) == 1); 
    401417  print "\n"; 
    402418  my $i = 1; 
    403419  for (@list) { 
    404     printf " %3d) $_\n", $i++; 
     420    printf " %3d) $hash->{$_}\n", $i++; 
    405421  } 
    406422  my $selection = 0; 
     
    411427    chomp($selection = <>); 
    412428  } 
    413   return $list[$selection - 1]
     429  return $hash->{$list[$selection - 1]}
    414430} 
    415431 
     
    467483 
    468484  # Here goes the possibly interactive dialog 
    469   my $host = choose("Restore from host", keys %source); 
    470   my $disk = choose("Restore from ZFS", keys %{$source{$host}}); 
    471   my $timestamp = choose("Restore as of timestamp", @{$source{$host}->{$disk}}); 
     485  my $host = choose("Restore from host",  [keys %source]); 
     486  my $disk = choose("Restore from ZFS", [keys %{$source{$host}}]); 
     487   
     488  # Times are special.  We build a human readable form and use a numerical 
     489  # sort function instead of the default lexical one. 
     490  my %times; 
    472491  my $tf = config_get($host, 'time_format'); 
     492  map { $times{$_} = strftime($tf, localtime($_)); } @{$source{$host}->{$disk}}; 
     493  my $timestamp = choose("Restore as of timestamp", \%times, 
     494                         sub { $_[0] <=> $_[1]; }); 
    473495 
    474496  my $store = config_get($host, 'store');