Browse Source

- refactoring, extracted __handle_nonportable_local_entry() from __file_find()

master
Andreas Romeyke 1 month ago
parent
commit
9bbadc5fec
1 changed files with 26 additions and 16 deletions
  1. +26
    -16
      lib/Archive/BagIt.pm

+ 26
- 16
lib/Archive/BagIt.pm View File

@ -802,6 +802,30 @@ sub _build_tagmanifest_files {
return \@tagmanifest_files;
}
sub __handle_nonportable_local_entry {
my $self = shift;
my $local_entry = shift;
my $dir = shift;
my $rx_portable = qr/^[a-zA-Z0-9._-]+$/;
my $is_portable = $local_entry =~ m/$rx_portable/;
if (! $is_portable) {
my $local_entry_utf8 = decode("UTF-8", $local_entry);
if ((!$self->has_force_utf8)) {
my $hexdump = "0x" . unpack('H*', $local_entry);
$local_entry =~m/[^a-zA-Z0-9._-]/; # to find PREMATCH, needed nextline
my $prematch_position = $`;
carp "possible non portable pathname detected in $dir,\n",
"got path (hexdump)='$hexdump'(hex),\n",
"decoded path='$local_entry_utf8'\n",
" "." "x length($prematch_position)."^"."------- first non portable char\n";
}
$local_entry = $local_entry_utf8;
}
return $local_entry;
}
sub __file_find { # own implementation, because File::Find has problems with UTF8 encoded Paths under MSWin32
# finds recursively all files in given directory.
# if $excludedir is defined, the content will be excluded
@ -810,7 +834,7 @@ sub __file_find { # own implementation, because File::Find has problems with UTF
$excludedir = File::Spec->rel2abs( $excludedir);
}
my @file_paths;
my $rx_portable = qr/^[a-zA-Z0-9._-]+$/;
my $finder;
$finder = sub {
my ($current_dir) = @_; #absolute path
@ -820,21 +844,7 @@ sub __file_find { # own implementation, because File::Find has problems with UTF
my @paths = File::Spec->no_upwards ( readdir $dh );
closedir $dh;
foreach my $local_entry (@paths) {
my $is_portable = $local_entry =~ m/$rx_portable/;
if (! $is_portable) {
my $local_entry_utf8 = decode("UTF-8", $local_entry);
if ((!$self->has_force_utf8)) {
my $hexdump = "0x" . unpack('H*', $local_entry);
$local_entry =~m/[^a-zA-Z0-9._-]/; # to find PREMATCH, needed nextline
carp "possible non portable pathname detected in $dir,\n",
"got path (hexdump)='$hexdump'(hex),\n",
"decoded path='$local_entry_utf8'\n",
" "." "x length($`)."^"."------- first non portable char\n"; #$` eq $PREMATCH
}
$local_entry = $local_entry_utf8;
}
my $path_entry = File::Spec->catdir($current_dir, $local_entry);
my $path_entry = File::Spec->catdir($current_dir, $self->__handle_nonportable_local_entry($local_entry, $dir));
if (-f $path_entry) {
push @tmp_file_paths, $path_entry;
} elsif (-d $path_entry) {


Loading…
Cancel
Save