From b7f1494f55c75badc352300c6a8e55ef676d225d Mon Sep 17 00:00:00 2001 From: ivan Date: Wed, 26 May 2004 11:11:10 +0000 Subject: [PATCH] use File::Temp for filenames and store the temp files in cache.datasrc instead of /tmp --- FS/FS/cust_bill.pm | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/FS/FS/cust_bill.pm b/FS/FS/cust_bill.pm index 4cfc59d10..13c48d965 100644 --- a/FS/FS/cust_bill.pm +++ b/FS/FS/cust_bill.pm @@ -5,6 +5,7 @@ use vars qw( @ISA $conf $money_char ); use vars qw( $invoice_lines @buf ); #yuck use Date::Format; use Text::Template; +use File::Temp; use FS::UID qw( datasrc ); use FS::Record qw( qsearch qsearchs ); use FS::Misc qw( send_email ); @@ -1108,17 +1109,17 @@ sub print_latex { $var; } - my $dir = '/tmp'; #! /usr/local/etc/freeside/invoices.datasrc/ - my $unique = int(rand(2**31)); #UGH... use File::Temp or something + my $dir = $FS::UID::conf_dir. "cache.". $FS::UID::datasrc; + my $fh = new File::Temp( TEMPLATE => 'invoice.'. $self->invnum. '.XXXXXXXX', + DIR => $dir + SUFFIX => '.tex', + UNLINK => 0, + ) or die "can't open temp file: $!\n"; + print $fh join("\n", @filled_in ), "\n"; + close $fh; - chdir($dir); - my $file = $self->invnum. ".$unique"; - - open(TEX,">$file.tex") or die "can't open $file.tex: $!\n"; - print TEX join("\n", @filled_in ), "\n"; - close TEX; - - return $file; + $fh->filename =~ /^(.*).tex$/ or die "unparsable filename: ". $fh->filename; + return $1; } @@ -1138,6 +1139,9 @@ sub print_ps { my $file = $self->print_latex(@_); + my $dir = $FS::UID::conf_dir. "cache.". $FS::UID::datasrc; + chdir($dir); + system("pslatex $file.tex >/dev/null 2>&1") == 0 or die "pslatex failed: $!"; system("pslatex $file.tex >/dev/null 2>&1") == 0 @@ -1178,6 +1182,9 @@ sub print_pdf { my $file = $self->print_latex(@_); + my $dir = $FS::UID::conf_dir. "cache.". $FS::UID::datasrc; + chdir($dir); + #system('pdflatex', "$file.tex"); #system('pdflatex', "$file.tex"); #! LaTeX Error: Unknown graphics extension: .eps. -- 2.11.0