Mercurial > noffle
diff src/content.c @ 223:ffb1848a39db noffle
[svn] * src/util.c: Improve (correct) error detection when updating
timestamp file.
* src/content.h, src/content.c: Return Boolean success/fail from
Cont_write. Also ensure cont.first isn't polluted in the event
of a failed update.
* src/client.c,src/control.c,src/fetch.c,src/noffle.c,src/post.c,
src/pseudo.c: If Cont_write fails, don't do actions that need it to
have worked. Typically, don't update first and last article numbers
in group database.
* src/server.c: If groupinfo.lastupdate is unreadable or corrupt,
spot this and report it and give an explicit error when processing
NNTP NEWGROUPS command.
author | bears |
---|---|
date | Sun, 09 Dec 2001 12:31:57 +0000 |
parents | d9f314014f7a |
children | c48d7e881a21 |
line wrap: on
line diff
--- a/src/content.c Sun Dec 09 11:32:31 2001 +0000 +++ b/src/content.c Sun Dec 09 12:31:57 2001 +0000 @@ -1,7 +1,7 @@ /* content.c - $Id: content.c 338 2001-11-29 22:16:06Z bears $ + $Id: content.c 342 2001-12-09 12:31:57Z bears $ */ #if HAVE_CONFIG_H @@ -183,7 +183,7 @@ } } -void +Bool Cont_write( void ) { Bool anythingWritten; @@ -192,10 +192,11 @@ const Over *ov, *ov_next; Str tmpfname; Bool writeErr; + int first; /* If nowt has changed, do nowt. */ if ( ! cont.dirty ) - return; + return TRUE; /* Save the overview to temporary file in same dir. */ /* old tmpfnames will be expired at noffle.c:expireContents() */ @@ -204,11 +205,11 @@ if ( ! ( f = fopen( tmpfname, "w" ) ) ) { Log_err( "Could not open %s for writing", tmpfname ); - return; + return FALSE; } Log_dbg( LOG_DBG_NEWSBASE, "Writing %s (%lu)", tmpfname, cont.size ); anythingWritten = FALSE; - cont.first = -1; + first = -1; writeErr = FALSE; for ( i = 0; i < cont.size; ++i ) @@ -232,7 +233,7 @@ || ( ov_next != NULL && Ov_numb( ov_next ) - Ov_numb( ov ) == 1 ) ) { - anythingWritten = TRUE; + anythingWritten = TRUE; if ( ! Ov_write( ov, f ) ) { Log_err( "Writing of overview line to %s failed: %s", @@ -242,8 +243,8 @@ } else { - if ( cont.first < 0 ) - cont.first = cont.vecFirst + i; + if ( first < 0 ) + first = cont.vecFirst + i; } } } @@ -255,8 +256,14 @@ writeErr = TRUE; } + if ( writeErr ) + { + /* Write error - leave everything as at present */ + return FALSE; + } + /* - If empty, remove the overview file and set set first to one + If empty, remove the overview file and set first to one beyond last to flag said emptiness. */ if ( ! anythingWritten ) @@ -264,21 +271,33 @@ if ( unlink( tmpfname ) < 0 ) Log_err( "Unlink of %s failed: %s", tmpfname, strerror( errno ) ); if ( unlink( cont.file ) < 0 ) + { Log_err( "Unlink of %s failed: %s", cont.file, strerror( errno ) ); + return FALSE; + } else { cont.dirty = FALSE; cont.first = cont.last + 1; } } - else if ( ! writeErr ) + else { if ( rename( tmpfname, cont.file ) < 0 ) + { Log_err( "Rename of content file %s to %s failed: %s", tmpfname, cont.file, strerror( errno ) ); + return FALSE; + } else + { + ASSERT( first != -1 ); cont.dirty = FALSE; + cont.first = first; + } } + + return TRUE; } const Over *