annotate src/content.c @ 331:ff7a2dc6023e noffle

[svn] * src/client.c,src/group.c: Reunite forbidden group comment with code, and revise forbidden rules to allow single component names except for some specific ones.
author bears
date Wed, 26 Feb 2003 11:30:41 +0000
parents 9b79433f0976
children 8e14809bf172
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
1 /*
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
2 content.c
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
3
318
9b79433f0976 [svn] * src/content.c: Tighten up checks when accessing content vector.
bears
parents: 281
diff changeset
4 $Id: content.c 453 2003-02-21 16:01:28Z bears $
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
5 */
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
6
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
7 #if HAVE_CONFIG_H
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
8 #include <config.h>
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
9 #endif
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
10
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
11 #include <stdio.h>
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
12 #include <dirent.h>
188
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
13 #include <errno.h>
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
14 #include <fcntl.h>
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
15 #include <sys/types.h>
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
16 #include <sys/stat.h>
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
17 #include <unistd.h>
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
18 #include "common.h"
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
19 #include "configfile.h"
197
24d4cd032da5 [svn] * AUTHORS,INSTALL,NEWS,README,TODO,docs/NOTES,src/client.c,src/protocol.c,
bears
parents: 196
diff changeset
20 #include "content.h"
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
21 #include "group.h"
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
22 #include "log.h"
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
23 #include "over.h"
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
24 #include "pseudo.h"
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
25 #include "util.h"
54
125d79c9e586 [svn] * src/client.c, src/configfile.c, src/content.c, src/control.c,
uh1763
parents: 49
diff changeset
26 #include "portable.h"
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
27
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
28 struct
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
29 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
30 DIR *dir; /* Directory for browsing through all
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
31 groups */
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
32 int vecFirst; /* First article number in vector */
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
33 int first; /* First live article number */
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
34 int last; /* Last article number */
59
e612b263934f [svn] Changed some variable types and used some casts to avoid compiler
enz
parents: 54
diff changeset
35 int size; /* Number of overviews. */
e612b263934f [svn] Changed some variable types and used some casts to avoid compiler
enz
parents: 54
diff changeset
36 int max; /* Size of elem. */
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
37 Over **elem; /* Ptr to array with ptrs to overviews.
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
38 NULL entries for non-existing article numbers
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
39 in group. */
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
40 Str name;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
41 Str file;
167
7ba337dafb2c [svn] * TODO,content.c,lock.c,server.c,server.h: Remove bug notice re:
bears
parents: 96
diff changeset
42 Bool dirty; /* Needs writing? */
7ba337dafb2c [svn] * TODO,content.c,lock.c,server.c,server.h: Remove bug notice re:
bears
parents: 96
diff changeset
43 } cont = { NULL, 1, 1, 0, 0, 0, NULL, "", "", FALSE };
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
44
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
45 void
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
46 Cont_app( Over *ov )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
47 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
48 if ( cont.max < cont.size + 1 )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
49 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
50 if ( ! ( cont.elem = realloc( cont.elem,
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
51 ( cont.max + 500 )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
52 * sizeof( cont.elem[ 0 ] ) ) ) )
281
5eece4dfd945 [svn] * src/log.c,src/log.h: Add Log_fatal() for reporting fatal errors
bears
parents: 255
diff changeset
53 Log_fatal( "Could not realloc overview list" );
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
54 cont.max += 500;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
55 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
56 ASSERT( cont.vecFirst > 0 );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
57 if ( ov )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
58 Ov_setNumb( ov, cont.vecFirst + cont.size );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
59 cont.elem[ cont.size++ ] = ov;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
60 cont.last = cont.vecFirst + cont.size - 1;
167
7ba337dafb2c [svn] * TODO,content.c,lock.c,server.c,server.h: Remove bug notice re:
bears
parents: 96
diff changeset
61 cont.dirty = TRUE;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
62 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
63
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
64 Bool
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
65 Cont_validNumb( int n )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
66 {
318
9b79433f0976 [svn] * src/content.c: Tighten up checks when accessing content vector.
bears
parents: 281
diff changeset
67 int ofs = n - cont.vecFirst;
9b79433f0976 [svn] * src/content.c: Tighten up checks when accessing content vector.
bears
parents: 281
diff changeset
68
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
69 return ( n != 0 && n >= cont.first && n <= cont.last
318
9b79433f0976 [svn] * src/content.c: Tighten up checks when accessing content vector.
bears
parents: 281
diff changeset
70 && ofs >= 0 && ofs < cont.size
9b79433f0976 [svn] * src/content.c: Tighten up checks when accessing content vector.
bears
parents: 281
diff changeset
71 && cont.elem[ ofs ] != NULL );
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
72 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
73
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
74 void
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
75 Cont_delete( int n )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
76 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
77 Over **ov;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
78
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
79 if ( ! Cont_validNumb( n ) )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
80 return;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
81 ov = &cont.elem[ n - cont.vecFirst ];
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
82 free( *ov );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
83 *ov = NULL;
167
7ba337dafb2c [svn] * TODO,content.c,lock.c,server.c,server.h: Remove bug notice re:
bears
parents: 96
diff changeset
84 cont.dirty = TRUE;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
85 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
86
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
87 /* Remove all overviews from content. */
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
88 static void
45
32ba1198c6fa [svn] * Makefile.in, configure, configure.in, docs/Makefile.in, src/Makefile.in:
uh1763
parents: 43
diff changeset
89 clearCont( void )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
90 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
91 int i;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
92
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
93 for ( i = 0; i < cont.size; ++i )
318
9b79433f0976 [svn] * src/content.c: Tighten up checks when accessing content vector.
bears
parents: 281
diff changeset
94 {
9b79433f0976 [svn] * src/content.c: Tighten up checks when accessing content vector.
bears
parents: 281
diff changeset
95 if ( cont.elem[ i ] != NULL )
9b79433f0976 [svn] * src/content.c: Tighten up checks when accessing content vector.
bears
parents: 281
diff changeset
96 del_Over( cont.elem[ i ] );
9b79433f0976 [svn] * src/content.c: Tighten up checks when accessing content vector.
bears
parents: 281
diff changeset
97 cont.elem[ i ] = NULL;
9b79433f0976 [svn] * src/content.c: Tighten up checks when accessing content vector.
bears
parents: 281
diff changeset
98 }
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
99 cont.size = 0;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
100 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
101
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
102 static void
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
103 setupEmpty( const char *name )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
104 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
105 cont.last = Grp_last( name );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
106 cont.first = cont.vecFirst = cont.last + 1;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
107 ASSERT( cont.first > 0 );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
108 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
109
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
110 /* Extend content list to size "cnt" and append NULL entries. */
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
111 static void
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
112 extendCont( int cnt )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
113 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
114 int i, n;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
115
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
116 if ( cont.size < cnt )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
117 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
118 n = cnt - cont.size;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
119 for ( i = 0; i < n; ++i )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
120 Cont_app( NULL );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
121 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
122 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
123
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
124 /* Discard all cached overviews, and read in the overviews of a new group
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
125 from its overviews file. */
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
126 void
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
127 Cont_read( const char *name )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
128 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
129 FILE *f;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
130 Over *ov;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
131 int numb;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
132 Str line;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
133
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
134 /* Delete old overviews and make room for new ones. */
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
135 cont.vecFirst = 0;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
136 cont.first = 0;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
137 cont.last = 0;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
138 Utl_cpyStr( cont.name, name );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
139 clearCont();
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
140
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
141 /* read overviews from overview file and store them in the overviews
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
142 list */
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
143 snprintf( cont.file, MAXCHAR, "%s/overview/%s", Cfg_spoolDir(), name );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
144 f = fopen( cont.file, "r" );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
145 if ( ! f )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
146 {
185
fed1334d766b [svn] * src/client.c: Change variable only used on constant to 'const'.
bears
parents: 167
diff changeset
147 Log_dbg( LOG_DBG_NEWSBASE, "No group overview file: %s", cont.file );
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
148 setupEmpty( name );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
149 return;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
150 }
185
fed1334d766b [svn] * src/client.c: Change variable only used on constant to 'const'.
bears
parents: 167
diff changeset
151 Log_dbg( LOG_DBG_NEWSBASE, "Reading %s", cont.file );
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
152 while ( fgets( line, MAXCHAR, f ) )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
153 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
154 if ( ! ( ov = Ov_read( line ) ) )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
155 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
156 Log_err( "Overview corrupted in %s: %s", name, line );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
157 continue;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
158 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
159 numb = Ov_numb( ov );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
160 if ( numb < cont.first )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
161 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
162 Log_err( "Wrong ordering in %s: %s", name, line );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
163 continue;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
164 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
165 if ( cont.first == 0 )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
166 cont.first = cont.vecFirst = numb;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
167 cont.last = numb;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
168 extendCont( numb - cont.first + 1 );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
169 cont.elem[ numb - cont.first ] = ov;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
170 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
171 fclose( f );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
172
196
60a70c16d79c [svn] * src/content.c: When generating temp file to write new content to, make
bears
parents: 188
diff changeset
173
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
174 if ( cont.first == 0 )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
175 setupEmpty( name ); /* Corrupt overview file recovery */
96
988cacc01470 [svn] Preserve group last number if last article(s) cancelled
bears
parents: 75
diff changeset
176 else
988cacc01470 [svn] Preserve group last number if last article(s) cancelled
bears
parents: 75
diff changeset
177 {
988cacc01470 [svn] Preserve group last number if last article(s) cancelled
bears
parents: 75
diff changeset
178 int grpLast;
988cacc01470 [svn] Preserve group last number if last article(s) cancelled
bears
parents: 75
diff changeset
179
988cacc01470 [svn] Preserve group last number if last article(s) cancelled
bears
parents: 75
diff changeset
180 /*
988cacc01470 [svn] Preserve group last number if last article(s) cancelled
bears
parents: 75
diff changeset
181 Check for end article(s) being cancelled. Need to ensure we
318
9b79433f0976 [svn] * src/content.c: Tighten up checks when accessing content vector.
bears
parents: 281
diff changeset
182 don't re-use end article number.
96
988cacc01470 [svn] Preserve group last number if last article(s) cancelled
bears
parents: 75
diff changeset
183 */
988cacc01470 [svn] Preserve group last number if last article(s) cancelled
bears
parents: 75
diff changeset
184 grpLast = Grp_last( name );
988cacc01470 [svn] Preserve group last number if last article(s) cancelled
bears
parents: 75
diff changeset
185 if ( cont.last < grpLast )
988cacc01470 [svn] Preserve group last number if last article(s) cancelled
bears
parents: 75
diff changeset
186 extendCont( grpLast - cont.first + 1 );
988cacc01470 [svn] Preserve group last number if last article(s) cancelled
bears
parents: 75
diff changeset
187 }
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
188 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
189
223
ffb1848a39db [svn] * src/util.c: Improve (correct) error detection when updating
bears
parents: 219
diff changeset
190 Bool
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
191 Cont_write( void )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
192 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
193 Bool anythingWritten;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
194 int i;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
195 FILE *f;
75
22b3e3dfc8c2 [svn] Preserve gen info sometimes
bears
parents: 59
diff changeset
196 const Over *ov, *ov_next;
188
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
197 Str tmpfname;
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
198 Bool writeErr;
223
ffb1848a39db [svn] * src/util.c: Improve (correct) error detection when updating
bears
parents: 219
diff changeset
199 int first;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
200
167
7ba337dafb2c [svn] * TODO,content.c,lock.c,server.c,server.h: Remove bug notice re:
bears
parents: 96
diff changeset
201 /* If nowt has changed, do nowt. */
7ba337dafb2c [svn] * TODO,content.c,lock.c,server.c,server.h: Remove bug notice re:
bears
parents: 96
diff changeset
202 if ( ! cont.dirty )
223
ffb1848a39db [svn] * src/util.c: Improve (correct) error detection when updating
bears
parents: 219
diff changeset
203 return TRUE;
167
7ba337dafb2c [svn] * TODO,content.c,lock.c,server.c,server.h: Remove bug notice re:
bears
parents: 96
diff changeset
204
188
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
205 /* Save the overview to temporary file in same dir. */
213
f0acb9366e4f [svn] minor bugfix in Conf_write()
mirkol
parents: 197
diff changeset
206 /* old tmpfnames will be expired at noffle.c:expireContents() */
196
60a70c16d79c [svn] * src/content.c: When generating temp file to write new content to, make
bears
parents: 188
diff changeset
207 snprintf( tmpfname, MAXCHAR, "%s/overview/.#%d.%s",
60a70c16d79c [svn] * src/content.c: When generating temp file to write new content to, make
bears
parents: 188
diff changeset
208 Cfg_spoolDir(), (int) getpid(), cont.name );
188
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
209 if ( ! ( f = fopen( tmpfname, "w" ) ) )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
210 {
188
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
211 Log_err( "Could not open %s for writing", tmpfname );
223
ffb1848a39db [svn] * src/util.c: Improve (correct) error detection when updating
bears
parents: 219
diff changeset
212 return FALSE;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
213 }
188
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
214 Log_dbg( LOG_DBG_NEWSBASE, "Writing %s (%lu)", tmpfname, cont.size );
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
215 anythingWritten = FALSE;
223
ffb1848a39db [svn] * src/util.c: Improve (correct) error detection when updating
bears
parents: 219
diff changeset
216 first = -1;
188
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
217 writeErr = FALSE;
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
218
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
219 for ( i = 0; i < cont.size; ++i )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
220 {
75
22b3e3dfc8c2 [svn] Preserve gen info sometimes
bears
parents: 59
diff changeset
221 ov = cont.elem[ i ];
22b3e3dfc8c2 [svn] Preserve gen info sometimes
bears
parents: 59
diff changeset
222 if ( ov )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
223 {
75
22b3e3dfc8c2 [svn] Preserve gen info sometimes
bears
parents: 59
diff changeset
224 if ( i + 1 < cont.size )
22b3e3dfc8c2 [svn] Preserve gen info sometimes
bears
parents: 59
diff changeset
225 ov_next = cont.elem[ i + 1 ];
22b3e3dfc8c2 [svn] Preserve gen info sometimes
bears
parents: 59
diff changeset
226 else
22b3e3dfc8c2 [svn] Preserve gen info sometimes
bears
parents: 59
diff changeset
227 ov_next = NULL;
22b3e3dfc8c2 [svn] Preserve gen info sometimes
bears
parents: 59
diff changeset
228
22b3e3dfc8c2 [svn] Preserve gen info sometimes
bears
parents: 59
diff changeset
229 /*
22b3e3dfc8c2 [svn] Preserve gen info sometimes
bears
parents: 59
diff changeset
230 Preserve gen info if it is followed immediately by an
22b3e3dfc8c2 [svn] Preserve gen info sometimes
bears
parents: 59
diff changeset
231 article with the next number. In practice, this means
22b3e3dfc8c2 [svn] Preserve gen info sometimes
bears
parents: 59
diff changeset
232 that when in auto-subscribed mode, the gen info will
22b3e3dfc8c2 [svn] Preserve gen info sometimes
bears
parents: 59
diff changeset
233 remain until the 'group now subscribed' message is
22b3e3dfc8c2 [svn] Preserve gen info sometimes
bears
parents: 59
diff changeset
234 expired.
22b3e3dfc8c2 [svn] Preserve gen info sometimes
bears
parents: 59
diff changeset
235 */
22b3e3dfc8c2 [svn] Preserve gen info sometimes
bears
parents: 59
diff changeset
236 if ( ! Pseudo_isGeneralInfo( Ov_msgId( ov ) )
22b3e3dfc8c2 [svn] Preserve gen info sometimes
bears
parents: 59
diff changeset
237 || ( ov_next != NULL &&
22b3e3dfc8c2 [svn] Preserve gen info sometimes
bears
parents: 59
diff changeset
238 Ov_numb( ov_next ) - Ov_numb( ov ) == 1 ) )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
239 {
223
ffb1848a39db [svn] * src/util.c: Improve (correct) error detection when updating
bears
parents: 219
diff changeset
240 anythingWritten = TRUE;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
241 if ( ! Ov_write( ov, f ) )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
242 {
188
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
243 Log_err( "Writing of overview line to %s failed: %s",
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
244 tmpfname, strerror( errno ) );
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
245 writeErr = TRUE;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
246 break;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
247 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
248 else
49
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
249 {
223
ffb1848a39db [svn] * src/util.c: Improve (correct) error detection when updating
bears
parents: 219
diff changeset
250 if ( first < 0 )
ffb1848a39db [svn] * src/util.c: Improve (correct) error detection when updating
bears
parents: 219
diff changeset
251 first = cont.vecFirst + i;
49
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
252 }
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
253 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
254 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
255 }
188
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
256 if ( fclose( f ) != 0 )
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
257 {
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
258 Log_err( "Close of content file %s failed: %s",
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
259 tmpfname, strerror( errno ) );
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
260 writeErr = TRUE;
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
261 }
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
262
223
ffb1848a39db [svn] * src/util.c: Improve (correct) error detection when updating
bears
parents: 219
diff changeset
263 if ( writeErr )
ffb1848a39db [svn] * src/util.c: Improve (correct) error detection when updating
bears
parents: 219
diff changeset
264 {
ffb1848a39db [svn] * src/util.c: Improve (correct) error detection when updating
bears
parents: 219
diff changeset
265 /* Write error - leave everything as at present */
ffb1848a39db [svn] * src/util.c: Improve (correct) error detection when updating
bears
parents: 219
diff changeset
266 return FALSE;
ffb1848a39db [svn] * src/util.c: Improve (correct) error detection when updating
bears
parents: 219
diff changeset
267 }
ffb1848a39db [svn] * src/util.c: Improve (correct) error detection when updating
bears
parents: 219
diff changeset
268
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
269 /*
223
ffb1848a39db [svn] * src/util.c: Improve (correct) error detection when updating
bears
parents: 219
diff changeset
270 If empty, remove the overview file and set first to one
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
271 beyond last to flag said emptiness.
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
272 */
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
273 if ( ! anythingWritten )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
274 {
213
f0acb9366e4f [svn] minor bugfix in Conf_write()
mirkol
parents: 197
diff changeset
275 if ( unlink( tmpfname ) < 0 )
f0acb9366e4f [svn] minor bugfix in Conf_write()
mirkol
parents: 197
diff changeset
276 Log_err( "Unlink of %s failed: %s", tmpfname, strerror( errno ) );
218
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
277 if ( unlink( cont.file ) < 0 )
223
ffb1848a39db [svn] * src/util.c: Improve (correct) error detection when updating
bears
parents: 219
diff changeset
278 {
218
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
279 Log_err( "Unlink of %s failed: %s", cont.file, strerror( errno ) );
223
ffb1848a39db [svn] * src/util.c: Improve (correct) error detection when updating
bears
parents: 219
diff changeset
280 return FALSE;
ffb1848a39db [svn] * src/util.c: Improve (correct) error detection when updating
bears
parents: 219
diff changeset
281 }
188
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
282 else
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
283 {
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
284 cont.dirty = FALSE;
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
285 cont.first = cont.last + 1;
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
286 }
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
287 }
223
ffb1848a39db [svn] * src/util.c: Improve (correct) error detection when updating
bears
parents: 219
diff changeset
288 else
188
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
289 {
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
290 if ( rename( tmpfname, cont.file ) < 0 )
223
ffb1848a39db [svn] * src/util.c: Improve (correct) error detection when updating
bears
parents: 219
diff changeset
291 {
188
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
292 Log_err( "Rename of content file %s to %s failed: %s",
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
293 tmpfname, cont.file, strerror( errno ) );
223
ffb1848a39db [svn] * src/util.c: Improve (correct) error detection when updating
bears
parents: 219
diff changeset
294 return FALSE;
ffb1848a39db [svn] * src/util.c: Improve (correct) error detection when updating
bears
parents: 219
diff changeset
295 }
188
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
296 else
223
ffb1848a39db [svn] * src/util.c: Improve (correct) error detection when updating
bears
parents: 219
diff changeset
297 {
ffb1848a39db [svn] * src/util.c: Improve (correct) error detection when updating
bears
parents: 219
diff changeset
298 ASSERT( first != -1 );
188
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
299 cont.dirty = FALSE;
223
ffb1848a39db [svn] * src/util.c: Improve (correct) error detection when updating
bears
parents: 219
diff changeset
300 cont.first = first;
ffb1848a39db [svn] * src/util.c: Improve (correct) error detection when updating
bears
parents: 219
diff changeset
301 }
188
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
302 }
223
ffb1848a39db [svn] * src/util.c: Improve (correct) error detection when updating
bears
parents: 219
diff changeset
303
ffb1848a39db [svn] * src/util.c: Improve (correct) error detection when updating
bears
parents: 219
diff changeset
304 return TRUE;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
305 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
306
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
307 const Over *
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
308 Cont_get( int numb )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
309 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
310 if ( ! Cont_validNumb( numb ) )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
311 return NULL;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
312 return cont.elem[ numb - cont.vecFirst ];
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
313 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
314
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
315 int
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
316 Cont_first( void ) { return cont.first; }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
317
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
318 int
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
319 Cont_last( void ) { return cont.last; }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
320
49
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
321 int
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
322 Cont_find( const char *msgId )
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
323 {
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
324 int i;
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
325 const Over *ov;
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
326
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
327 for ( i = 0; i < cont.size; i++ )
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
328 {
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
329 if ( ( ov = cont.elem[ i ] )
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
330 && strcmp( Ov_msgId( ov ), msgId ) == 0 )
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
331 return i + cont.vecFirst;
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
332 }
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
333
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
334 return -1;
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
335 }
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
336
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
337 const char *
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
338 Cont_grp( void ) { return cont.name; }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
339
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
340 Bool
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
341 Cont_nextGrp( Str result )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
342 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
343 struct dirent *d;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
344
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
345 ASSERT( cont.dir );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
346 if ( ! ( d = readdir( cont.dir ) ) )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
347 {
219
d9f314014f7a [svn] * src/content.c: Remove spurious temporary files and add a closedir()
bears
parents: 218
diff changeset
348 closedir( cont.dir );
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
349 cont.dir = NULL;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
350 return FALSE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
351 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
352 if ( ! d->d_name )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
353 return FALSE;
218
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
354 if ( d->d_name[0] == '.' )
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
355 {
227
c48d7e881a21 [svn] fixed expiration of temp overview files, once again.
mirkol
parents: 223
diff changeset
356 Str tmpfname;
219
d9f314014f7a [svn] * src/content.c: Remove spurious temporary files and add a closedir()
bears
parents: 218
diff changeset
357
218
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
358 /*
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
359 * If it is '.' or '..', skip.
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
360 * If it starts '.#', treat as a temporary file that didn't
219
d9f314014f7a [svn] * src/content.c: Remove spurious temporary files and add a closedir()
bears
parents: 218
diff changeset
361 * get deleted for some reason and flag an error and delete it.
218
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
362 */
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
363 switch( d->d_name[1] )
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
364 {
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
365 case '\0':
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
366 case '.':
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
367 break;
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
368
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
369 case '#':
227
c48d7e881a21 [svn] fixed expiration of temp overview files, once again.
mirkol
parents: 223
diff changeset
370 snprintf( tmpfname, MAXCHAR, "%s/overview/%s",
c48d7e881a21 [svn] fixed expiration of temp overview files, once again.
mirkol
parents: 223
diff changeset
371 Cfg_spoolDir(), d->d_name );
c48d7e881a21 [svn] fixed expiration of temp overview files, once again.
mirkol
parents: 223
diff changeset
372 Log_err( "Bad temporary file %s - deleting.",
c48d7e881a21 [svn] fixed expiration of temp overview files, once again.
mirkol
parents: 223
diff changeset
373 tmpfname );
219
d9f314014f7a [svn] * src/content.c: Remove spurious temporary files and add a closedir()
bears
parents: 218
diff changeset
374 if ( unlink( tmpfname ) < 0 )
d9f314014f7a [svn] * src/content.c: Remove spurious temporary files and add a closedir()
bears
parents: 218
diff changeset
375 Log_err( "Unlink of %s failed: %s",
d9f314014f7a [svn] * src/content.c: Remove spurious temporary files and add a closedir()
bears
parents: 218
diff changeset
376 tmpfname, strerror(errno) );
218
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
377 break;
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
378
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
379 default:
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
380 Log_err( "Unknown file %s in %s/overview - please delete",
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
381 d->d_name, Cfg_spoolDir() );
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
382 break;
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
383 }
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
384 return Cont_nextGrp( result );
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
385 }
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
386 Utl_cpyStr( result, d->d_name );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
387 result[ MAXCHAR - 1 ] = '\0';
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
388 return TRUE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
389 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
390
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
391 Bool
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
392 Cont_firstGrp( Str result )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
393 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
394 Str name;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
395
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
396 snprintf( name, MAXCHAR, "%s/overview", Cfg_spoolDir() );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
397 if ( ! ( cont.dir = opendir( name ) ) )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
398 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
399 Log_err( "Cannot open %s", name );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
400 return FALSE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
401 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
402 return Cont_nextGrp( result );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
403 }
255
52f467c7213b [svn] * docs/noffle.1,src/Makefile.am,src/Makefile.in,src/content.c,
bears
parents: 227
diff changeset
404
52f467c7213b [svn] * docs/noffle.1,src/Makefile.am,src/Makefile.in,src/content.c,
bears
parents: 227
diff changeset
405 Bool
52f467c7213b [svn] * docs/noffle.1,src/Makefile.am,src/Makefile.in,src/content.c,
bears
parents: 227
diff changeset
406 Cont_exists( const char *grp )
52f467c7213b [svn] * docs/noffle.1,src/Makefile.am,src/Makefile.in,src/content.c,
bears
parents: 227
diff changeset
407 {
52f467c7213b [svn] * docs/noffle.1,src/Makefile.am,src/Makefile.in,src/content.c,
bears
parents: 227
diff changeset
408 Str fname;
52f467c7213b [svn] * docs/noffle.1,src/Makefile.am,src/Makefile.in,src/content.c,
bears
parents: 227
diff changeset
409
52f467c7213b [svn] * docs/noffle.1,src/Makefile.am,src/Makefile.in,src/content.c,
bears
parents: 227
diff changeset
410 /* Do we have a content/overview file for this group? */
52f467c7213b [svn] * docs/noffle.1,src/Makefile.am,src/Makefile.in,src/content.c,
bears
parents: 227
diff changeset
411 snprintf( fname, MAXCHAR, "%s/overview/%s", Cfg_spoolDir(), grp );
52f467c7213b [svn] * docs/noffle.1,src/Makefile.am,src/Makefile.in,src/content.c,
bears
parents: 227
diff changeset
412 return ( access( fname, R_OK ) == 0 );
52f467c7213b [svn] * docs/noffle.1,src/Makefile.am,src/Makefile.in,src/content.c,
bears
parents: 227
diff changeset
413 }
52f467c7213b [svn] * docs/noffle.1,src/Makefile.am,src/Makefile.in,src/content.c,
bears
parents: 227
diff changeset
414