# Craig Barratt <cbarratt@users.sourceforge.net>
#
# COPYRIGHT
-# Copyright (C) 2002-2003 Craig Barratt
+# Copyright (C) 2002-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 3.0.0, released 28 Jan 2007.
+# Version 3.2.0, released 31 Jul 2010.
#
# See http://backuppc.sourceforge.net.
#
use BackupPC::Attrib qw(:all);
use BackupPC::FileZIO;
use Data::Dumper;
+use Encode qw/from_to/;
sub new
{
# are added to the returned hash.
# See BackupPC::Lib::dirRead().
}, $class;
- for ( my $i = 0 ; $i < @{$m->{backups}} ; $i++ ) {
- next if ( defined($m->{backups}[$i]{level}) );
- $m->{backups}[$i]{level} = $m->{backups}[$i]{type} eq "incr" ? 1 : 0;
- }
$m->{topDir} = $m->{bpc}->TopDir();
return $m;
}
push(@{$m->{mergeNums}}, $backupNum);
my $mangle = $m->{backups}[$i]{mangle};
my $compress = $m->{backups}[$i]{compress};
- my $path = "$m->{topDir}/pc/$m->{host}/$backupNum/";
+ my $path = "$m->{topDir}/pc/$m->{host}/$backupNum/";
+ my $legacyCharset = $m->{backups}[$i]{version} < 3.0;
my $sharePathM;
if ( $mangle ) {
$sharePathM = $m->{bpc}->fileNameEltMangle($share)
$sharePathM = $share . $dir;
}
$path .= $sharePathM;
- #print(STDERR "Opening $path (share=$share)\n");
+ #print(STDERR "Opening $path (share=$share, mangle=$mangle)\n");
+
+ my $dirOpts = { %{$m->{dirOpts} || {} } };
+ my $attribOpts = { compress => $compress };
+ if ( $legacyCharset ) {
+ $dirOpts->{charsetLegacy}
+ = $attribOpts->{charsetLegacy}
+ = $m->{bpc}->{Conf}{ClientCharsetLegacy} || "iso-8859-1";
+ }
- my $dirInfo = $m->{bpc}->dirRead($path, $m->{dirOpts});
+ my $dirInfo = $m->{bpc}->dirRead($path, $dirOpts);
if ( !defined($dirInfo) ) {
if ( $i == $m->{idx} ) {
#
}
my $attr;
if ( $mangle ) {
- $attr = BackupPC::Attrib->new({ compress => $compress });
- if ( -f $attr->fileName($path) && !$attr->read($path) ) {
- $m->{error} = "Can't read attribute file in $path";
+ $attr = BackupPC::Attrib->new($attribOpts);
+ if ( !$attr->read($path) ) {
+ $m->{error} = "Can't read attribute file in $path: " . $attr->errStr();
$attr = undef;
}
}
|| $file eq "."
|| $file eq "backupInfo"
|| $mangle && $file eq "attrib" );
+
if ( defined($attr) && defined(my $a = $attr->get($fileUM)) ) {
$m->{files}{$fileUM} = $a;
#
# is on. We have to stat the file and read compressed files
# to determine their size.
#
- my @s = stat("$path/$file");
+ my $realPath = "$path/$file";
+
+ from_to($realPath, "utf8", $attribOpts->{charsetLegacy})
+ if ( $attribOpts->{charsetLegacy} ne "" );
+
+ my @s = stat($realPath);
next if ( $i < $m->{idx} && -d _ );
$m->{files}{$fileUM} = {
type => -d _ ? BPC_FTYPE_DIR : BPC_FTYPE_FILE,
#
# Compute the correct size by reading the whole file
#
- my $f = BackupPC::FileZIO->open("$path/$file",
+ my $f = BackupPC::FileZIO->open($realPath,
0, $compress);
if ( !defined($f) ) {
- $m->{error} = "Can't open $path/$file";
+ $m->{error} = "Can't open $realPath";
} else {
my($data, $size);
while ( $f->read(\$data, 65636 * 8) > 0 ) {
($m->{files}{$fileUM}{sharePathM} = "$sharePathM/$file")
=~ s{//+}{/}g;
($m->{files}{$fileUM}{fullPath} = "$path/$file") =~ s{//+}{/}g;
+ from_to($m->{files}{$fileUM}{fullPath}, "utf8", $attribOpts->{charsetLegacy})
+ if ( $attribOpts->{charsetLegacy} ne "" );
$m->{files}{$fileUM}{backupNum} = $backupNum;
$m->{files}{$fileUM}{compress} = $compress;
$m->{files}{$fileUM}{nlink} = $entry->{nlink}
$m->{files}{$fileUM}{relPath} = "$dir/$fileUM";
$m->{files}{$fileUM}{sharePathM} = "$sharePathM/$file";
$m->{files}{$fileUM}{fullPath} = "$path/$file";
+ from_to($m->{files}{$fileUM}{fullPath}, "utf8", $attribOpts->{charsetLegacy})
+ if ( $attribOpts->{charsetLegacy} ne "" );
$m->{files}{$fileUM}{backupNum} = $backupNum;
$m->{files}{$fileUM}{compress} = $compress;
$m->{files}{$fileUM}{nlink} = 0;
my $mangle = $m->{backups}[$i]{mangle};
my $compress = $m->{backups}[$i]{compress};
my $path = "$m->{topDir}/pc/$m->{host}/$backupNum/";
+ my $legacyCharset = $m->{backups}[$i]{version} < 3.0;
my $sharePathM;
if ( $mangle ) {
$sharePathM = $m->{bpc}->fileNameEltMangle($share)
$path .= $sharePathM;
#print(STDERR "Opening $path (share=$share)\n");
- my $dirInfo = $m->{bpc}->dirRead($path, $m->{dirOpts});
+ my $dirOpts = { %{$m->{dirOpts} || {} } };
+ my $attribOpts = { compress => $compress };
+ if ( $legacyCharset ) {
+ $dirOpts->{charsetLegacy}
+ = $attribOpts->{charsetLegacy}
+ = $m->{bpc}->{Conf}{ClientCharsetLegacy} || "iso-8859-1";
+ }
+
+ my $dirInfo = $m->{bpc}->dirRead($path, $dirOpts);
if ( !defined($dirInfo) ) {
#
# Oops, directory doesn't exist.
}
my $attr;
if ( $mangle ) {
- $attr = BackupPC::Attrib->new({ compress => $compress });
- if ( -f $attr->fileName($path) && !$attr->read($path) ) {
+ $attr = BackupPC::Attrib->new($attribOpts);
+ if ( !$attr->read($path) ) {
$m->{error} = "Can't read attribute file in $path";
$attr = undef;
}
|| $file eq "."
|| $mangle && $file eq "attrib"
|| defined($files->{$fileUM}[$i]) );
- my @s = stat("$path/$file");
+
+ my $realPath = "$path/$file";
+ from_to($realPath, "utf8", $attribOpts->{charsetLegacy})
+ if ( $attribOpts->{charsetLegacy} ne "" );
+ my @s = stat($realPath);
if ( defined($attr) && defined(my $a = $attr->get($fileUM)) ) {
$files->{$fileUM}[$i] = $a;
$attr->set($fileUM, undef);
#
# Compute the correct size by reading the whole file
#
- my $f = BackupPC::FileZIO->open("$path/$file",
+ my $f = BackupPC::FileZIO->open("$realPath",
0, $compress);
if ( !defined($f) ) {
$m->{error} = "Can't open $path/$file";