From 0ab45ec8f9d13c9527118650c175eaffd3a417d1 Mon Sep 17 00:00:00 2001 From: doogie <> Date: Mon, 1 May 2000 17:56:34 -0800 Subject: [PATCH] [project @ 2000-05-01 18:56:34 by doogie] Changed OpenFile to GetFileName. If the last parameter of 'new' is passed to GetFileName, it'll return the name from the first dir in the array passed to it. Modified OpenRecord to pass an array of ["db", "archive"] to OpenFile. --- Debbugs/DBase.pm | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/Debbugs/DBase.pm b/Debbugs/DBase.pm index 10c4a1d..6927fae 100644 --- a/Debbugs/DBase.pm +++ b/Debbugs/DBase.pm @@ -111,11 +111,12 @@ sub WriteRecord } } -sub OpenFile +sub GetFileName { my ($prePaths, $stub, $postPath, $desc, $new) = (shift, shift, shift, shift, shift); + my $path; foreach my $prePath (@$prePaths) { - my $path = "/" . $prePath . "/" . $stub . $postPath, my $handle = new FileHandle; + $path = "/" . $prePath . "/" . $stub . $postPath; print "V: Opening $desc $stub\n" if $Globals{ 'verbose' }; print "D2: (DBase) trying $path\n" if $Globals{ 'debug' } > 1; if( ! -r $Globals{ "work-dir" } . $path ) { @@ -125,17 +126,28 @@ sub OpenFile next if( !$new =~ "new" ); } } - open( $handle, $Globals{ "work-dir" } . $path ) && return $handle; - if(defined($new) && $new =~ "new") { + if( -r $Globals{ "work-dir" } . $path ) { + return $path; + } + if( ( ! -r $Globals{ "work-dir" } . $path ) && defined($new) && $new =~ "new") { my $dir = dirname( $path ); if ( ! -d $Globals{ "work-dir" } . $dir ) { mkpath($Globals{ "work-dir" } . $dir); } - open( $handle, ">" . $Globals{ "work-dir" } . $path ) && return $handle; + return $path; } } - return; + return undef; +} +sub OpenFile +{ + my ($prePaths, $stub, $postPath, $desc, $new) = (shift, shift, shift, shift, shift); + my $fileName = GetFileName($prePaths, $stub, $postPath, $desc, $new); + my $handle = new FileHandle; + open( $handle, $Globals{ "work-dir" } . $fileName ) && return $handle; + return undef; } + sub OpenRecord { my $record = $_[0]; @@ -159,8 +171,7 @@ sub OpenLogfile my $record = $_[0]; if ( $record ne $OpenedLog ) { - $LogfileHandle = OpenFile("db", $record, ".log", "log"); - seek( $FileHandle, 0, 2 ); + $LogfileHandle = OpenFile(["db", "archive"], $record, ".log", "log"); $OpenedLog = $record; } } -- 2.39.2