X-Git-Url: http://git.rot13.org/?p=BackupPC.git;a=blobdiff_plain;f=bin%2FBackupPC_tarExtract;h=af9b298bef4b4bf55bcc2138a34e5f19f0c47a07;hp=32044f6d05bd2fdd5e729fc9f305462153509596;hb=fda25dc88a63ccac1c80efa2e4994bf0725ca9b7;hpb=17dcbbebb871212f90b81bb97f8d1feb528bdc43 diff --git a/bin/BackupPC_tarExtract b/bin/BackupPC_tarExtract index 32044f6..af9b298 100755 --- a/bin/BackupPC_tarExtract +++ b/bin/BackupPC_tarExtract @@ -9,7 +9,7 @@ # Craig Barratt # # COPYRIGHT -# Copyright (C) 2001-2003 Craig Barratt +# Copyright (C) 2001-2007 Craig Barratt # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -27,7 +27,7 @@ # #======================================================================== # -# Version 2.1.0, released 20 Jun 2004. +# Version 3.1.0, released 25 Nov 2007. # # 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,11 +59,11 @@ if ( $ARGV[0] !~ /^([\w\.\s-]+)$/ ) { exit(1); } my $client = $1; -if ( $ARGV[1] !~ /^([\w\s.\/$(){}[\]-]+)$/ ) { +if ( $ARGV[1] =~ m{(^|/)\.\.(/|$)} ) { print("$0: bad share name '$ARGV[1]'\n"); exit(1); } -my $ShareNameUM = $1; +my $ShareNameUM = $1 if ( $ARGV[1] =~ /(.*)/ ); my $ShareName = $bpc->fileNameEltMangle($ShareNameUM); if ( $ARGV[2] !~ /^(\d+)$/ ) { print("$0: bad compress level '$ARGV[2]'\n"); @@ -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,7 +325,7 @@ sub TarReadFile # my($nRead); #print("Reading $f->{name}, $f->{size} bytes, type $f->{type}\n"); - pathCreate($dir, "$OutDir/$ShareName/$f->{mangleName}", $file, $f); + pathCreate($dir, "$OutDir/$ShareName/$f->{mangleName}", $f); my $poolWrite = BackupPC::PoolWrite->new($bpc, "$OutDir/$ShareName/$f->{mangleName}", $f->{size}, $Compress); @@ -351,7 +363,7 @@ sub TarReadFile # a plain file. # $f->{size} = length($f->{linkname}); - pathCreate($dir, "$OutDir/$ShareName/$f->{mangleName}", $file, $f); + pathCreate($dir, "$OutDir/$ShareName/$f->{mangleName}", $f); my $poolWrite = BackupPC::PoolWrite->new($bpc, "$OutDir/$ShareName/$f->{mangleName}", $f->{size}, $Compress); @@ -369,7 +381,7 @@ sub TarReadFile # contents. # $f->{size} = length($f->{linkname}); - pathCreate($dir, "$OutDir/$ShareName/$f->{mangleName}", $file, $f); + pathCreate($dir, "$OutDir/$ShareName/$f->{mangleName}", $f); my $poolWrite = BackupPC::PoolWrite->new($bpc, "$OutDir/$ShareName/$f->{mangleName}", $f->{size}, $Compress); @@ -393,7 +405,7 @@ sub TarReadFile } else { $data = "$f->{devmajor},$f->{devminor}"; } - pathCreate($dir, "$OutDir/$ShareName/$f->{mangleName}", $file, $f); + pathCreate($dir, "$OutDir/$ShareName/$f->{mangleName}", $f); my $poolWrite = BackupPC::PoolWrite->new($bpc, "$OutDir/$ShareName/$f->{mangleName}", length($data), $Compress); @@ -487,17 +499,21 @@ sub logFileAction # sub pathCreate { - my($dir, $fullPath, $file, $f) = @_; + my($dir, $fullPath, $f) = @_; # # Get parent directory of each of $dir and $fullPath # - $dir =~ s{/[^/]*$}{}; + # print("pathCreate: dir = $dir, fullPath = $fullPath\n"); + $dir =~ s{/([^/]*)$}{}; + my $file = $bpc->fileNameUnmangle($1); $fullPath =~ s{/[^/]*$}{}; - return if ( -d $fullPath ); + 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,