Changeset 17963
- Timestamp:
- Jun 6, 2008, 1:46:57 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/PS-IPP-Config/lib/PS/IPP/Config.pm (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/PS-IPP-Config/lib/PS/IPP/Config.pm
r17829 r17963 1 1 # Copyright (c) 2006 Paul Price, Joshua Hoblitt 2 2 # 3 # $Id: Config.pm,v 1.8 7 2008-05-28 20:28:46 jhoblittExp $3 # $Id: Config.pm,v 1.88 2008-06-06 23:46:57 bills Exp $ 4 4 5 5 package PS::IPP::Config; … … 11 11 12 12 use Carp qw( carp ); 13 use File::Basename qw( basename dirname ); 13 14 # use File::Spec 3.19; 14 15 use File::Spec 0.87; 16 use File::Temp qw( tempfile ); 17 15 18 use PS::IPP::Metadata::Config 1.00; 16 19 use Getopt::Long 2.33 qw( GetOptions :config gnu_getopt pass_through ); # Set pass_through so we don't kill @ARGV … … 510 513 exit($PS_EXIT_DATA_ERROR)); 511 514 return 1; 515 } 516 517 # create a (possibly) temporary file with name (basename $_[0]) 518 # if $preserve create a file named basename$_[0] in current directory 519 520 sub create_temp_file 521 { 522 my $self = shift; 523 my $pathname = shift; 524 my $preserve = shift; 525 526 die "pathname must be defined" unless ($pathname); 527 528 my $fileRef; 529 my $fileName; 530 531 # we only use in the last part of the path 532 my $base = basename($pathname); 533 534 if ($preserve) { 535 # we want to keep the file just create it in the current directory 536 $fileName = "./$base"; 537 open $fileRef, ">$fileName" or die "can't open $fileName for output"; 538 } else { 539 # we really want a tempfile, so put it in /tmp 540 ($fileRef, $fileName) = tempfile("/tmp/$base.XXXX", UNLINK => 1); 541 } 542 543 return ($fileRef, $fileName); 544 } 545 546 # redirect stderr and stdout streams to a file 547 sub redirect_output 548 { 549 my $self = shift; 550 my $name = shift; 551 552 die "need name" unless $name; 553 554 my $filename = $self->file_resolve($name, "--touch"); 555 556 die "cannot resolve $name" unless $filename; 557 558 # We need to make sure the directory for this file exists 559 # If it's a nebulous file it has already been created so the directory must exist 560 # we won't run mkdir there 561 my $dir = dirname($filename); 562 if (! -d $dir) { 563 my $rc = system "mkdir -p $dir"; 564 die "failed to create directory for $filename" unless (!$rc); 565 } 566 567 open STDOUT, ">>$filename" or die "failed to redirect stdout to $filename"; 568 open STDERR, ">>$filename" or die "failed to redirect stderr to $filename"; 512 569 } 513 570
Note:
See TracChangeset
for help on using the changeset viewer.
