On Sun, May 08, 2016 at 07:34:22PM +0200, Marc Espie wrote: > On Sun, May 08, 2016 at 07:22:07PM +0200, Marc Espie wrote: > > > - my $tmp = OpenBSD::Temp::permanent_file($output, "pkg"); > > > + my ($fh2, $tmp) = OpenBSD::Temp::permanent_file($output, "pkg"); > > So with that code, you're going to have two handles writing into the same > file... bleah.
Well, to handles open at the same time, the second write doesn't happen until after the first has finished and is closed. There could be problems I'm not remembering. My coffee doesn't seem to be strong enough today. > I'd prefer just > > my (undef, $tmp) = OpenBSD::Temp::permanent_file($output, "pkg"); OK afresh1@ I also don't mind this idiom, I think we lose some of race safety you get from mkstemp (I don't think it matters here though) and since we re-open by filename to create_archive there's not a lot of benefit. Unfortunately OpenBSD::MkTemp isn't an IO::Handle subclass so we don't get $fh2->write and other convenience methods, so we can't pass the filehandle to $state->create_archive the way I would have done otherwise. > not quite sure I'm not using a similar idiom in other ports tools. As far as I can tell, grep says this was the only place in src/usr.sbin/pkg_add and ports/infrastructure. I could be missing something.