X-Git-Url: http://www.git.stargrave.org/?a=blobdiff_plain;f=lib%2FPublicInbox%2FTestCommon.pm;h=cd73b5b691ea85654f6554f0d5e37689a1c0a742;hb=6e472b959b6e4391ca902ad23d73e90c220f2da5;hp=ac14d27bc87b9ba406edd22eb475f704a8dabc39;hpb=5d8dbb4aca5afcc6b98a4d951f03003fb7eaf356;p=public-inbox.git diff --git a/lib/PublicInbox/TestCommon.pm b/lib/PublicInbox/TestCommon.pm index ac14d27b..cd73b5b6 100644 --- a/lib/PublicInbox/TestCommon.pm +++ b/lib/PublicInbox/TestCommon.pm @@ -11,27 +11,10 @@ use IO::Socket::INET; our @EXPORT = qw(tmpdir tcp_server tcp_connect require_git require_mods run_script start_script key2sub xsys xqx mime_load); -sub mime_load ($;&) { - my ($path, $cb) = @_; - if (open(my $fh, '<', $path)) { - PublicInbox::MIME->new(\(do { local $/; <$fh> })); - } elsif ($cb) { - require File::Temp; - - my $mime = $cb->(); - my ($dir) = ($path =~ m!(.+)/(?:[^/]+)\z!); - -d $dir or die "BUG: dir=$dir is not the dir of $path"; - my $fh = File::Temp->new(DIR => $dir); - $fh->autoflush(1); - print $fh $mime->as_string or die "print: $!"; - my $fn = $fh->filename; - rename($fn, $path) or die "link $fn => $path: $!"; - $fh->unlink_on_destroy(0); - pop @_; # retry via tail recursion - goto &mime_load; - } else { - die "open $path: $!"; - } +sub mime_load ($) { + my ($path) = @_; + open(my $fh, '<', $path) or die "open $path: $!"; + PublicInbox::MIME->new(\(do { local $/; <$fh> })); } sub tmpdir (;$) {