comparison src/content.c @ 167:7ba337dafb2c noffle

[svn] * TODO,content.c,lock.c,server.c,server.h: Remove bug notice re: need to do a Cont_write on Lock_closeDatabases in case of unwritten content changes when releasing the lock. Update content to keep dirty flag and avoid unnecessary writes, and lock to signal server to re-read its group content info after the lock is released. Do NOT write content info on Lock_close if dirty, as the placeholder article in unsubscribed groups is currently done by adding it to the content when joining the group and deliberately not saving it unless another content modification takes place and thus causes the content to be saved.
author bears
date Sun, 25 Feb 2001 23:29:50 +0000
parents 988cacc01470
children fed1334d766b
comparison
equal deleted inserted replaced
166:1d92abe57427 167:7ba337dafb2c
1 /* 1 /*
2 content.c 2 content.c
3 3
4 $Id: content.c 115 2000-05-19 15:18:05Z bears $ 4 $Id: content.c 260 2001-02-25 23:29:50Z 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
36 Over **elem; /* Ptr to array with ptrs to overviews. 36 Over **elem; /* Ptr to array with ptrs to overviews.
37 NULL entries for non-existing article numbers 37 NULL entries for non-existing article numbers
38 in group. */ 38 in group. */
39 Str name; 39 Str name;
40 Str file; 40 Str file;
41 } cont = { NULL, 1, 1, 0, 0, 0, NULL, "", "" }; 41 Bool dirty; /* Needs writing? */
42 } cont = { NULL, 1, 1, 0, 0, 0, NULL, "", "", FALSE };
42 43
43 void 44 void
44 Cont_app( Over *ov ) 45 Cont_app( Over *ov )
45 { 46 {
46 if ( cont.max < cont.size + 1 ) 47 if ( cont.max < cont.size + 1 )
57 ASSERT( cont.vecFirst > 0 ); 58 ASSERT( cont.vecFirst > 0 );
58 if ( ov ) 59 if ( ov )
59 Ov_setNumb( ov, cont.vecFirst + cont.size ); 60 Ov_setNumb( ov, cont.vecFirst + cont.size );
60 cont.elem[ cont.size++ ] = ov; 61 cont.elem[ cont.size++ ] = ov;
61 cont.last = cont.vecFirst + cont.size - 1; 62 cont.last = cont.vecFirst + cont.size - 1;
63 cont.dirty = TRUE;
62 } 64 }
63 65
64 Bool 66 Bool
65 Cont_validNumb( int n ) 67 Cont_validNumb( int n )
66 { 68 {
76 if ( ! Cont_validNumb( n ) ) 78 if ( ! Cont_validNumb( n ) )
77 return; 79 return;
78 ov = &cont.elem[ n - cont.vecFirst ]; 80 ov = &cont.elem[ n - cont.vecFirst ];
79 free( *ov ); 81 free( *ov );
80 *ov = NULL; 82 *ov = NULL;
83 cont.dirty = TRUE;
81 } 84 }
82 85
83 /* Remove all overviews from content. */ 86 /* Remove all overviews from content. */
84 static void 87 static void
85 clearCont( void ) 88 clearCont( void )
184 Bool anythingWritten; 187 Bool anythingWritten;
185 int i; 188 int i;
186 FILE *f; 189 FILE *f;
187 const Over *ov, *ov_next; 190 const Over *ov, *ov_next;
188 191
192 /* If nowt has changed, do nowt. */
193 if ( ! cont.dirty )
194 return;
195
189 /* Save the overview */ 196 /* Save the overview */
190 if ( ! ( f = fopen( cont.file, "w" ) ) ) 197 if ( ! ( f = fopen( cont.file, "w" ) ) )
191 { 198 {
192 Log_err( "Could not open %s for writing", cont.file ); 199 Log_err( "Could not open %s for writing", cont.file );
193 return; 200 return;
239 if ( ! anythingWritten ) 246 if ( ! anythingWritten )
240 { 247 {
241 unlink( cont.file ); 248 unlink( cont.file );
242 cont.first = cont.last + 1; 249 cont.first = cont.last + 1;
243 } 250 }
251
252 cont.dirty = FALSE;
244 } 253 }
245 254
246 const Over * 255 const Over *
247 Cont_get( int numb ) 256 Cont_get( int numb )
248 { 257 {