comparison 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
comparison
equal deleted inserted replaced
218:411b6ab1acb7 219:d9f314014f7a
1 /* 1 /*
2 content.c 2 content.c
3 3
4 $Id: content.c 337 2001-11-22 22:48:07Z bears $ 4 $Id: content.c 338 2001-11-29 22:16:06Z bears $
5 */ 5 */
6 6
7 #if HAVE_CONFIG_H 7 #if HAVE_CONFIG_H
8 #include <config.h> 8 #include <config.h>
9 #endif 9 #endif
320 struct dirent *d; 320 struct dirent *d;
321 321
322 ASSERT( cont.dir ); 322 ASSERT( cont.dir );
323 if ( ! ( d = readdir( cont.dir ) ) ) 323 if ( ! ( d = readdir( cont.dir ) ) )
324 { 324 {
325 closedir( cont.dir );
325 cont.dir = NULL; 326 cont.dir = NULL;
326 return FALSE; 327 return FALSE;
327 } 328 }
328 if ( ! d->d_name ) 329 if ( ! d->d_name )
329 return FALSE; 330 return FALSE;
330 if ( d->d_name[0] == '.' ) 331 if ( d->d_name[0] == '.' )
331 { 332 {
333 Str tmpfname;
334
332 /* 335 /*
333 * If it is '.' or '..', skip. 336 * If it is '.' or '..', skip.
334 * If it starts '.#', treat as a temporary file that didn't 337 * If it starts '.#', treat as a temporary file that didn't
335 * get deleted for some reason and flag an error. 338 * get deleted for some reason and flag an error and delete it.
336 * Otherwise weirdness lurks; log an error.
337 *
338 * N.B. Don't delete it! I'm not sure what happens to
339 * readdir if you go around deleting stuff from the directory
340 * between calls. The Single Unix Spec v2 isn't either.
341 */ 339 */
342 switch( d->d_name[1] ) 340 switch( d->d_name[1] )
343 { 341 {
344 case '\0': 342 case '\0':
345 case '.': 343 case '.':
346 break; 344 break;
347 345
348 case '#': 346 case '#':
349 Log_err( "Bad temporary file %s in %s/overview - please delete", 347 snprintf( tmpfname, MAXCHAR, "%s/overview/.#%d.%s",
350 d->d_name, Cfg_spoolDir() ); 348 Cfg_spoolDir(), (int) getpid(), d->d_name );
349 Log_err( "Bad temporary file %s - please delete",
350 tmpfname );
351 if ( unlink( tmpfname ) < 0 )
352 Log_err( "Unlink of %s failed: %s",
353 tmpfname, strerror(errno) );
351 break; 354 break;
352 355
353 default: 356 default:
354 Log_err( "Unknown file %s in %s/overview - please delete", 357 Log_err( "Unknown file %s in %s/overview - please delete",
355 d->d_name, Cfg_spoolDir() ); 358 d->d_name, Cfg_spoolDir() );