[interchange] Prevent [import] from using a temporary file for inline data.
Stefan Hornburg <[email protected]>
| Newsgroups | gmane.comp.web.interchange.cvs |
|---|---|
| Message-ID | <[email protected]> |
commit fe4fa39a7cf19031b5e463d55c978b6981a9ae39 Author: Rok Ružič <[email protected]> Date: Tue Apr 20 10:07:54 2010 +0200 Prevent [import] from using a temporary file for inline data. This also implicitly fixes the UTF-8 problems reported in #339. lib/Vend/Data.pm | 7 ++++--- lib/Vend/Table/Common.pm | 24 ++++++++++++++++++------ 2 files changed, 22 insertions(+), 9 deletions(-) --- diff --git a/lib/Vend/Data.pm b/lib/Vend/Data.pm index ab64cad..9922ca3 100644 --- a/lib/Vend/Data.pm +++ b/lib/Vend/Data.pm @@ -306,8 +306,9 @@ sub import_text { or die ::errmsg("No absolute file names like '%s' allowed.\n", $fn); } else { - Vend::Util::writefile($fn, $text) - or die ("Cannot write temporary import file $fn: $!\n"); + # data is already in memory, do not create a temporary file + $options->{scalar_ref} = 1; + $fn = \$text; } my $save = $/; @@ -319,7 +320,7 @@ sub import_text { Vend::Table::Common::import_ascii_delimited($fn, $options); $/ = $save; - unlink $fn unless $options->{'file'}; + unlink $fn unless $options->{'file'} or $options->{scalar_ref}; return 1; } diff --git a/lib/Vend/Table/Common.pm b/lib/Vend/Table/Common.pm index a5b04e2..f321d66 100644 --- a/lib/Vend/Table/Common.pm +++ b/lib/Vend/Table/Common.pm @@ -1046,7 +1046,9 @@ sub import_ascii_delimited { my $realfile; if($options->{PRELOAD}) { - if (-f $infile and $options->{PRELOAD_EMPTY_ONLY}) { + # do not preload if $infile is a scalar reference + if ($options->{scalar_ref} or + (-f $infile and $options->{PRELOAD_EMPTY_ONLY})) { # Do nothing, no preload } else { @@ -1058,10 +1060,18 @@ sub import_ascii_delimited { } if(! defined $realfile) { - open(IN, "+<$infile") - or die errmsg("%s %s: %s\n", errmsg("open read/write"), $infile, $!); - lockfile(\*IN, 1, 1) - or die errmsg("%s %s: %s\n", errmsg("lock"), $infile, $!); + if($options->{scalar_ref}){ + open(IN, '+<', $infile) + or die errmsg("%s %s: %s\n", errmsg("open scalar reference"), *$infile, $!); + # locking of scalar reference filehandles in unsupported + } + else{ + open(IN, "+<$infile") + or die errmsg("%s %s: %s\n", errmsg("open read/write"), $infile, $!); + lockfile(\*IN, 1, 1) + or die errmsg("%s %s: %s\n", errmsg("lock"), $infile, $!); + } + } else { open(IN, "<$infile") @@ -1474,7 +1484,9 @@ EndOfRoutine } delete $out->[$CONFIG]{Clean_start}; delete $out->[$CONFIG]{_Dirty}; - unlockfile(\*IN) or die "unlock\n"; + unless($options->{scalar_ref}){ + unlockfile(\*IN) or die "unlock\n"; + } close(IN); my $dot = $out->[$CONFIG]{HIDE_AUTO_FILES} ? '.' : ''; if($numeric_guess) { _______________________________________________ interchange-cvs mailing list [email protected] http://www.icdevgroup.org/mailman/listinfo/interchange-cvs