Skip Menu |

This queue is for tickets about the Archive-Tar CPAN distribution.

Report information
The Basics
Id: 54850
Status: resolved
Worked: 30 min
Priority: 0/
Queue: Archive-Tar

People
Owner: BINGOS [...] cpan.org
Requestors: dk.cpan [...] quietmoon.com
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 1.58
Fixed in: (no value)



Subject: write() closes provided filehandle
When you pass a filehandle to Archive::Tar::write() or create_archive(), it closes the filehandle after writing to it. I think it makes more sense not to close a handle that A::T didn't open, since the application may need to write additional data to it. (Consider sockets, package files containing encapsulated tar archives, etc.) Example: $ perl -e 'use Archive::Tar; open(PKG, ">mypkg") or die "open: $!"; my $tar = Archive::Tar->new; $tar->add_data("foo.txt","hello"); $tar->write(\*PKG); print PKG "more data" or die "print: $!";' print: Bad file descriptor at -e line 1. The attached patch makes write() and create_archive() close only handles they opened.
Subject: write-close-patch.txt
--- lib/Archive/Tar.pm.orig 2010-02-17 16:39:08.000000000 -0500 +++ lib/Archive/Tar.pm 2010-02-21 15:26:35.000000000 -0500 @@ -1244,8 +1244,8 @@ : $HAS_PERLIO ? $dummy : do { seek $handle, 0, 0; local $/; <$handle> }; - ### make sure to close the handle; - close $handle; + ### make sure to close the handle if we created it + close $handle unless ref($file); return $rv; }
According to my records this got included in 1.60 release, but I forgot to close the ticket. ==== * important changes in version 1.60 23/04/2010 - Apply patch from Darrell K. [RT #54850] that makes write() and create_archive() close only handles they opened. When you pass a filehandle to Archive::Tar::write() or create_archive(), it closes the filehandle after writing to it. I think it makes more sense not to close a handle that A::T didn't open, since the application may need to write additional data to it. (Consider sockets, package files containing encapsulated tar archives, etc.) Example: $ perl -e 'use Archive::Tar; open(PKG, ">mypkg") or die "open: $!"; my $tar = Archive::Tar->new; $tar->add_data("foo.txt","hello"); $tar->write(\*PKG); print PKG "more data" or die "print: $!";' print: Bad file descriptor at -e line 1. ==== Many thanks for the patch.