From 94ad4ae03583feb4a65dc27377b465c0e2c2535c Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Tue, 10 Mar 2015 17:42:48 +0100 Subject: [PATCH] CreatePDF-Helfer: Dateinamen fixen MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Die Vorlagen-Parser-Module SL::Template::* erwarten, dass $form->{tmpdir} den zu parsenden Dateinamen enthält. Sie entfernen dann das Präfix $self->{userspath} von $form->{tmpdir}, wodurch nur noch der Dateiname bleibt. Der Name der finalen Ausgabedatei wird ebenfalls über $form->{tmpdir} zurückgegeben – ohne jegliche Pfadangabe. Allerdings ist das von Modul zu Modul unterschiedlich. Manche geben den vollen Namen, manche nur den Dateinamen (der dann relativ zu $self->{userspath} ist) zurück. --- SL/Helper/CreatePDF.pm | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/SL/Helper/CreatePDF.pm b/SL/Helper/CreatePDF.pm index 6308e3608..1460ecffd 100644 --- a/SL/Helper/CreatePDF.pm +++ b/SL/Helper/CreatePDF.pm @@ -6,6 +6,7 @@ use Carp; use Cwd; use English qw(-no_match_vars); use File::Slurp (); +use File::Spec (); use File::Temp (); use List::MoreUtils qw(uniq); use List::Util qw(first); @@ -47,12 +48,13 @@ sub create_parsed_file { $form->{templates} = $::instance_conf->get_templates; $form->{IN} = $params{template}; $form->{tmpdir} = $form->{cwd} . '/' . $userspath; + my $tmpdir = $form->{tmpdir}; my ($suffix) = $params{template} =~ m{\.(.+)}; my ($temp_fh, $tmpfile) = File::Temp::tempfile( 'kivitendo-printXXXXXX', SUFFIX => ".${suffix}", - DIR => $userspath, + DIR => $form->{tmpdir}, UNLINK => ($::lx_office_conf{debug} && $::lx_office_conf{debug}->{keep_temp_files})? 0 : 1, ); @@ -63,7 +65,7 @@ sub create_parsed_file { source => $form->{IN}, form => $form, myconfig => \%::myconfig, - userspath => $userspath, + userspath => $tmpdir, ); my $result = $parser->parse($temp_fh); @@ -76,16 +78,22 @@ sub create_parsed_file { die $parser->get_error; } + # SL::Template:** modify $form->{tmpfile} by removing its + # $form->{userspath} prefix. They also store the final file's actual + # file name in $form->{tmpfile} – but it is now relative to + # $form->{userspath}. Other modules return the full file name… + my ($volume, $directory, $file_name) = File::Spec->splitpath($form->{tmpfile}); + my $full_file_name = File::Spec->catfile($tmpdir, $file_name); if (($params{return} || 'content') eq 'file_name') { - my $new_name = $userspath . '/keep-' . $tmpfile; - rename $tmpfile, $new_name; + my $new_name = File::Spec->catfile($tmpdir, 'keep-' . $form->{tmpfile}); + rename $full_file_name, $new_name; $form->cleanup; return $new_name; } - my $content = File::Slurp::read_file($tmpfile); + my $content = File::Slurp::read_file($full_file_name); $form->cleanup; -- 2.20.1