From: doogie <>
Date: Tue, 2 May 2000 01:56:34 +0000 (-0800)
Subject: [project @ 2000-05-01 18:56:34 by doogie]
X-Git-Tag: release/2.6.0~1288
X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=0ab45ec8f9d13c9527118650c175eaffd3a417d1;p=debbugs.git

[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.
---

diff --git a/Debbugs/DBase.pm b/Debbugs/DBase.pm
index 10c4a1d5..6927faee 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;
     }
 }