annotate 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
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
219
d9f314014f7a [svn] * src/content.c: Remove spurious temporary files and add a closedir()
bears
parents: 218
diff changeset
4 $Id: content.c 338 2001-11-29 22:16:06Z 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 ] ) ) ) )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
53 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
54 Log_err( "Could not realloc overview list" );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
55 exit( EXIT_FAILURE );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
56 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
57 cont.max += 500;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
58 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
59 ASSERT( cont.vecFirst > 0 );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
60 if ( ov )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
61 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
62 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
63 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
64 cont.dirty = TRUE;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
65 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
66
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
67 Bool
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
68 Cont_validNumb( int n )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
69 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
70 return ( n != 0 && n >= cont.first && n <= cont.last
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
71 && 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
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 )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
94 del_Over( cont.elem[ i ] );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
95 cont.size = 0;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
96 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
97
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
98 static void
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
99 setupEmpty( const char *name )
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 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
102 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
103 ASSERT( cont.first > 0 );
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
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
106 /* 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
107 static void
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
108 extendCont( int cnt )
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 int i, n;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
111
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
112 if ( cont.size < 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 n = cnt - cont.size;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
115 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
116 Cont_app( NULL );
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 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
119
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
120 /* 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
121 from its overviews file. */
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
122 void
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
123 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
124 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
125 FILE *f;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
126 Over *ov;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
127 int numb;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
128 Str line;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
129
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
130 /* 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
131 cont.vecFirst = 0;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
132 cont.first = 0;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
133 cont.last = 0;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
134 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
135 clearCont();
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
136
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
137 /* 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
138 list */
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
139 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
140 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
141 if ( ! f )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
142 {
185
fed1334d766b [svn] * src/client.c: Change variable only used on constant to 'const'.
bears
parents: 167
diff changeset
143 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
144 setupEmpty( name );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
145 return;
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, "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
148 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
149 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
150 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
151 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
152 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
153 continue;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
154 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
155 numb = Ov_numb( ov );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
156 if ( numb < cont.first )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
157 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
158 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
159 continue;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
160 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
161 if ( cont.first == 0 )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
162 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
163 cont.last = numb;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
164 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
165 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
166 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
167 fclose( f );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
168
196
60a70c16d79c [svn] * src/content.c: When generating temp file to write new content to, make
bears
parents: 188
diff changeset
169
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
170 if ( cont.first == 0 )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
171 setupEmpty( name ); /* Corrupt overview file recovery */
96
988cacc01470 [svn] Preserve group last number if last article(s) cancelled
bears
parents: 75
diff changeset
172 else
988cacc01470 [svn] Preserve group last number if last article(s) cancelled
bears
parents: 75
diff changeset
173 {
988cacc01470 [svn] Preserve group last number if last article(s) cancelled
bears
parents: 75
diff changeset
174 int grpLast;
988cacc01470 [svn] Preserve group last number if last article(s) cancelled
bears
parents: 75
diff changeset
175
988cacc01470 [svn] Preserve group last number if last article(s) cancelled
bears
parents: 75
diff changeset
176 /*
988cacc01470 [svn] Preserve group last number if last article(s) cancelled
bears
parents: 75
diff changeset
177 Check for end article(s) being cancelled. Need to ensure we
988cacc01470 [svn] Preserve group last number if last article(s) cancelled
bears
parents: 75
diff changeset
178 don't re-use and article number.
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 grpLast = Grp_last( name );
988cacc01470 [svn] Preserve group last number if last article(s) cancelled
bears
parents: 75
diff changeset
181 if ( cont.last < grpLast )
988cacc01470 [svn] Preserve group last number if last article(s) cancelled
bears
parents: 75
diff changeset
182 extendCont( grpLast - cont.first + 1 );
988cacc01470 [svn] Preserve group last number if last article(s) cancelled
bears
parents: 75
diff changeset
183 }
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
184 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
185
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
186 void
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
187 Cont_write( void )
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 Bool anythingWritten;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
190 int i;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
191 FILE *f;
75
22b3e3dfc8c2 [svn] Preserve gen info sometimes
bears
parents: 59
diff changeset
192 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
193 Str tmpfname;
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
194 Bool writeErr;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
195
167
7ba337dafb2c [svn] * TODO,content.c,lock.c,server.c,server.h: Remove bug notice re:
bears
parents: 96
diff changeset
196 /* 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
197 if ( ! cont.dirty )
7ba337dafb2c [svn] * TODO,content.c,lock.c,server.c,server.h: Remove bug notice re:
bears
parents: 96
diff changeset
198 return;
7ba337dafb2c [svn] * TODO,content.c,lock.c,server.c,server.h: Remove bug notice re:
bears
parents: 96
diff changeset
199
188
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
200 /* Save the overview to temporary file in same dir. */
213
f0acb9366e4f [svn] minor bugfix in Conf_write()
mirkol
parents: 197
diff changeset
201 /* 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
202 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
203 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
204 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
205 {
188
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
206 Log_err( "Could not open %s for writing", tmpfname );
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
207 return;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
208 }
188
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
209 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
210 anythingWritten = FALSE;
49
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
211 cont.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
212 writeErr = FALSE;
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
213
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
214 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
215 {
75
22b3e3dfc8c2 [svn] Preserve gen info sometimes
bears
parents: 59
diff changeset
216 ov = cont.elem[ i ];
22b3e3dfc8c2 [svn] Preserve gen info sometimes
bears
parents: 59
diff changeset
217 if ( ov )
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
218 {
75
22b3e3dfc8c2 [svn] Preserve gen info sometimes
bears
parents: 59
diff changeset
219 if ( i + 1 < cont.size )
22b3e3dfc8c2 [svn] Preserve gen info sometimes
bears
parents: 59
diff changeset
220 ov_next = cont.elem[ i + 1 ];
22b3e3dfc8c2 [svn] Preserve gen info sometimes
bears
parents: 59
diff changeset
221 else
22b3e3dfc8c2 [svn] Preserve gen info sometimes
bears
parents: 59
diff changeset
222 ov_next = NULL;
22b3e3dfc8c2 [svn] Preserve gen info sometimes
bears
parents: 59
diff changeset
223
22b3e3dfc8c2 [svn] Preserve gen info sometimes
bears
parents: 59
diff changeset
224 /*
22b3e3dfc8c2 [svn] Preserve gen info sometimes
bears
parents: 59
diff changeset
225 Preserve gen info if it is followed immediately by an
22b3e3dfc8c2 [svn] Preserve gen info sometimes
bears
parents: 59
diff changeset
226 article with the next number. In practice, this means
22b3e3dfc8c2 [svn] Preserve gen info sometimes
bears
parents: 59
diff changeset
227 that when in auto-subscribed mode, the gen info will
22b3e3dfc8c2 [svn] Preserve gen info sometimes
bears
parents: 59
diff changeset
228 remain until the 'group now subscribed' message is
22b3e3dfc8c2 [svn] Preserve gen info sometimes
bears
parents: 59
diff changeset
229 expired.
22b3e3dfc8c2 [svn] Preserve gen info sometimes
bears
parents: 59
diff changeset
230 */
22b3e3dfc8c2 [svn] Preserve gen info sometimes
bears
parents: 59
diff changeset
231 if ( ! Pseudo_isGeneralInfo( Ov_msgId( ov ) )
22b3e3dfc8c2 [svn] Preserve gen info sometimes
bears
parents: 59
diff changeset
232 || ( ov_next != NULL &&
22b3e3dfc8c2 [svn] Preserve gen info sometimes
bears
parents: 59
diff changeset
233 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
234 {
188
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
235 anythingWritten = TRUE;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
236 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
237 {
188
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
238 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
239 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
240 writeErr = TRUE;
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
241 break;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
242 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
243 else
49
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
244 {
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
245 if ( cont.first < 0 )
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
246 cont.first = cont.vecFirst + i;
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
247 }
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
248 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
249 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
250 }
188
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
251 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
252 {
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
253 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
254 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
255 writeErr = TRUE;
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
256 }
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
257
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
258 /*
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
259 If empty, remove the overview file and set set first to one
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
260 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
261 */
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
262 if ( ! anythingWritten )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
263 {
213
f0acb9366e4f [svn] minor bugfix in Conf_write()
mirkol
parents: 197
diff changeset
264 if ( unlink( tmpfname ) < 0 )
f0acb9366e4f [svn] minor bugfix in Conf_write()
mirkol
parents: 197
diff changeset
265 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
266 if ( unlink( cont.file ) < 0 )
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
267 Log_err( "Unlink of %s failed: %s", cont.file, strerror( errno ) );
188
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
268 else
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
269 {
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
270 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
271 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
272 }
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
273 }
188
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
274 else if ( ! writeErr )
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
275 {
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
276 if ( rename( tmpfname, cont.file ) < 0 )
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
277 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
278 tmpfname, cont.file, strerror( errno ) );
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
279 else
f1bacee93ca6 [svn] * src/client.c,src/client.h,src/fetch.c,src/noffle.c,src/server.c:
bears
parents: 185
diff changeset
280 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
281 }
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
282 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
283
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
284 const Over *
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
285 Cont_get( int numb )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
286 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
287 if ( ! Cont_validNumb( numb ) )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
288 return NULL;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
289 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
290 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
291
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
292 int
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
293 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
294
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
295 int
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
296 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
297
49
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
298 int
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
299 Cont_find( const char *msgId )
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
300 {
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
301 int i;
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
302 const Over *ov;
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
303
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
304 for ( i = 0; i < cont.size; i++ )
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
305 {
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
306 if ( ( ov = cont.elem[ i ] )
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
307 && strcmp( Ov_msgId( ov ), msgId ) == 0 )
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
308 return i + cont.vecFirst;
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
309 }
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
310
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
311 return -1;
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
312 }
5ecb646acf97 [svn] Article numbering bug fixes
bears
parents: 45
diff changeset
313
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
314 const char *
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
315 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
316
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
317 Bool
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
318 Cont_nextGrp( Str result )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
319 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
320 struct dirent *d;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
321
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
322 ASSERT( cont.dir );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
323 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
324 {
219
d9f314014f7a [svn] * src/content.c: Remove spurious temporary files and add a closedir()
bears
parents: 218
diff changeset
325 closedir( cont.dir );
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
326 cont.dir = NULL;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
327 return FALSE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
328 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
329 if ( ! d->d_name )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
330 return FALSE;
218
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
331 if ( d->d_name[0] == '.' )
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
332 {
219
d9f314014f7a [svn] * src/content.c: Remove spurious temporary files and add a closedir()
bears
parents: 218
diff changeset
333 Str tmpfname;
d9f314014f7a [svn] * src/content.c: Remove spurious temporary files and add a closedir()
bears
parents: 218
diff changeset
334
218
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
335 /*
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
336 * If it is '.' or '..', skip.
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
337 * 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
338 * 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
339 */
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
340 switch( d->d_name[1] )
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
341 {
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
342 case '\0':
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
343 case '.':
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
344 break;
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
345
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
346 case '#':
219
d9f314014f7a [svn] * src/content.c: Remove spurious temporary files and add a closedir()
bears
parents: 218
diff changeset
347 snprintf( tmpfname, MAXCHAR, "%s/overview/.#%d.%s",
d9f314014f7a [svn] * src/content.c: Remove spurious temporary files and add a closedir()
bears
parents: 218
diff changeset
348 Cfg_spoolDir(), (int) getpid(), d->d_name );
d9f314014f7a [svn] * src/content.c: Remove spurious temporary files and add a closedir()
bears
parents: 218
diff changeset
349 Log_err( "Bad temporary file %s - please delete",
d9f314014f7a [svn] * src/content.c: Remove spurious temporary files and add a closedir()
bears
parents: 218
diff changeset
350 tmpfname );
d9f314014f7a [svn] * src/content.c: Remove spurious temporary files and add a closedir()
bears
parents: 218
diff changeset
351 if ( unlink( tmpfname ) < 0 )
d9f314014f7a [svn] * src/content.c: Remove spurious temporary files and add a closedir()
bears
parents: 218
diff changeset
352 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
353 tmpfname, strerror(errno) );
218
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
354 break;
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
355
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
356 default:
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
357 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
358 d->d_name, Cfg_spoolDir() );
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
359 break;
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
360 }
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
361 return Cont_nextGrp( result );
411b6ab1acb7 [svn] *src/content.c,src/noffle.c: Correct bugfix in Conf_write().
bears
parents: 213
diff changeset
362 }
43
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
363 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
364 result[ MAXCHAR - 1 ] = '\0';
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
365 return TRUE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
366 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
367
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
368 Bool
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
369 Cont_firstGrp( Str result )
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
370 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
371 Str name;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
372
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
373 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
374 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
375 {
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
376 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
377 return FALSE;
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
378 }
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
379 return Cont_nextGrp( result );
2842f50feb55 [svn] * client.c, client.h, common.h, config.c, config.h, content.c, content.h,
uh1763
parents:
diff changeset
380 }