"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "bin/BackupPC_tarCreate" between
BackupPC-4.3.2.tar.gz and BackupPC-4.4.0.tar.gz

About: BackupPC is a high-performance, enterprise-grade system for backing up Linux and WinXX PCs and laptops to a server’s disk (http/cgi user interface).

BackupPC_tarCreate  (BackupPC-4.3.2):BackupPC_tarCreate  (BackupPC-4.4.0)
skipping to change at line 60 skipping to change at line 60
# This program is distributed in the hope that it will be useful, # This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of # but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details. # GNU General Public License for more details.
# #
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
#======================================================================== #========================================================================
# #
# Version 4.3.2, released 17 Feb 2020. # Version 4.4.0, released 20 Jun 2020.
# #
# See http://backuppc.sourceforge.net. # See http://backuppc.sourceforge.net.
# #
#======================================================================== #========================================================================
use strict; use strict;
no utf8; no utf8;
use lib "__INSTALLDIR__/lib"; use lib "__INSTALLDIR__/lib";
use File::Path; use File::Path;
use Getopt::Std; use Getopt::Std;
use Encode qw/from_to/; use Encode qw/from_to/;
use Data::Dumper; use Data::Dumper;
use BackupPC::Lib; use BackupPC::Lib;
use BackupPC::XS qw( :all ); use BackupPC::XS qw( :all );
use BackupPC::View; use BackupPC::View;
die("BackupPC::Lib->new failed\n") if ( !(my $bpc = BackupPC::Lib->new) ); die("BackupPC::Lib->new failed\n") if ( !(my $bpc = BackupPC::Lib->new) );
my %Conf = $bpc->Conf(); my %Conf = $bpc->Conf();
my %opts; my %opts;
if ( !getopts("Lltme:h:n:p:r:s:b:w:", \%opts) || @ARGV < 1 ) { if ( !getopts("Lltme:h:n:p:r:s:b:w:", \%opts) || @ARGV < 1 ) {
print STDERR <<EOF; print STDERR <<EOF;
usage: $0 [options] files/directories... usage: $0 [options] files/directories...
Required options: Required options:
-h host host from which the tar archive is created -h host host from which the tar archive is created
-n dumpNum dump number from which the tar archive is created -n dumpNum dump number from which the tar archive is created
A negative number means relative to the end (eg -1 A negative number means relative to the end (eg -1
skipping to change at line 122 skipping to change at line 123
$Host = $1; $Host = $1;
} else { } else {
print(STDERR "$0: bad host name '$opts{h}'\n"); print(STDERR "$0: bad host name '$opts{h}'\n");
exit(1); exit(1);
} }
if ( $opts{n} !~ /^(-?\d+)$/ ) { if ( $opts{n} !~ /^(-?\d+)$/ ) {
print(STDERR "$0: bad dump number '$opts{n}'\n"); print(STDERR "$0: bad dump number '$opts{n}'\n");
exit(1); exit(1);
} }
if ( !$opts{m} && !defined($bpc->ServerConnect($Conf{ServerHost}, $Conf{ServerPo if ( !$opts{m}
rt})) && !defined($bpc->ServerConnect($Conf{ServerHost}, $Conf{ServerPort}))
&& (my $status = $bpc->ServerMesg("hostMutex $Host 1 BackupPC_tarC && (my $status = $bpc->ServerMesg("hostMutex $Host 1 BackupPC_tarCreate")) =
reate")) =~ /fail/ ) { ~ /fail/ ) {
print(STDERR "$0: $status (use -m option to force running)\n"); print(STDERR "$0: $status (use -m option to force running)\n");
exit(1); exit(1);
} }
my $Num = $opts{n}; my $Num = $opts{n};
my @Backups = $bpc->BackupInfoRead($Host); my @Backups = $bpc->BackupInfoRead($Host);
my $FileCnt = 0; my $FileCnt = 0;
my $ByteCnt = 0; my $ByteCnt = 0;
my $DirCnt = 0; my $DirCnt = 0;
my $SpecialCnt = 0; my $SpecialCnt = 0;
my $ErrorCnt = 0; my $ErrorCnt = 0;
my $i; my $i;
$Num = $Backups[@Backups + $Num]{num} if ( -@Backups <= $Num && $Num < 0 ); $Num = $Backups[@Backups + $Num]{num} if ( -@Backups <= $Num && $Num < 0 );
for ( $i = 0 ; $i < @Backups ; $i++ ) { for ( $i = 0 ; $i < @Backups ; $i++ ) {
last if ( $Backups[$i]{num} == $Num ); last if ( $Backups[$i]{num} == $Num );
} }
if ( $i >= @Backups ) { if ( $i >= @Backups ) {
print(STDERR "$0: bad backup number $Num for host $Host\n"); print(STDERR "$0: bad backup number $Num for host $Host\n");
exit(1); exit(1);
} }
my $Charset = $Backups[$i]{charset}; my $Charset = $Backups[$i]{charset};
$Charset = $opts{e} if ( $opts{e} ne "" ); $Charset = $opts{e} if ( $opts{e} ne "" );
my $PreV4 = ($Backups[$i]{version} eq "" || $Backups[$i]{version} =~ /^[23]\./ my $PreV4 = ($Backups[$i]{version} eq "" || $Backups[$i]{version} =~ /^[23]\./)
) ? 1 : 0; ? 1 : 0;
my $PathRemove = $1 if ( $opts{r} =~ /(.+)/ ); my $PathRemove = $1 if ( $opts{r} =~ /(.+)/ );
my $PathAdd = $1 if ( $opts{p} =~ /(.+)/ ); my $PathAdd = $1 if ( $opts{p} =~ /(.+)/ );
if ( $opts{s} =~ m{(^|/)\.\.(/|$)} ) { if ( $opts{s} =~ m{(^|/)\.\.(/|$)} ) {
print(STDERR "$0: bad share name '$opts{s}'\n"); print(STDERR "$0: bad share name '$opts{s}'\n");
exit(1); exit(1);
} }
our $ShareName = $opts{s}; our $ShareName = $opts{s};
our $view = BackupPC::View->new($bpc, $Host, \@Backups); our $view = BackupPC::View->new($bpc, $Host, \@Backups);
# #
# 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
# from Archive::Tar. Thanks to Calle Dybedahl and Stephen Zander. # from Archive::Tar. Thanks to Calle Dybedahl and Stephen Zander.
# See www.cpan.org. # See www.cpan.org.
# #
# Archive::Tar is Copyright 1997 Calle Dybedahl. All rights reserved. # Archive::Tar is Copyright 1997 Calle Dybedahl. All rights reserved.
# Copyright 1998 Stephen Zander. All rights reserved. # Copyright 1998 Stephen Zander. All rights reserved.
# #
my $tar_pack_header my $tar_pack_header = 'a100 a8 a8 a8 a12 a12 A8 a1 a100 a6 a2 a32 a32 a8 a8 a1
= 'a100 a8 a8 a8 a12 a12 A8 a1 a100 a6 a2 a32 a32 a8 a8 a155 x12'; 55 x12';
my $tar_unpack_header my $tar_unpack_header = 'Z100 A8 A8 A8 a12 A12 A8 A1 Z100 A6 A2 Z32 Z32 A8 A8 A1
= 'Z100 A8 A8 A8 a12 A12 A8 A1 Z100 A6 A2 Z32 Z32 A8 A8 A155 x12'; 55 x12';
my $tar_header_length = 512; my $tar_header_length = 512;
my $BufSize = $opts{w} || 1048576; # 1MB or 2^20 my $BufSize = $opts{w} || 1048576; # 1MB or 2^20
my $WriteBuf = ""; my $WriteBuf = "";
my $WriteBufSz = ($opts{b} || 20) * $tar_header_length; my $WriteBufSz = ($opts{b} || 20) * $tar_header_length;
my(%UidCache, %GidCache); my(%UidCache, %GidCache);
my(%HardLinkExtraFiles, @HardLinks, %Inode2File); my(%HardLinkExtraFiles, @HardLinks, %Inode2File);
# #
# Write out all the requested files/directories # Write out all the requested files/directories
# #
binmode(STDOUT); binmode(STDOUT);
skipping to change at line 219 skipping to change at line 221
# #
my $data = "\0" x ($tar_header_length * 2); my $data = "\0" x ($tar_header_length * 2);
TarWrite($fh, \$data); TarWrite($fh, \$data);
TarWrite($fh, undef); TarWrite($fh, undef);
} }
# #
# print out totals if requested # print out totals if requested
# #
if ( $opts{t} ) { if ( $opts{t} ) {
print STDERR "Done: $FileCnt files, $ByteCnt bytes, $DirCnt dirs,", print STDERR "Done: $FileCnt files, $ByteCnt bytes, $DirCnt dirs,", " $Speci
" $SpecialCnt specials, $ErrorCnt errors\n"; alCnt specials, $ErrorCnt errors\n";
} }
if ( $ErrorCnt && !$FileCnt && !$DirCnt ) { if ( $ErrorCnt && !$FileCnt && !$DirCnt ) {
# #
# Got errors, with no files or directories; exit with non-zero # Got errors, with no files or directories; exit with non-zero
# status # status
# #
exit(1); exit(1);
} }
exit(0); exit(0);
########################################################################### ###########################################################################
# Subroutines # Subroutines
########################################################################### ###########################################################################
sub archiveWrite sub archiveWrite
{ {
my($fh, $dir, $tarPathOverride) = @_; my($fh, $dir, $tarPathOverride) = @_;
if ( $dir =~ m{(^|/)\.\.(/|$)} ) { if ( $dir =~ m{(^|/)\.\.(/|$)} ) {
print(STDERR "$0: bad directory '$dir'\n"); print(STDERR "$0: bad directory '$dir'\n");
$ErrorCnt++; $ErrorCnt++;
return; return;
} }
$dir = "/" if ( $dir eq "." ); $dir = "/" if ( $dir eq "." );
#print(STDERR "calling find with $Num, $ShareName, $dir\n"); #print(STDERR "calling find with $Num, $ShareName, $dir\n");
if ( $view->find($Num, $ShareName, $dir, 0, \&TarWriteFile, if ( $view->find($Num, $ShareName, $dir, 0, \&TarWriteFile, $fh, $tarPathOve
$fh, $tarPathOverride) < 0 ) { rride) < 0 ) {
print(STDERR "$0: bad share or directory '$ShareName/$dir'\n"); print(STDERR "$0: bad share or directory '$ShareName/$dir'\n");
$ErrorCnt++; $ErrorCnt++;
return; return;
} }
} }
# #
# Write out any hardlinks (if any); only for <= 3.x backups. # Write out any hardlinks (if any); only for <= 3.x backups.
# #
sub archiveWriteHardLinks sub archiveWriteHardLinks
{ {
my($fh) = @_; my($fh) = @_;
return if ( !$PreV4 ); return if ( !$PreV4 );
foreach my $hdr ( @HardLinks ) { foreach my $hdr ( @HardLinks ) {
$hdr->{size} = 0; $hdr->{size} = 0;
my $name = $hdr->{linkname}; my $name = $hdr->{linkname};
$name =~ s{^\./}{/}; $name =~ s{^\./}{/};
if ( defined($HardLinkExtraFiles{$name}) ) { if ( defined($HardLinkExtraFiles{$name}) ) {
$hdr->{linkname} = $HardLinkExtraFiles{$name}; $hdr->{linkname} = $HardLinkExtraFiles{$name};
} }
if ( defined($PathRemove) if ( defined($PathRemove)
&& substr($hdr->{linkname}, 0, length($PathRemove)+1) && substr($hdr->{linkname}, 0, length($PathRemove) + 1) eq ".$PathRe
eq ".$PathRemove" ) { move" ) {
substr($hdr->{linkname}, 0, length($PathRemove)+1) = ".$PathAdd"; substr($hdr->{linkname}, 0, length($PathRemove) + 1) = ".$PathAdd";
} }
TarWriteFileInfo($fh, $hdr); TarWriteFileInfo($fh, $hdr);
} }
@HardLinks = (); @HardLinks = ();
%HardLinkExtraFiles = (); %HardLinkExtraFiles = ();
} }
sub UidLookup sub UidLookup
{ {
my($uid) = @_; my($uid) = @_;
$UidCache{$uid} = (getpwuid($uid))[0] if ( !exists($UidCache{$uid}) ); $UidCache{$uid} = (getpwuid($uid))[0] if ( !exists($UidCache{$uid}) );
return $UidCache{$uid}; return $UidCache{$uid};
} }
skipping to change at line 315 skipping to change at line 314
$dataRef = \$data; $dataRef = \$data;
} }
if ( length($WriteBuf) + length($$dataRef) < $WriteBufSz ) { if ( length($WriteBuf) + length($$dataRef) < $WriteBufSz ) {
# #
# just buffer and return # just buffer and return
# #
$WriteBuf .= $$dataRef; $WriteBuf .= $$dataRef;
return; return;
} }
my $done = $WriteBufSz - length($WriteBuf); my $done = $WriteBufSz - length($WriteBuf);
if ( syswrite($fh, $WriteBuf . substr($$dataRef, 0, $done)) if ( syswrite($fh, $WriteBuf . substr($$dataRef, 0, $done)) != $WriteBufSz )
!= $WriteBufSz ) { {
print(STDERR "Unable to write to output file ($!)\n"); print(STDERR "Unable to write to output file ($!)\n");
exit(1); exit(1);
} }
while ( $done + $WriteBufSz <= length($$dataRef) ) { while ( $done + $WriteBufSz <= length($$dataRef) ) {
if ( syswrite($fh, substr($$dataRef, $done, $WriteBufSz)) if ( syswrite($fh, substr($$dataRef, $done, $WriteBufSz)) != $WriteBufSz
!= $WriteBufSz ) { ) {
print(STDERR "Unable to write to output file ($!)\n"); print(STDERR "Unable to write to output file ($!)\n");
exit(1); exit(1);
} }
$done += $WriteBufSz; $done += $WriteBufSz;
} }
$WriteBuf = substr($$dataRef, $done); $WriteBuf = substr($$dataRef, $done);
} }
sub TarWritePad sub TarWritePad
{ {
skipping to change at line 347 skipping to change at line 344
TarWrite($fh, \$data); TarWrite($fh, \$data);
} }
} }
sub TarWriteHeader sub TarWriteHeader
{ {
my($fh, $hdr) = @_; my($fh, $hdr) = @_;
$hdr->{uname} = UidLookup($hdr->{uid}) if ( !defined($hdr->{uname}) ); $hdr->{uname} = UidLookup($hdr->{uid}) if ( !defined($hdr->{uname}) );
$hdr->{gname} = GidLookup($hdr->{gid}) if ( !defined($hdr->{gname}) ); $hdr->{gname} = GidLookup($hdr->{gid}) if ( !defined($hdr->{gname}) );
my $devmajor = defined($hdr->{devmajor}) ? sprintf("%07o", $hdr->{devmajor}) my $devmajor =
: ""; defined($hdr->{devmajor})
my $devminor = defined($hdr->{devminor}) ? sprintf("%07o", $hdr->{devminor}) ? sprintf("%07o", $hdr->{devmajor})
: ""; : "";
my $data = pack($tar_pack_header, my $devminor =
substr($hdr->{name}, 0, 99), defined($hdr->{devminor})
sprintf("%07o", $hdr->{mode}), ? sprintf("%07o", $hdr->{devminor})
sprintf("%07o", $hdr->{uid}), : "";
sprintf("%07o", $hdr->{gid}), my $data = pack(
sprintf("%011o", $hdr->{size}), $tar_pack_header,
sprintf("%011o", $hdr->{mtime}), substr($hdr->{name}, 0, 99),
"", #checksum field - space padded by pack("A8") sprintf("%07o", $hdr->{mode}),
$hdr->{type}, sprintf("%07o", $hdr->{uid}),
substr($hdr->{linkname}, 0, 99), sprintf("%07o", $hdr->{gid}),
$hdr->{magic} || 'ustar ', sprintf("%011o", $hdr->{size}),
$hdr->{version} || ' ', sprintf("%011o", $hdr->{mtime}),
$hdr->{uname}, "", #checksum field - space padded by pack("A8")
$hdr->{gname}, $hdr->{type},
$devmajor, substr($hdr->{linkname}, 0, 99),
$devminor, $hdr->{magic} || 'ustar ',
"" # prefix is empty $hdr->{version} || ' ',
); $hdr->{uname},
$hdr->{gname},
$devmajor,
$devminor,
"" # prefix is empty
);
# #
# now unpack it to see which fields weren't represented correctly, # now unpack it to see which fields weren't represented correctly,
# and if there are any we generate a pax header # and if there are any we generate a pax header
# #
my @paxFlds; my @paxFlds;
my($name, # string my(
$mode, # octal number $name, # string
$uid, # octal number $mode, # octal number
$gid, # octal number $uid, # octal number
$size, # octal number $gid, # octal number
$mtime, # octal number $size, # octal number
$chksum, # octal number $mtime, # octal number
$type, # character $chksum, # octal number
$linkname, # string $type, # character
$magic, # string $linkname, # string
$version, # two bytes $magic, # string
$uname, # string $version, # two bytes
$gname, # string $uname, # string
$devmajor, # octal number $gname, # string
$devminor, # octal number $devmajor, # octal number
$prefix) = unpack($tar_unpack_header, $data); $devminor, # octal number
push(@paxFlds, "path=$hdr->{name}") if ( $name ne $hdr->{name} ); $prefix
) = unpack($tar_unpack_header, $data);
push(@paxFlds, "path=$hdr->{name}") if ( $name ne $hdr->{name} );
push(@paxFlds, "linkpath=$hdr->{linkname}") if ( $linkname ne $hdr->{linknam e} ); push(@paxFlds, "linkpath=$hdr->{linkname}") if ( $linkname ne $hdr->{linknam e} );
push(@paxFlds, "size=$hdr->{size}") if ( oct($size) != $hdr->{size} ); push(@paxFlds, "size=$hdr->{size}") if ( oct($size) != $hdr->{size}
push(@paxFlds, "mtime=$hdr->{mtime}") if ( oct($mtime) != $hdr->{mtime} ); );
push(@paxFlds, "uid=$hdr->{uid}") if ( oct($uid) != $hdr->{uid} ); push(@paxFlds, "mtime=$hdr->{mtime}") if ( oct($mtime) != $hdr->{mtime
push(@paxFlds, "gid=$hdr->{gid}") if ( oct($uid) != $hdr->{gid} ); } );
push(@paxFlds, "uname=$hdr->{uname}") if ( $uname ne $hdr->{uname} ); push(@paxFlds, "uid=$hdr->{uid}") if ( oct($uid) != $hdr->{uid} );
push(@paxFlds, "gname=$hdr->{gname}") if ( $gname ne $hdr->{gname} ); push(@paxFlds, "gid=$hdr->{gid}") if ( oct($uid) != $hdr->{gid} );
push(@paxFlds, "uname=$hdr->{uname}") if ( $uname ne $hdr->{uname} );
push(@paxFlds, "gname=$hdr->{gname}") if ( $gname ne $hdr->{gname} );
if ( ref($hdr->{xattr}) eq 'HASH' ) {
# include xattr and acl using gnu tar naming convention
foreach my $name ( keys(%{$hdr->{xattr}}) ) {
# Skip rsync acls; should try to figure out binary rsync acls, and m
ap
# then to ascii version used by tar...
next if ( $name eq "user.rsync.%aacl" || $name eq "user.rsync.%dacl"
);
if ( $name eq "user.gtar.%aacl" ) {
push(@paxFlds, "SCHILY.acl.access=" . $hdr->{xattr}{$name});
} elsif ( $name eq "user.gtar.%dacl" ) {
push(@paxFlds, "SCHILY.acl.default=" . $hdr->{xattr}{$name});
} else {
push(@paxFlds, "SCHILY.xattr.$name=" . $hdr->{xattr}{$name});
}
}
}
if ( @paxFlds ) { if ( @paxFlds ) {
# #
# Some fields don't match - we need to generate a pax header # Some fields don't match - we need to generate a pax header
# #
my $paxData; my $paxData;
foreach my $fld ( @paxFlds ) { foreach my $fld ( @paxFlds ) {
# the length includes the string length... # the length includes the string length...
my $len = sprintf("%d", length($fld) + 3); # at lea my $len = sprintf("%d", length($fld) + 3); # at l
st 1 digit + space + \n east 1 digit + space + \n
my $len2 = sprintf("%d", length($fld) + length($len) + 2); # + spac my $len2 = sprintf("%d", length($fld) + length($len) + 2); # + sp
e + \n ace + \n
if ( length($len2) != length($len) ) { if ( length($len2) != length($len) ) {
# rollover: adding length requires one more digit in length # rollover: adding length requires one more digit in length
$len2 = sprintf("%d", length($fld) + length($len2) + 2); $len2 = sprintf("%d", length($fld) + length($len2) + 2);
} }
$paxData .= "$len2 " . $fld . "\n"; $paxData .= "$len2 " . $fld . "\n";
} }
my $paxHdrData = pack($tar_pack_header, my $paxHdrData = pack(
substr("./PaxHeaders/$hdr->{name}", 0, 99), $tar_pack_header,
sprintf("%07o", $hdr->{mode}), substr("./PaxHeaders/$hdr->{name}", 0, 99),
sprintf("%07o", $hdr->{uid}), sprintf("%07o", $hdr->{mode}),
sprintf("%07o", $hdr->{gid}), sprintf("%07o", $hdr->{uid}),
sprintf("%011o", length($paxData)), sprintf("%07o", $hdr->{gid}),
sprintf("%011o", $hdr->{mtime}), sprintf("%011o", length($paxData)),
"", #checksum field - space padded by pack("A8") sprintf("%011o", $hdr->{mtime}),
"x", "", #checksum field - space padded by pack("A8")
substr($hdr->{linkname}, 0, 99), "x",
$hdr->{magic} || 'ustar ', substr($hdr->{linkname}, 0, 99),
$hdr->{version} || ' ', $hdr->{magic} || 'ustar ',
$hdr->{uname}, $hdr->{version} || ' ',
$hdr->{gname}, $hdr->{uname},
$devmajor, $hdr->{gname},
$devminor, $devmajor,
"" # prefix is empty $devminor,
); "" # prefix is empty
substr($paxHdrData, 148, 7) = sprintf("%06o\0", unpack("%16C*",$paxHdrDa );
ta)); substr($paxHdrData, 148, 7) = sprintf("%06o\0", unpack("%16C*", $paxHdrD
ata));
TarWrite($fh, \$paxHdrData); TarWrite($fh, \$paxHdrData);
TarWrite($fh, \$paxData); TarWrite($fh, \$paxData);
TarWritePad($fh, length($paxData)); TarWritePad($fh, length($paxData));
} }
substr($data, 148, 7) = sprintf("%06o\0", unpack("%16C*",$data)); substr($data, 148, 7) = sprintf("%06o\0", unpack("%16C*", $data));
TarWrite($fh, \$data); TarWrite($fh, \$data);
} }
sub TarWriteFileInfo sub TarWriteFileInfo
{ {
my($fh, $hdr) = @_; my($fh, $hdr) = @_;
# #
# Convert path names to requested (eg: client) charset # Convert path names to requested (eg: client) charset
# #
skipping to change at line 465 skipping to change at line 490
} elsif ( $opts{L} ) { } elsif ( $opts{L} ) {
my $owner = "$hdr->{uid}/$hdr->{gid}"; my $owner = "$hdr->{uid}/$hdr->{gid}";
my $name = $hdr->{name}; my $name = $hdr->{name};
if ( $hdr->{type} == BPC_FTYPE_SYMLINK ) { if ( $hdr->{type} == BPC_FTYPE_SYMLINK ) {
$name .= " -> $hdr->{linkname}"; $name .= " -> $hdr->{linkname}";
} }
$name =~ s/\n/\\n/g; $name =~ s/\n/\\n/g;
printf("%6o %9s %11.0f %s\n", printf("%6o %9s %11.0f %s\n", $hdr->{mode}, $owner, $hdr->{size}, $name)
$hdr->{mode}, ;
$owner,
$hdr->{size},
$name);
return; return;
} }
TarWriteHeader($fh, $hdr); TarWriteHeader($fh, $hdr);
} }
sub TarWriteFile sub TarWriteFile
{ {
my($hdr, $fh, $tarPathOverride) = @_; my($hdr, $fh, $tarPathOverride) = @_;
my $tarPath = $hdr->{relPath}; my $tarPath = $hdr->{relPath};
$tarPath = $tarPathOverride if ( defined($tarPathOverride) ); $tarPath = $tarPathOverride if ( defined($tarPathOverride) );
$tarPath =~ s{//+}{/}g; $tarPath =~ s{//+}{/}g;
if ( defined($PathRemove) if ( defined($PathRemove)
&& substr($tarPath, 0, length($PathRemove)) eq $PathRemove ) { && substr($tarPath, 0, length($PathRemove)) eq $PathRemove ) {
substr($tarPath, 0, length($PathRemove)) = $PathAdd; substr($tarPath, 0, length($PathRemove)) = $PathAdd;
} }
$tarPath = "./" . $tarPath if ( $tarPath !~ /^\.\// ); $tarPath = "./" . $tarPath if ( $tarPath !~ /^\.\// );
$tarPath =~ s{//+}{/}g; $tarPath =~ s{//+}{/}g;
$hdr->{name} = $tarPath; $hdr->{name} = $tarPath;
if ( !$PreV4 && $hdr->{nlinks} > 0 && defined($hdr->{inode}) ) { if ( !$PreV4 && $hdr->{nlinks} > 0 && defined($hdr->{inode}) ) {
if ( defined($Inode2File{$hdr->{inode}}) ) { if ( defined($Inode2File{$hdr->{inode}}) ) {
# #
# Later inodes: emit a hardlink to an existing file in the archive # Later inodes: emit a hardlink to an existing file in the archive
# TODO: do path rewrite on link path? # TODO: do path rewrite on link path?
# #
$hdr->{size} = 0; $hdr->{size} = 0;
$hdr->{type} = BPC_FTYPE_HARDLINK; $hdr->{type} = BPC_FTYPE_HARDLINK;
$hdr->{linkname} = $Inode2File{$hdr->{inode}}{name}; $hdr->{linkname} = $Inode2File{$hdr->{inode}}{name};
TarWriteFileInfo($fh, $hdr); TarWriteFileInfo($fh, $hdr);
return; return;
} else { } else {
# #
# First time: remember the data for this inode and dump # First time: remember the data for this inode and dump
# the file in its original form. # the file in its original form.
# #
$Inode2File{$hdr->{inode}} = { %$hdr }; $Inode2File{$hdr->{inode}} = {%$hdr};
} }
} }
if ( $hdr->{type} == BPC_FTYPE_DIR ) { if ( $hdr->{type} == BPC_FTYPE_DIR ) {
# #
# Directory: just write the header # Directory: just write the header
# #
$hdr->{name} .= "/" if ( $hdr->{name} !~ m{/$} ); $hdr->{name} .= "/" if ( $hdr->{name} !~ m{/$} );
TarWriteFileInfo($fh, $hdr); TarWriteFileInfo($fh, $hdr);
$DirCnt++; $DirCnt++;
} elsif ( $hdr->{type} == BPC_FTYPE_FILE ) { } elsif ( $hdr->{type} == BPC_FTYPE_FILE ) {
my($data, $size); my($data, $size);
# #
# Regular file: write the header and file # Regular file: write the header and file
# #
my $f = BackupPC::XS::FileZIO::open($hdr->{fullPath}, 0, $hdr->{compress }); my $f = BackupPC::XS::FileZIO::open($hdr->{fullPath}, 0, $hdr->{compress });
if ( !defined($f) ) { if ( !defined($f) ) {
print(STDERR "Unable to open file $hdr->{fullPath} (for $hdr->{name} )\n"); print(STDERR "Unable to open file $hdr->{fullPath} (for $hdr->{name} )\n");
$ErrorCnt++; $ErrorCnt++;
return; return;
} }
TarWriteFileInfo($fh, $hdr); TarWriteFileInfo($fh, $hdr);
if ( $opts{l} || $opts{L} ) { if ( $opts{l} || $opts{L} ) {
$size = $hdr->{size}; $size = $hdr->{size};
} else { } else {
while ( $f->read(\$data, $BufSize) > 0 ) { while ( $f->read(\$data, $BufSize) > 0 ) {
if ( $size + length($data) > $hdr->{size} ) { if ( $size + length($data) > $hdr->{size} ) {
print(STDERR "Error: truncating $hdr->{fullPath} to" print(STDERR "Error: truncating $hdr->{fullPath} to $hdr->{s
. " $hdr->{size} bytes (for $hdr->{name})\n"); ize} bytes (for $hdr->{name})\n");
$data = substr($data, 0, $hdr->{size} - $size); $data = substr($data, 0, $hdr->{size} - $size);
$ErrorCnt++; $ErrorCnt++;
} }
TarWrite($fh, \$data); TarWrite($fh, \$data);
$size += length($data); $size += length($data);
} }
$f->close; $f->close;
if ( $size != $hdr->{size} ) { if ( $size != $hdr->{size} ) {
print(STDERR "Error: padding $hdr->{fullPath} to $hdr->{size}" print(STDERR "Error: padding $hdr->{fullPath} to $hdr->{size}"
. " bytes from $size bytes (for $hdr->{name})\n"); . " bytes from $size bytes (for $hdr->{name})\n");
$ErrorCnt++; $ErrorCnt++;
while ( $size < $hdr->{size} ) { while ( $size < $hdr->{size} ) {
my $len = $hdr->{size} - $size; my $len = $hdr->{size} - $size;
$len = $BufSize if ( $len > $BufSize ); $len = $BufSize if ( $len > $BufSize );
$data = "\0" x $len; $data = "\0" x $len;
TarWrite($fh, \$data); TarWrite($fh, \$data);
$size += $len; $size += $len;
} }
} }
TarWritePad($fh, $size); TarWritePad($fh, $size);
} }
$FileCnt++; $FileCnt++;
$ByteCnt += $size; $ByteCnt += $size;
} elsif ( $PreV4 && $hdr->{type} == BPC_FTYPE_HARDLINK ) { } elsif ( $PreV4 && $hdr->{type} == BPC_FTYPE_HARDLINK ) {
# #
# Note: the meaning of this type changed between BackupPC <= v3.x # Note: the meaning of this type changed between BackupPC <= v3.x
# and >= 4.x. # and >= 4.x.
# #
# In 3.x a hardlink is stored like a symlink: the contents # In 3.x a hardlink is stored like a symlink: the contents
# of the "file" is the path to the linked-to file. # of the "file" is the path to the linked-to file.
# #
# In 4.x+ a hardlink's attributes are stored with the # In 4.x+ a hardlink's attributes are stored with the
# inode, and the real attributes are stored by inode # inode, and the real attributes are stored by inode
skipping to change at line 649 skipping to change at line 669
$ErrorCnt++; $ErrorCnt++;
return; return;
} }
my $data; my $data;
while ( $f->read(\$data, $BufSize) > 0 ) { while ( $f->read(\$data, $BufSize) > 0 ) {
$hdr->{linkname} .= $data; $hdr->{linkname} .= $data;
} }
$f->close; $f->close;
$hdr->{size} = 0; $hdr->{size} = 0;
TarWriteFileInfo($fh, $hdr); TarWriteFileInfo($fh, $hdr);
$SpecialCnt++; $SpecialCnt++;
} elsif ( $hdr->{type} == BPC_FTYPE_CHARDEV } elsif ( $hdr->{type} == BPC_FTYPE_CHARDEV
|| $hdr->{type} == BPC_FTYPE_BLOCKDEV || $hdr->{type} == BPC_FTYPE_BLOCKDEV
|| $hdr->{type} == BPC_FTYPE_FIFO ) { || $hdr->{type} == BPC_FTYPE_FIFO ) {
# #
# Special files: for char and block special we read the # Special files: for char and block special we read the
# major and minor numbers from a plain file. # major and minor numbers from a plain file.
# #
if ( $hdr->{type} != BPC_FTYPE_FIFO ) { if ( $hdr->{type} != BPC_FTYPE_FIFO ) {
my $f = BackupPC::XS::FileZIO::open($hdr->{fullPath}, 0, my $f = BackupPC::XS::FileZIO::open($hdr->{fullPath}, 0, $hdr->{comp
$hdr->{compress}); ress});
my $data; my $data;
if ( !defined($f) || $f->read(\$data, $BufSize) < 0 ) { if ( !defined($f) || $f->read(\$data, $BufSize) < 0 ) {
print(STDERR "Unable to open/read char/block special file" print(STDERR "Unable to open/read char/block special file $hdr->
. " $hdr->{fullPath} (for $hdr->{name})\n"); {fullPath} (for $hdr->{name})\n");
$f->close if ( defined($f) ); $f->close if ( defined($f) );
$ErrorCnt++; $ErrorCnt++;
return; return;
} }
$f->close; $f->close;
if ( $data =~ /(\d+),(\d+)/ ) { if ( $data =~ /(\d+),(\d+)/ ) {
$hdr->{devmajor} = $1; $hdr->{devmajor} = $1;
$hdr->{devminor} = $2; $hdr->{devminor} = $2;
} }
} }
$hdr->{size} = 0; $hdr->{size} = 0;
TarWriteFileInfo($fh, $hdr); TarWriteFileInfo($fh, $hdr);
$SpecialCnt++; $SpecialCnt++;
} elsif ( $hdr->{type} == BPC_FTYPE_SOCKET } elsif ( $hdr->{type} == BPC_FTYPE_SOCKET || $hdr->{type} == BPC_FTYPE_UNKN
|| $hdr->{type} == BPC_FTYPE_UNKNOWN ) { OWN ) {
# #
# ignore these two file types - these are dynamic file types created # ignore these two file types - these are dynamic file types created
# by applications as needed # by applications as needed
# #
} else { } else {
print(STDERR "Got unknown type $hdr->{type} for $hdr->{name}\n"); print(STDERR "Got unknown type $hdr->{type} for $hdr->{name}\n");
$ErrorCnt++; $ErrorCnt++;
} }
} }
 End of changes. 45 change blocks. 
139 lines changed or deleted 171 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)