Perl on MacOSX の話題。OSX では通常の方法では libapreq (Apache::Request) がコンパイルできないので、CGI / CGI::Upload を使ったラッパープログラムを適当に書いてお茶を濁している。
ところが、File::Basename の挙動がどうもおかしいので調べてみると、CGI::Upload 内でブラウザの判定を少々いいかげんに行っているためだとわかった(OSX を考慮していない)。さらに $Fileparse_fstype を write back していないために間違った OS としてパスを処理してしまう。
いちおうメンテナには連絡した(返答があった)が、数年ほど放置されているバグのようなので直してもらえるかはかなり微妙。
OSX なひとは次のようなパッチを /System/Library/Perl/5.8.6/File/Basename.pm にあてておくと少し幸せになれるかもしれない(あまり厳密にはテストしていません)。
--- Upload.pm.orig 2007-07-02 15:47:33.000000000 +0900
+++ Upload.pm 2007-07-02 15:50:05.000000000 +0900
@@ -43,7 +43,7 @@
# returns a hash of all information determined about the uploaded file
# which is be cached for subsequent requests.
- $self->{'_CACHE'}->{$param} = $self->_handle_file( $param ) unless exists $self->{'_CACHE'};
+ $self->{'_CACHE'}->{$param} = $self->_handle_file( $param ) unless exists $self->{'_CACHE'}->{$param};
# Return the requested property of the uploaded file
@@ -64,9 +64,10 @@
my $client_os = $^O;
my $browser = HTTP::BrowserDetect->new;
$client_os = 'MSWin32' if $browser->windows;
- $client_os = 'MacOS' if $browser->mac;
- fileparse_set_fstype($client_os);
+ $client_os = $browser->macosx ? 'Unix' : 'MacOS' if $browser->mac;
+ my $fstype_old = fileparse_set_fstype($client_os);
my @file = fileparse( $cgi->param( $param ), '¥.[^.]*' );
+ fileparse_set_fstype($fstype_old);
# Return an undefined value if the file name cannot be parsed from the
# file field form parameter.
コメント