Subject: | Problems with UTF8 in folder- and file-names |
Test scripts attached:
$ perl test.pl
script wanted to create existing folder tmp!
$ rm -rf tmp
$ perl test.pl
1 tmp/Fügen/00-a.txt
1 tmp/Fügen/01-e.txt
2 tmp/Fügen/02-é.txt
2 tmp/Fügen/03-z.txt
1 tmp/Fügen/04-ż.txt
Wide character in IO::Compress::Gzip::write: at /pro/lib/perl5/5.14.1/
Compress/Zlib.pm line 205.
The documentation mentions UTF-8 in *data*, but not in file or folder
names, and the script adds files as-is.
Subject: | test.pl |
#!/pro/bin/perl
use strict;
use warnings;
-d "tmp" and die "script wanted to create existing folder tmp!\n";
use Encode qw( decode encode );
use File::Find;
use Archive::Tar;
binmode STDOUT, ":encoding(utf-8)";
binmode STDERR, ":encoding(utf-8)";
my $dn = encode ("utf8", "tmp/F\x{00fc}gen");
mkdir $_, 0777 for "tmp", $dn;
for ( [ "00-a.txt", "a" ],
[ "01-e.txt", "e" ],
[ "02-\x{00e9}.txt", "\x{00e9}" ],
[ "03-z.txt", "\x{017c}" ],
[ "04-\x{017c}.txt", "z" ],
) {
my ($fn, $data) = @$_;
$fn = encode ("utf8", $fn);
open my $fh, ">:encoding(utf-8)",
"$dn/$fn" or die "Cannot opn $fn: $!\n";
print $fh $data;
close $fh;
}
my @files;
find (sub {
-f and push @files, decode ("utf8", $File::Find::name);
}, "tmp");
my $tar = Archive::Tar->new ();
foreach my $f (sort @files) {
printf "%4d %s\n", -s $f, $f;
$tar->add_files ($f);
}
$tar->write ("test.tgz", 9);