# Craig Barratt <cbarratt@users.sourceforge.net>
#
# COPYRIGHT
-# Copyright (C) 2001 Craig Barratt
+# Copyright (C) 2001-2009 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
#
#========================================================================
#
-# Version 2.0.0beta2, released 13 Apr 2003.
+# Version 3.2.0, released 31 Jul 2010.
#
# See http://backuppc.sourceforge.net.
#
use Carp;
use File::Path;
use BackupPC::FileZIO;
+use Encode qw/from_to/;
require Exporter;
use vars qw( @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS );
my($data);
$file = $a->fileName($dir, $file);
+ from_to($file, "utf8", $a->{charsetLegacy})
+ if ( $a->{charsetLegacy} ne "" );
my $fd = BackupPC::FileZIO->open($file, 0, $a->{compress});
if ( !$fd ) {
$a->{_errStr} = "Can't open $file";
}
(my $magic, $data) = unpack("N a*", $data);
if ( $magic != $a->{type} ) {
- $a->{_errStr} = sprintf("Wrong magic number in $file"
+ $a->{_errStr} = sprintf("Wrong magic number in %s"
. " (got 0x%x, expected 0x%x)",
- $magic, $a->{type});
+ $file, $magic, $a->{type});
$fd->close;
return;
}
}
}
(my $fileName, $data) = unpack("a$len a*", $data);
+
+ from_to($fileName, $a->{charsetLegacy}, "utf8")
+ if ( $a->{charsetLegacy} ne "" );
my $nFldsW = @FldsUnixW;
my $nFldsN = @FldsUnixN;
if ( length($data) < 5 * $nFldsW + 4 * $nFldsN ) {
$fd->read(\$newData, 65536);
$data .= $newData;
}
- (
- @{$a->{files}{$fileName}}{@FldsUnixW},
- @{$a->{files}{$fileName}}{@FldsUnixN},
- $data
- ) = unpack("w$nFldsW N$nFldsN a*", $data);
+ eval {
+ (
+ @{$a->{files}{$fileName}}{@FldsUnixW},
+ @{$a->{files}{$fileName}}{@FldsUnixN},
+ $data
+ ) = unpack("w$nFldsW N$nFldsN a*", $data);
+ };
+ if ( $@ ) {
+ $a->{_errStr} = "unpack: Can't read attributes for $fileName from $file ($@)";
+ $fd->close;
+ return;
+ }
if ( $a->{files}{$fileName}{$FldsUnixN[-1]} eq "" ) {
$a->{_errStr} = "Can't read attributes for $fileName"
. " from $file";
my($data) = $a->writeData;
$file = $a->fileName($dir, $file);
- mkpath($dir, 0, 0777) if ( !-d $dir );
+ if ( !-d $dir ) {
+ eval { mkpath($dir, 0, 0777) };
+ if ( $@ ) {
+ $a->{_errStr} = "Can't create directory $dir";
+ return;
+ }
+ }
my $fd = BackupPC::FileZIO->open($file, 1, $a->{compress});
if ( !$fd ) {
$a->{_errStr} = "Can't open/write to $file";