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;
}