Changeset 76

Show
Ignore:
Timestamp:
10/29/06 15:32:02 (3 years ago)
Author:
bradfitz
Message:

merging mart's win32 changes from trunk

Location:
branches/refactoring
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • branches/refactoring/brackup

    r63 r76  
    6767my $opt_du_stats; 
    6868 
     69my $config_file = Brackup::Config->default_config_file_name; 
     70 
    6971usage() unless 
    7072    GetOptions( 
     
    7678               'dry-run'   => \$opt_dryrun, 
    7779               'du-stats' => \$opt_du_stats, 
     80               'config=s'  => \$config_file, 
    7881               ); 
    7982 
     
    8487} 
    8588 
    86 my $config = eval { Brackup::Config->load("$ENV{HOME}/.brackup.conf") } or 
     89my $config = eval { Brackup::Config->load($config_file) } or 
    8790    usage($@); 
    8891 
     
    116119my @now = localtime(); 
    117120$backup_file ||= $root->name . "-" . sprintf("%04d%02d%02d", $now[5]+1900, $now[4]+1, $now[3]) . ".brackup"; 
    118 $backup_file =~ s!^~/!$ENV{HOME}/!; 
     121$backup_file =~ s!^~/!$ENV{HOME}/! if $ENV{HOME}; 
    119122$backup_file = "$cwd/$backup_file" unless $backup_file =~ m!^/!; 
    120123 
  • branches/refactoring/brackup-restore

    r52 r76  
    7070my ($opt_verbose, $meta_file, $opt_help, $restore_dir, $opt_all, $prefix); 
    7171 
     72my $config_file = Brackup::Config->default_config_file_name; 
     73 
    7274usage() unless 
    7375    GetOptions( 
     
    7880               'all'       => \$opt_all, 
    7981               'just=s'    => \$prefix, 
     82               'config=s'  => \$config_file, 
    8083               ); 
    8184 
     
    8689} 
    8790 
    88 my $config = eval { Brackup::Config->load("$ENV{HOME}/.brackup.conf") } or 
     91my $config = eval { Brackup::Config->load($config_file) } or 
    8992    usage($@); 
    9093 
  • branches/refactoring/lib/Brackup/Config.pm

    r69 r76  
    5353 
    5454    return $self; 
     55} 
     56 
     57sub default_config_file_name { 
     58    my ($class) = @_; 
     59     
     60    if ($ENV{HOME}) { 
     61        # Default for UNIX folk 
     62        return "$ENV{HOME}/.brackup.conf"; 
     63    } 
     64    elsif ($ENV{APPDATA}) { 
     65        # For Windows users 
     66        return "$ENV{APPDATA}/brackup.conf"; 
     67    } 
     68    else { 
     69        # Fall back on the current directory 
     70        return "brackup.conf"; 
     71    } 
     72 
    5573} 
    5674 
  • branches/refactoring/lib/Brackup/File.pm

    r69 r76  
    5353sub is_link { 
    5454    my $self = shift; 
    55     return S_ISLNK($self->stat->mode); 
     55    my $result = eval { S_ISLNK($self->stat->mode) }; 
     56    $result = -l $self->fullpath unless defined($result); 
     57    return $result; 
    5658} 
    5759 
  • branches/refactoring/lib/Brackup/Root.pm

    r69 r76  
    66use Brackup::Dict::SQLite; 
    77use File::Temp qw(tempfile); 
     8use IPC::Open2; 
     9use Symbol; 
    810 
    911sub new { 
     
    185187        unless -s $tmpfn == length $$data; 
    186188 
    187     my ($etmpfh, $etmpfn) = tempfile(); 
    188  
    189     system($self->gpg_path, $self->gpg_args, 
    190            "--recipient", $gpg_rcpt, 
    191            "--trust-model=always", 
    192            "--batch", 
    193            "--encrypt", 
    194            "--output=$etmpfn", 
    195            "--yes", $tmpfn) 
    196         and die "Failed to run gpg: $!\n"; 
    197     open (my $enc_fh, $etmpfn) or die "Failed to open $etmpfn: $!\n"; 
    198     return do { local $/; <$enc_fh>; }; 
     189    my $cout = Symbol::gensym(); 
     190    my $cin = Symbol::gensym(); 
     191 
     192    my $pid = IPC::Open2::open2($cout, $cin, 
     193        $self->gpg_path, $self->gpg_args, 
     194        "--recipient", $gpg_rcpt, 
     195        "--trust-model=always", 
     196        "--batch", 
     197        "--encrypt", 
     198        "--output=-",  # Send output to stdout 
     199        "--yes", 
     200        $tmpfn 
     201    ); 
     202 
     203    binmode $cout; 
     204     
     205    my $ret = do { local $/; <$cout>; }; 
     206 
     207    waitpid($pid, 0); 
     208    die "GPG failed: $!" if $? != 0; # If gpg return status is non-zero 
     209 
     210    return $ret; 
    199211} 
    200212 
  • branches/refactoring/lib/Brackup/Target/Filesystem.pm

    r69 r76  
    99    my $self = $class->SUPER::new($confsec); 
    1010    $self->{path} = $confsec->path_value("path"); 
     11    $self->{nocolons} = $confsec->value("no_filename_colons"); 
     12    $self->{nocolons} = ($^O eq 'MSWin32') unless defined $self->{nocolons}; # LAME: Make it work on Windows 
    1113    return $self; 
    1214} 
     
    3537    my $fulldig = $dig; 
    3638    $dig =~ s/^\w+://; # remove the "hashtype:" from beginning 
     39    $fulldig =~ s/:/./g if $self->{nocolons}; # Convert colons to dots if we've been asked to 
    3740    while (length $dig && @parts < 4) { 
    3841        $dig =~ s/^(.{1,4})//; 
     
    8083    } 
    8184    open (my $fh, ">$path") or die "Failed to open $path for writing: $!\n"; 
     85    binmode($fh); 
    8286    my $chunkref = $chunk->chunkref; 
    8387    print $fh $$chunkref; 
     
    8690    my $actual_size   = -s $path; 
    8791    my $expected_size = length $$chunkref; 
     92    unless (defined($actual_size)) { 
     93        die "Chunk output file $path does not exist. Do you need to set no_filename_colons=1?"; 
     94    } 
    8895    unless ($actual_size == $expected_size) { 
    89         die "Chunk was written to disk wrong:  size is $actual_size, expecting $expected_size\n"; 
     96        die "Chunk $path was written to disk wrong:  size is $actual_size, expecting $expected_size\n"; 
    9097    } 
    9198