freeside/FS/FS cust_bill.pm,1.87,1.88

ivan ivan at pouncequick.420.am
Wed May 26 04:11:13 PDT 2004


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory pouncequick:/tmp/cvs-serv28458

Modified Files:
	cust_bill.pm 
Log Message:
use File::Temp for filenames and store the temp files in cache.datasrc instead of /tmp

Index: cust_bill.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/cust_bill.pm,v
retrieving revision 1.87
retrieving revision 1.88
diff -u -d -r1.87 -r1.88
--- cust_bill.pm	26 May 2004 10:36:06 -0000	1.87
+++ cust_bill.pm	26 May 2004 11:11:10 -0000	1.88
@@ -5,6 +5,7 @@
 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 @@
     $var;
   }
 
-  my $dir = '/tmp'; #! /usr/local/etc/freeside/invoices.datasrc/
-  my $unique = int(rand(2**31)); #UGH... use File::Temp or something
-
-  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;
+  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;
 
-  return $file;
+  $fh->filename =~ /^(.*).tex$/ or die "unparsable filename: ". $fh->filename;
+  return $1;
 
 }
 
@@ -1138,6 +1139,9 @@
 
   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
@@ -1177,6 +1181,9 @@
   my $self = shift;
 
   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");




More information about the freeside-commits mailing list