diff src/content.c @ 219:d9f314014f7a noffle

[svn] * src/content.c: Remove spurious temporary files and add a closedir() to terminate opendir()/readdir() sequence properly. * Updated NEWS ready for 1.1.1.
author bears
date Thu, 29 Nov 2001 22:16:06 +0000
parents 411b6ab1acb7
children ffb1848a39db
line wrap: on
line diff
--- a/src/content.c	Thu Nov 22 22:48:07 2001 +0000
+++ b/src/content.c	Thu Nov 29 22:16:06 2001 +0000
@@ -1,7 +1,7 @@
 /*
   content.c
 
-  $Id: content.c 337 2001-11-22 22:48:07Z bears $
+  $Id: content.c 338 2001-11-29 22:16:06Z bears $
 */
 
 #if HAVE_CONFIG_H
@@ -322,6 +322,7 @@
     ASSERT( cont.dir );
     if ( ! ( d = readdir( cont.dir ) ) )
     {
+	closedir( cont.dir );
         cont.dir = NULL;
         return FALSE;
     }
@@ -329,15 +330,12 @@
         return FALSE;
     if ( d->d_name[0] == '.' )
     {
+	Str tmpfname;
+
 	/*
 	 * If it is '.' or '..', skip.
 	 * If it starts '.#', treat as a temporary file that didn't
-	 * get deleted for some reason and flag an error.
-	 * Otherwise weirdness lurks; log an error.
-	 *
-	 * N.B. Don't delete it! I'm not sure what happens to
-	 * readdir if you go around deleting stuff from the directory
-	 * between calls. The Single Unix Spec v2 isn't either.
+	 * get deleted for some reason and flag an error and delete it.
 	 */
 	switch( d->d_name[1] )
 	{
@@ -346,8 +344,13 @@
 	    break;
 
 	case '#':
-	    Log_err( "Bad temporary file %s in %s/overview - please delete",
-		     d->d_name, Cfg_spoolDir() );
+	    snprintf( tmpfname, MAXCHAR, "%s/overview/.#%d.%s",
+		      Cfg_spoolDir(), (int) getpid(), d->d_name ); 
+	    Log_err( "Bad temporary file %s - please delete",
+		     tmpfname );
+	    if ( unlink( tmpfname ) < 0 )
+		Log_err( "Unlink of %s failed: %s",
+			 tmpfname, strerror(errno) );
 	    break;
 
 	default: