/[BackupPC]/trunk/bin/BackupPC_tarIncCreate
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/bin/BackupPC_tarIncCreate

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 156 by dpavlin, Mon Oct 10 13:04:49 2005 UTC revision 297 by dpavlin, Thu Jan 26 17:13:55 2006 UTC
# Line 1  Line 1 
1  #!/usr/bin/perl  #!/usr/bin/perl -w
2  #============================================================= -*-perl-*-  #============================================================= -*-perl-*-
3  #  #
4  # BackupPC_tarIncCreate: create a tar archive of an existing incremental dump  # BackupPC_tarIncCreate: create a tar archive of an existing incremental dump
# Line 72  use BackupPC::View; Line 72  use BackupPC::View;
72  use BackupPC::SearchLib;  use BackupPC::SearchLib;
73  use Time::HiRes qw/time/;  use Time::HiRes qw/time/;
74  use POSIX qw/strftime/;  use POSIX qw/strftime/;
75    use File::Which;
76    use File::Path;
77    use File::Slurp;
78  use Data::Dumper;       ### FIXME  use Data::Dumper;       ### FIXME
79    
80  die("BackupPC::Lib->new failed\n") if ( !(my $bpc = BackupPC::Lib->new) );  die("BackupPC::Lib->new failed\n") if ( !(my $bpc = BackupPC::Lib->new) );
81  my $TopDir = $bpc->TopDir();  my $TopDir = $bpc->TopDir();
82  my $BinDir = $bpc->BinDir();  my $BinDir = $bpc->BinDir();
83  my %Conf   = $bpc->Conf();  my %Conf   = $bpc->Conf();
84    %BackupPC::SearchLib::Conf = %Conf;
85  my %opts;  my %opts;
86  my $in_backup_increment;  my $in_backup_increment;
87    
88    
89  if ( !getopts("th:n:p:r:s:b:w:v", \%opts) ) {  if ( !getopts("th:n:p:r:s:b:w:vdf", \%opts) ) {
90      print STDERR <<EOF;      print STDERR <<EOF;
91  usage: $0 [options]  usage: $0 [options]
92    Required options:    Required options:
# Line 98  usage: $0 [options] Line 102  usage: $0 [options]
102       -p pathAdd      new path prefix       -p pathAdd      new path prefix
103       -b BLOCKS       BLOCKS x 512 bytes per record (default 20; same as tar)       -b BLOCKS       BLOCKS x 512 bytes per record (default 20; same as tar)
104       -w writeBufSz   write buffer size (default 1048576 = 1MB)       -w writeBufSz   write buffer size (default 1048576 = 1MB)
105         -f              overwrite existing parts
106       -v              verbose output       -v              verbose output
107         -d              debug output
108  EOF  EOF
109      exit(1);      exit(1);
110  }  }
111    
112  if ( $opts{h} !~ /^([\w\.\s-]+)$/ ) {  if ( $opts{h} !~ /^([\w\.\s-]+)$/ ) {
113      print(STDERR "$0: bad host name '$opts{h}'\n");      die "$0: bad host name '$opts{h}'\n";
     exit(1);  
114  }  }
115  my $Host = $opts{h};  my $Host = $opts{h};
116    
117  if ( $opts{n} !~ /^(-?\d+)$/ ) {  if ( $opts{n} !~ /^(-?\d+)$/ ) {
118      print(STDERR "$0: bad dump number '$opts{n}'\n");      die "$0: bad dump number '$opts{n}'\n";
     exit(1);  
119  }  }
120  my $Num = $opts{n};  my $Num = $opts{n};
121    
122    my $bin;
123    foreach my $c (qw/gzip md5sum tee/) {
124            $bin->{$c} = which($c) || die "$0 needs $c, install it\n";
125    }
126    
127  my @Backups = $bpc->BackupInfoRead($Host);  my @Backups = $bpc->BackupInfoRead($Host);
128  my $FileCnt = 0;  my $FileCnt = 0;
129  my $ByteCnt = 0;  my $ByteCnt = 0;
130  my $DirCnt = 0;  my $DirCnt = 0;
131  my $SpecialCnt = 0;  my $SpecialCnt = 0;
132  my $ErrorCnt = 0;  my $ErrorCnt = 0;
133    my $current_tar_size = 0;
134    my $total_increment_size = 0;
135    
136  my $i;  my $i;
137  $Num = $Backups[@Backups + $Num]{num} if ( -@Backups <= $Num && $Num < 0 );  $Num = $Backups[@Backups + $Num]{num} if ( -@Backups <= $Num && $Num < 0 );
# Line 128  for ( $i = 0 ; $i < @Backups ; $i++ ) { Line 139  for ( $i = 0 ; $i < @Backups ; $i++ ) {
139      last if ( $Backups[$i]{num} == $Num );      last if ( $Backups[$i]{num} == $Num );
140  }  }
141  if ( $i >= @Backups ) {  if ( $i >= @Backups ) {
142      print(STDERR "$0: bad backup number $Num for host $Host\n");      die "$0: bad backup number $Num for host $Host\n";
     exit(1);  
143  }  }
144    
145  my $PathRemove = $1 if ( $opts{r} =~ /(.+)/ );  my $PathRemove = $1 if ( $opts{r} =~ /(.+)/ );
146  my $PathAdd    = $1 if ( $opts{p} =~ /(.+)/ );  my $PathAdd    = $1 if ( $opts{p} =~ /(.+)/ );
147  if ( $opts{s} !~ /^([\w\s\.\/\$-]+)$/ && $opts{s} ne "*" ) {  if ( $opts{s} !~ /^([\w\s\.\/\$-]+)$/ && $opts{s} ne "*" ) {
148      print(STDERR "$0: bad share name '$opts{s}'\n");      die "$0: bad share name '$opts{s}'\n";
     exit(1);  
149  }  }
150  our $ShareName = $opts{s};  our $ShareName = $opts{s};
151  our $view = BackupPC::View->new($bpc, $Host, \@Backups);  our $view = BackupPC::View->new($bpc, $Host, \@Backups);
152    
153    # database
154    
155    my $dsn = $Conf{SearchDSN};
156    my $db_user = $Conf{SearchUser} || '';
157    
158    my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 0} );
159    
160    my $sth_inc_size = $dbh->prepare(qq{
161            update backups set
162                    inc_size = ?,
163                    parts = ?,
164                    inc_deleted = false
165            where id = ?
166    });
167    my $sth_backup_parts = $dbh->prepare(qq{
168            insert into backup_parts (
169                    backup_id,
170                    part_nr,
171                    tar_size,
172                    size,
173                    md5,
174                    items
175            ) values (?,?,?,?,?,?)
176    });
177    
178  #  #
179  # This constant and the line of code below that uses it are borrowed  # This constant and the line of code below that uses it are borrowed
180  # from Archive::Tar.  Thanks to Calle Dybedahl and Stephen Zander.  # from Archive::Tar.  Thanks to Calle Dybedahl and Stephen Zander.
# Line 163  my(%HardLinkExtraFiles, @HardLinks); Line 197  my(%HardLinkExtraFiles, @HardLinks);
197  #  #
198  # Write out all the requested files/directories  # Write out all the requested files/directories
199  #  #
200  binmode(STDOUT);  
201  my $fh = *STDOUT;  my $max_file_size = $Conf{'MaxArchiveFileSize'} || die "problem with MaxArchiveFileSize parametar";
202    
203    my $tar_dir = $Conf{InstallDir}.'/'.$Conf{GzipTempDir};
204    die "problem with $tar_dir, check GzipTempDir in configuration\n" unless (-d $tar_dir && -w $tar_dir);
205    
206    my $tar_file = BackupPC::SearchLib::getGzipName($Host, $ShareName, $Num) || die "can't getGzipName($Host, $ShareName, $Num)";
207    
208    my $tar_path_final = $tar_dir . '/' . $tar_file;
209    my $tar_path = $tar_path_final . '.tmp';
210    
211    $tar_path =~ s#//#/#g;
212    
213    my $sth = $dbh->prepare(qq{
214            SELECT
215                    backups.id
216            FROM backups
217                    JOIN shares on shares.id = shareid
218                    JOIN hosts on hosts.id = shares.hostid
219            WHERE hosts.name = ? and shares.name = ? and backups.num = ?
220    });
221    $sth->execute($Host, $ShareName, $Num);
222    my ($backup_id) = $sth->fetchrow_array;
223    $sth->finish;
224    
225    
226    # delete exising backup_parts
227    my $sth_delete_backup_parts = $dbh->prepare(qq{
228            delete from backup_parts
229            where backup_id = ?
230    });
231    $sth_delete_backup_parts->execute($backup_id);
232    
233    
234    print STDERR "backup_id: $backup_id working dir: $tar_dir, max uncompressed size $max_file_size bytes, tar $tar_file\n" if ($opts{d});
235    
236    if (-e $tar_path_final) {
237            if ($opts{f}) {
238                    rmtree $tar_path_final || die "can't remove $tar_path_final: $!";
239            } else {
240                    die "$tar_path_final allready exists\n";
241            }
242    }
243    
244    my $fh;
245    my $part = 0;
246    my $no_files = 0;
247    my $items_in_part = 0;
248    
249    sub new_tar_part {
250            my $arg = {@_};
251    
252            if ($fh) {
253                    return if ($current_tar_size == 0);
254    
255                    print STDERR "\n\t+ $part:";
256    
257                    #
258                    # Finish with two null 512 byte headers,
259                    # and then round out a full block.
260                    #
261                    my $data = "\0" x ($tar_header_length * 2);
262                    TarWrite($fh, \$data);
263                    TarWrite($fh, undef);
264    
265                    close($fh) || die "can't close archive part $part: $!";
266    
267                    my $file = $tar_path . '/' . $part;
268    
269                    my $md5 = read_file( $file . '.md5' ) || die "can't read md5sum file ${file}.md5";
270                    $md5 =~ s/\s.*$//;
271    
272                    my $size = (stat( $file . '.tar.gz' ))[7] || die "can't stat ${file}.tar.gz";
273    
274                    print "$file, $size bytes, $items_in_part items";
275    
276                    $sth_backup_parts->execute(
277                            $backup_id,
278                            $part,
279                            $current_tar_size,
280                            $size,
281                            $md5,
282                            $items_in_part,
283                    );
284    
285                    $total_increment_size += $size;
286    
287                    if ($arg->{close}) {
288    
289                            sub move($$) {
290                                    my ($from,$to) = @_;
291                                    print STDERR "# rename $from -> $to\n" if ($opts{d});
292                                    rename $from, $to || die "can't move $from -> $to: $!\n";
293                            }
294    
295                            if ($part == 1) {
296                                    print STDERR " single" if ($opts{v});
297                                    move("${tar_path}/1.tar.gz", "${tar_path_final}.tar.gz");
298                                    move("${tar_path}/1.md5", "${tar_path_final}.md5");
299                                    rmtree $tar_path or die "can't remove temporary dir $tar_path: $!";
300                            } else {
301                                    print STDERR " [last]" if ($opts{v});
302                                    move("${tar_path}", "${tar_path_final}");
303    
304                                    # if this archive was single part, remove it
305                                    foreach my $suffix (qw/.tar.gz .md5/) {
306                                            my $path = $tar_path_final . $suffix;
307                                            unlink $path if (-e $path);
308                                    }
309                            }
310    
311                            $sth_inc_size->execute(
312                                    $total_increment_size,
313                                    $part,
314                                    $backup_id
315                            );
316    
317                            print "\n\ttotal $total_increment_size bytes";
318    
319                            return;
320                    }
321    
322            }
323    
324            $part++;
325    
326            # if this is first part, create directory
327    
328            if ($part == 1) {
329                    if (-e $tar_path) {
330                            print STDERR "# deleting existing $tar_path\n" if ($opts{d});
331                            rmtree($tar_path);
332                    }
333                    mkdir($tar_path) || die "can't create directory $tar_path: $!";
334    
335                    sub abort_cleanup {
336                            print STDERR "ABORTED: cleanup temp dir ";
337                            rmtree($tar_path);
338                            $dbh->rollback;
339                            exit 1;
340                    }
341    
342                    $SIG{'INT'}  = \&abort_cleanup;
343                    $SIG{'QUIT'} = \&abort_cleanup;
344                    $SIG{'__DIE__'} = \&abort_cleanup;
345    
346            }
347    
348            my $file = $tar_path . '/' . $part;
349    
350            #
351            # create comprex pipe which will pass output through gzip
352            # for compression, create file on disk using tee
353            # and pipe same output to md5sum to create checksum
354            #
355    
356            my $cmd = '| ' . $bin->{'gzip'}   . ' ' . $Conf{GzipLevel} .      ' ' .
357                      '| ' . $bin->{'tee'}    . ' ' . $file . '.tar.gz' . ' ' .
358                      '| ' . $bin->{'md5sum'} . ' - > ' . $file . '.md5';
359    
360            print STDERR "## $cmd\n" if ($opts{d});
361    
362            open($fh, $cmd) or die "can't open $cmd: $!";
363            binmode($fh);
364    
365            $current_tar_size = 0;
366            $items_in_part = 0;
367    }
368    
369    new_tar_part();
370    
371  if (seedCache($Host, $ShareName, $Num)) {  if (seedCache($Host, $ShareName, $Num)) {
372          archiveWrite($fh, '/');          archiveWrite($fh, '/');
373          archiveWriteHardLinks($fh);          archiveWriteHardLinks($fh);
374            new_tar_part( close => 1 );
375  } else {  } else {
376          print STDERR "NOTE: no files found for $Host:$ShareName, increment $Num\n";          print STDERR "NOTE: no files found for $Host:$ShareName, increment $Num\n" if ($opts{v});
377  }          # remove temporary files if there are no files
378            rmtree($tar_path);
379    
380            my $sth = $dbh->prepare(qq{
381                    update backups set inc_size = 0, parts = 0, inc_deleted = true
382                    where id = ?
383            });
384            $sth->execute($backup_id);
385    
386  #  }
 # Finish with two null 512 byte headers, and then round out a full  
 # block.  
 #  
 my $data = "\0" x ($tar_header_length * 2);  
 TarWrite($fh, \$data);  
 TarWrite($fh, undef);  
387    
388  #  #
389  # print out totals if requested  # print out totals if requested
# Line 193  if ( $ErrorCnt && !$FileCnt && !$DirCnt Line 397  if ( $ErrorCnt && !$FileCnt && !$DirCnt
397      # Got errors, with no files or directories; exit with non-zero      # Got errors, with no files or directories; exit with non-zero
398      # status      # status
399      #      #
400      exit(1);      die "got errors or no files\n";
401  }  }
402  exit(0);  
403    $sth_inc_size->finish;
404    $sth_backup_parts->finish;
405    
406    $dbh->commit || die "can't commit changes to database";
407    $dbh->disconnect();
408    
409    exit;
410    
411  ###########################################################################  ###########################################################################
412  # Subroutines  # Subroutines
# Line 260  sub TarWrite Line 471  sub TarWrite
471  {  {
472      my($fh, $dataRef) = @_;      my($fh, $dataRef) = @_;
473    
474    
475      if ( !defined($dataRef) ) {      if ( !defined($dataRef) ) {
476          #          #
477          # do flush by padding to a full $WriteBufSz          # do flush by padding to a full $WriteBufSz
# Line 267  sub TarWrite Line 479  sub TarWrite
479          my $data = "\0" x ($WriteBufSz - length($WriteBuf));          my $data = "\0" x ($WriteBufSz - length($WriteBuf));
480          $dataRef = \$data;          $dataRef = \$data;
481      }      }
482    
483        # poor man's tell :-)
484        $current_tar_size += length($$dataRef);
485    
486      if ( length($WriteBuf) + length($$dataRef) < $WriteBufSz ) {      if ( length($WriteBuf) + length($$dataRef) < $WriteBufSz ) {
487          #          #
488          # just buffer and return          # just buffer and return
# Line 277  sub TarWrite Line 493  sub TarWrite
493      my $done = $WriteBufSz - length($WriteBuf);      my $done = $WriteBufSz - length($WriteBuf);
494      if ( syswrite($fh, $WriteBuf . substr($$dataRef, 0, $done))      if ( syswrite($fh, $WriteBuf . substr($$dataRef, 0, $done))
495                                  != $WriteBufSz ) {                                  != $WriteBufSz ) {
496          print(STDERR "Unable to write to output file ($!)\n");          die "Unable to write to output file ($!)\n";
         exit(1);  
497      }      }
498      while ( $done + $WriteBufSz <= length($$dataRef) ) {      while ( $done + $WriteBufSz <= length($$dataRef) ) {
499          if ( syswrite($fh, substr($$dataRef, $done, $WriteBufSz))          if ( syswrite($fh, substr($$dataRef, $done, $WriteBufSz))
500                              != $WriteBufSz ) {                              != $WriteBufSz ) {
501              print(STDERR "Unable to write to output file ($!)\n");              die "Unable to write to output file ($!)\n";
             exit(1);  
502          }          }
503          $done += $WriteBufSz;          $done += $WriteBufSz;
504      }      }
# Line 389  sub TarWriteFileInfo Line 603  sub TarWriteFileInfo
603  sub seedCache($$$) {  sub seedCache($$$) {
604          my ($host, $share, $dumpNo) = @_;          my ($host, $share, $dumpNo) = @_;
605    
606          my $dsn = $Conf{SearchDSN};          print STDERR curr_time(), "$host:$share #$dumpNo" if ($opts{v});
         my $db_user = $Conf{SearchUser} || '';  
           
         print STDERR curr_time(), "getting files for $host:$share increment $dumpNo..." if ($opts{v});  
607          my $sql = q{          my $sql = q{
608                  SELECT path                  SELECT path,size
609                  FROM files                  FROM files
610                          JOIN shares on shares.id = shareid                          JOIN shares on shares.id = shareid
611                          JOIN hosts on hosts.id = shares.hostid                          JOIN hosts on hosts.id = shares.hostid
612                  WHERE hosts.name = ? and shares.name = ? and backupnum = ?                  WHERE hosts.name = ? and shares.name = ? and backupnum = ?
613          };          };
614    
         my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 1} );        
615          my $sth = $dbh->prepare($sql);            my $sth = $dbh->prepare($sql);  
616          $sth->execute($host, $share, $dumpNo);          $sth->execute($host, $share, $dumpNo);
617          my $count = $sth->rows;          my $count = $sth->rows;
618          print STDERR " found $count items\n" if ($opts{v});          print STDERR " $count items, parts:" if ($opts{v});
619          while (my $row = $sth->fetchrow_arrayref) {          while (my $row = $sth->fetchrow_arrayref) {
620  #print STDERR "+ ", $row->[0],"\n";  #print STDERR "+ ", $row->[0],"\n";
621                  $in_backup_increment->{ $row->[0] }++;                  $in_backup_increment->{ $row->[0] } = $row->[1];
622          }          }
623                    
624          $sth->finish();          $sth->finish();
         $dbh->disconnect();  
625    
626          return $count;          return $count;
627  }  }
628    
629    #
630    # calculate overhad for one file in tar
631    #
632    sub tar_overhead($) {
633            my $name = shift || '';
634    
635            # header, padding of file and two null blocks at end
636            my $len = 4 * $tar_header_length;
637    
638            # if filename is longer than 99 chars subtract blocks for
639            # long filename
640            if ( length($name) > 99 ) {
641                    $len += int( ( length($name) + $tar_header_length ) / $tar_header_length ) * $tar_header_length;
642            }
643    
644            return $len;
645    }
646    
647  my $Attr;  my $Attr;
648  my $AttrDir;  my $AttrDir;
649    
# Line 429  sub TarWriteFile Line 656  sub TarWriteFile
656    
657      $tarPath =~ s{//+}{/}g;      $tarPath =~ s{//+}{/}g;
658    
659  #print STDERR "? $tarPath\n";      #print STDERR "? $tarPath\n" if ($opts{d});
660      return unless ($in_backup_increment->{$tarPath});      my $size = $in_backup_increment->{$tarPath};
661  #print STDERR "A $tarPath\n";      return unless (defined($size));
662    
663        # is this file too large to fit into MaxArchiveFileSize?
664    
665        if ( ($current_tar_size + tar_overhead($tarPath) + $size) > $max_file_size ) {
666            print STDERR "# tar file $current_tar_size + $tar_header_length + $size > $max_file_size, splitting\n" if ($opts{d});
667            new_tar_part();
668        }
669    
670        #print STDERR "A $tarPath [$size] tell: $current_tar_size\n" if ($opts{d});
671        $items_in_part++;
672    
673      if ( defined($PathRemove)      if ( defined($PathRemove)
674              && substr($tarPath, 0, length($PathRemove)) eq $PathRemove ) {              && substr($tarPath, 0, length($PathRemove)) eq $PathRemove ) {
# Line 445  sub TarWriteFile Line 682  sub TarWriteFile
682          #          #
683          # Directory: just write the header          # Directory: just write the header
684          #          #
           
                   
685          $hdr->{name} .= "/" if ( $hdr->{name} !~ m{/$} );          $hdr->{name} .= "/" if ( $hdr->{name} !~ m{/$} );
686          TarWriteFileInfo($fh, $hdr);          TarWriteFileInfo($fh, $hdr);
687          $DirCnt++;          $DirCnt++;
# Line 460  sub TarWriteFile Line 695  sub TarWriteFile
695              $ErrorCnt++;              $ErrorCnt++;
696              return;              return;
697          }          }
698          TarWriteFileInfo($fh, $hdr);          # do we need to split file?
699          my($data, $size);          if ($hdr->{size} < $max_file_size) {
700          while ( $f->read(\$data, $BufSize) > 0 ) {                  TarWriteFileInfo($fh, $hdr);
701              TarWrite($fh, \$data);                  my($data, $size);
702              $size += length($data);                  while ( $f->read(\$data, $BufSize) > 0 ) {
703          }                      TarWrite($fh, \$data);
704          $f->close;                      $size += length($data);
705          TarWritePad($fh, $size);                  }
706                    $f->close;
707                    TarWritePad($fh, $size);
708                  $FileCnt++;                  $FileCnt++;
709                  $ByteCnt += $size;                  $ByteCnt += $size;
710            } else {
711                    my $full_size = $hdr->{size};
712                    my $orig_name = $hdr->{name};
713                    my $max_part_size = $max_file_size - tar_overhead($hdr->{name});
714    
715                    my $parts = int(($full_size + $max_part_size - 1) / $max_part_size);
716                    print STDERR "# splitting $orig_name [$full_size bytes] into $parts parts\n" if ($opts{d});
717                    foreach my $subpart ( 1 .. $parts ) {
718                            new_tar_part();
719                            if ($subpart < $parts) {
720                                    $hdr->{size} = $max_part_size;
721                            } else {
722                                    $hdr->{size} = $full_size % $max_part_size;
723                            }
724                            $hdr->{name} = $orig_name . '/' . $subpart;
725                            print STDERR "## creating part $subpart ",$hdr->{name}, " [", $hdr->{size}," bytes]\n";
726    
727                            TarWriteFileInfo($fh, $hdr);
728                            my($data, $size);
729    if (0) {
730                            for ( 1 .. int($hdr->{size} / $BufSize) ) {
731                                    my $r_size = $f->read(\$data, $BufSize);
732                                    die "expected $BufSize bytes read, got $r_size bytes!" if ($r_size != $BufSize);
733                                    TarWrite($fh, \$data);
734                                    $size += length($data);
735                            }
736    }
737                            my $size_left = $hdr->{size} % $BufSize;
738                            my $r_size = $f->read(\$data, $size_left);
739                            die "expected $size_left bytes last read, got $r_size bytes!" if ($r_size != $size_left);
740    
741                            TarWrite($fh, \$data);
742                            $size += length($data);
743                            TarWritePad($fh, $size);
744    
745                            $items_in_part++;
746                    }
747                    $f->close;
748                    $FileCnt++;
749                    $ByteCnt += $full_size;
750                    new_tar_part();
751            }
752      } elsif ( $hdr->{type} == BPC_FTYPE_HARDLINK ) {      } elsif ( $hdr->{type} == BPC_FTYPE_HARDLINK ) {
753          #          #
754          # Hardlink file: either write a hardlink or the complete file          # Hardlink file: either write a hardlink or the complete file
755                  # depending upon whether the linked-to file will be written          # depending upon whether the linked-to file will be written
756                  # to the archive.          # to the archive.
757          #          #
758                  # Start by reading the contents of the link.          # Start by reading the contents of the link.
759                  #          #
760          my $f = BackupPC::FileZIO->open($hdr->{fullPath}, 0, $hdr->{compress});          my $f = BackupPC::FileZIO->open($hdr->{fullPath}, 0, $hdr->{compress});
761          if ( !defined($f) ) {          if ( !defined($f) ) {
762              print(STDERR "Unable to open file $hdr->{fullPath}\n");              print(STDERR "Unable to open file $hdr->{fullPath}\n");
# Line 488  sub TarWriteFile Line 767  sub TarWriteFile
767          while ( $f->read(\$data, $BufSize) > 0 ) {          while ( $f->read(\$data, $BufSize) > 0 ) {
768              $hdr->{linkname} .= $data;              $hdr->{linkname} .= $data;
769          }          }
770                  $f->close;          $f->close;
771                  my $done = 0;          my $done = 0;
772                  my $name = $hdr->{linkname};          my $name = $hdr->{linkname};
773                  $name =~ s{^\./}{/};          $name =~ s{^\./}{/};
774                  if ( $HardLinkExtraFiles{$name} ) {          if ( $HardLinkExtraFiles{$name} ) {
775                      #              #
776                      # Target file will be or was written, so just remember              # Target file will be or was written, so just remember
777                      # the hardlink so we can dump it later.              # the hardlink so we can dump it later.
778                      #              #
779                      push(@HardLinks, $hdr);              push(@HardLinks, $hdr);
780                      $SpecialCnt++;              $SpecialCnt++;
781                  } else {          } else {
782                      #              #
783                      # Have to dump the original file.  Just call the top-level              # Have to dump the original file.  Just call the top-level
784                      # routine, so that we save the hassle of dealing with              # routine, so that we save the hassle of dealing with
785                      # mangling, merging and attributes.              # mangling, merging and attributes.
786                      #              #
787                      $HardLinkExtraFiles{$hdr->{linkname}} = 1;              $HardLinkExtraFiles{$hdr->{linkname}} = 1;
788                      archiveWrite($fh, $hdr->{linkname}, $hdr->{name});              archiveWrite($fh, $hdr->{linkname}, $hdr->{name});
789                  }          }
790      } elsif ( $hdr->{type} == BPC_FTYPE_SYMLINK ) {      } elsif ( $hdr->{type} == BPC_FTYPE_SYMLINK ) {
791          #          #
792          # Symbolic link: read the symbolic link contents into the header          # Symbolic link: read the symbolic link contents into the header

Legend:
Removed from v.156  
changed lines
  Added in v.297

  ViewVC Help
Powered by ViewVC 1.1.26