X-Git-Url: http://git.rot13.org/?p=BackupPC.git;a=blobdiff_plain;f=bin%2FBackupPC_tarExtract;h=55217b997b9d1139c255ab2a3528e57aa3c53d22;hp=c18dc9550e97e1d08c81d62b74ef10637db41b4c;hb=5b3e6091d542c2e7445d5dd511cdf6e20aec8b8d;hpb=1a2fa2c2a1e0db12dc788216d9f3ba73301a131f diff --git a/bin/BackupPC_tarExtract b/bin/BackupPC_tarExtract index c18dc95..55217b9 100755 --- a/bin/BackupPC_tarExtract +++ b/bin/BackupPC_tarExtract @@ -27,7 +27,7 @@ # #======================================================================== # -# Version 2.1.0beta1, released 9 Apr 2004. +# Version 3.0.0alpha, released 23 Jan 2006. # # See http://backuppc.sourceforge.net. # @@ -36,6 +36,7 @@ use strict; no utf8; use lib "/usr/local/BackupPC/lib"; +use Encode qw/from_to/; use BackupPC::Lib; use BackupPC::Attrib qw(:all); use BackupPC::FileZIO; @@ -58,7 +59,7 @@ if ( $ARGV[0] !~ /^([\w\.\s-]+)$/ ) { exit(1); } my $client = $1; -if ( $ARGV[1] !~ /^([\w\s\.\/\$-]+)$/ ) { +if ( $ARGV[1] !~ /^([\w\s.\/$(){}[\]-]+)$/ ) { print("$0: bad share name '$ARGV[1]'\n"); exit(1); } @@ -101,7 +102,7 @@ $SIG{TTIN} = \&catch_signal; # Copyright 1998 Stephen Zander. All rights reserved. # my $tar_unpack_header - = 'Z100 A8 A8 A8 A12 A12 A8 A1 Z100 A6 A2 Z32 Z32 A8 A8 A155 x12'; + = 'Z100 A8 A8 A8 a12 A12 A8 A1 Z100 A6 A2 Z32 Z32 A8 A8 A155 x12'; my $tar_header_length = 512; my $BufSize = 1048576; # 1MB or 2^20 @@ -250,8 +251,19 @@ sub TarReadFileInfo $name, $mode, $size, $type) if ( $Conf{XferLogLevel} >= 3 ); $name = $longName if ( defined($longName) ); $linkname = $longLink if ( defined($longLink) ); + + # + # Map client charset encodings to utf8 + # + # printf("File $name (hex: %s)\n", unpack("H*", $name)); + if ( $Conf{ClientCharset} ne "" ) { + from_to($name, $Conf{ClientCharset}, "utf8"); + from_to($linkname, $Conf{ClientCharset}, "utf8"); + } + # printf("File now $name (hex: %s)\n", unpack("H*", $name)); + $name =~ s{^\./+}{}; - $name =~ s{/+$}{}; + $name =~ s{/+\.?$}{}; $name =~ s{//+}{/}g; return { name => $name, @@ -313,6 +325,7 @@ sub TarReadFile # my($nRead); #print("Reading $f->{name}, $f->{size} bytes, type $f->{type}\n"); + pathCreate($dir, "$OutDir/$ShareName/$f->{mangleName}", $f); my $poolWrite = BackupPC::PoolWrite->new($bpc, "$OutDir/$ShareName/$f->{mangleName}", $f->{size}, $Compress); @@ -350,6 +363,7 @@ sub TarReadFile # a plain file. # $f->{size} = length($f->{linkname}); + pathCreate($dir, "$OutDir/$ShareName/$f->{mangleName}", $f); my $poolWrite = BackupPC::PoolWrite->new($bpc, "$OutDir/$ShareName/$f->{mangleName}", $f->{size}, $Compress); @@ -367,6 +381,7 @@ sub TarReadFile # contents. # $f->{size} = length($f->{linkname}); + pathCreate($dir, "$OutDir/$ShareName/$f->{mangleName}", $f); my $poolWrite = BackupPC::PoolWrite->new($bpc, "$OutDir/$ShareName/$f->{mangleName}", $f->{size}, $Compress); @@ -390,6 +405,7 @@ sub TarReadFile } else { $data = "$f->{devmajor},$f->{devminor}"; } + pathCreate($dir, "$OutDir/$ShareName/$f->{mangleName}", $f); my $poolWrite = BackupPC::PoolWrite->new($bpc, "$OutDir/$ShareName/$f->{mangleName}", length($data), $Compress); @@ -478,6 +494,36 @@ sub logFileAction $name); } +# +# Create the parent directory of $file if necessary +# +sub pathCreate +{ + my($dir, $fullPath, $f) = @_; + + # + # Get parent directory of each of $dir and $fullPath + # + # print("pathCreate: dir = $dir, fullPath = $fullPath\n"); + $dir =~ s{/([^/]*)$}{}; + my $file = $bpc->fileNameUnmangle($1); + $fullPath =~ s{/[^/]*$}{}; + return if ( -d $fullPath || $file eq "" ); + unlink($fullPath) if ( -e $fullPath ); + mkpath($fullPath, 0, 0777); + $Attrib{$dir} = BackupPC::Attrib->new({ compress => $Compress }) + if ( !defined($Attrib{$dir}) ); + # print("pathCreate: adding file = $file to dir = $dir\n"); + $Attrib{$dir}->set($file, { + type => BPC_FTYPE_DIR, + mode => 0755, + uid => $f->{uid}, + gid => $f->{gid}, + size => 0, + mtime => 0, + }); +} + sub catch_signal { my $sigName = shift;