Mercurial > noffle
diff src/util.c @ 206:eb2589384836 noffle
[svn] * TODO: Update the TODO list.
* src/util.c: When updating timestamp files, write new stamp to temp file
and rename, so failure with e.g. full disc doesn't leave an empty stamp
file.
author | bears |
---|---|
date | Wed, 14 Nov 2001 10:56:42 +0000 |
parents | 027608dbd16b |
children | ffb1848a39db |
line wrap: on
line diff
--- a/src/util.c Sun Nov 11 04:22:42 2001 +0000 +++ b/src/util.c Wed Nov 14 10:56:42 2001 +0000 @@ -1,7 +1,7 @@ /* util.c - $Id: util.c 321 2001-11-11 03:53:07Z mirkol $ + $Id: util.c 325 2001-11-14 10:56:42Z bears $ */ #if HAVE_CONFIG_H @@ -243,16 +243,31 @@ { FILE *f; time_t t; + Str tmpfname; + snprintf( tmpfname, MAXCHAR, "%s/.#%d.stamp.update", + Cfg_spoolDir(), (int) getpid() ); time( &t ); - if ( ! ( f = fopen( file, "w" ) ) ) + if ( ! ( f = fopen( tmpfname, "w" ) ) ) { Log_err( "Could not open %s for writing (%s)", - file, strerror( errno ) ); + tmpfname, strerror( errno ) ); return; } fprintf( f, "%lu\n", t ); fclose( f ); + if ( ferror( f ) ) + { + Log_err( "Error stamping into file %s: %s", + tmpfname, strerror( errno ) ); + + } + else + { + if ( rename( tmpfname, file ) < 0 ) + Log_err( "Rename of stamp file %s to %s failed: %s", + tmpfname, file, strerror( errno ) ); + } } Bool