2 * Copyright (C) 1994-1995, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.11 1995-11-22 17:19:19 adam
8 * Record management uses the bfile system.
10 * Revision 1.10 1995/11/21 15:01:16 adam
11 * New general match criteria implemented.
12 * New feature: document groups.
14 * Revision 1.9 1995/11/21 09:20:32 adam
15 * Yet more work on record match.
17 * Revision 1.8 1995/11/20 16:59:46 adam
18 * New update method: the 'old' keys are saved for each records.
20 * Revision 1.7 1995/11/20 11:56:28 adam
21 * Work on new traversal.
23 * Revision 1.6 1995/11/17 15:54:42 adam
24 * Started work on virtual directory structure.
26 * Revision 1.5 1995/10/17 18:02:09 adam
27 * New feature: databases. Implemented as prefix to words in dictionary.
29 * Revision 1.4 1995/09/28 09:19:46 adam
30 * xfree/xmalloc used everywhere.
31 * Extract/retrieve method seems to work for text records.
33 * Revision 1.3 1995/09/06 16:11:18 adam
34 * Option: only one word key per file.
36 * Revision 1.2 1995/09/04 12:33:43 adam
37 * Various cleanup. YAZ util used instead.
39 * Revision 1.1 1995/09/01 14:06:36 adam
40 * Split of work into more files.
48 #include <sys/types.h>
55 static int repComp (const char *a, const char *b, size_t len)
59 return memcmp (a, b, len);
62 static void repositoryExtractR (int deleteFlag, char *rep,
63 struct recordGroup *rGroup)
67 size_t rep_len = strlen (rep);
72 if (rep[rep_len-1] != '/')
76 for (i=0; e[i].name; i++)
78 strcpy (rep +rep_len+1, e[i].name);
82 fileExtract (NULL, rep, rGroup, deleteFlag);
85 repositoryExtractR (deleteFlag, rep, rGroup);
93 static void repositoryUpdateR (struct dirs_info *di, struct dirs_entry *dst,
94 const char *base, char *src,
95 struct recordGroup *rGroup)
97 struct dir_entry *e_src;
99 static char tmppath[256];
100 size_t src_len = strlen (src);
102 sprintf (tmppath, "%s%s", base, src);
103 e_src = dir_open (tmppath);
106 if (!dst || repComp (dst->path, src, src_len))
108 if (!dst || strcmp (dst->path, src))
113 if (src_len && src[src_len-1] == '/')
117 src[src_len+1] = '\0';
118 dirs_mkdir (di, src, 0);
123 /* delete tree dst */
128 if (src_len && src[src_len-1] == '/')
132 src[src_len+1] = '\0';
133 dst = dirs_read (di);
141 if (dst && !repComp (dst->path, src, src_len+1))
143 if (e_src[i_src].name)
145 logf (LOG_DEBUG, "dst=%s src=%s", dst->path + src_len+1,
147 sd = strcmp (dst->path + src_len+1, e_src[i_src].name);
152 else if (e_src[i_src].name)
156 logf (LOG_DEBUG, "trav sd=%d", sd);
159 strcpy (src + src_len+1, e_src[i_src].name);
160 sprintf (tmppath, "%s%s", base, src);
162 switch (e_src[i_src].kind)
165 if (e_src[i_src].ctime > dst->ctime)
167 if (fileExtract (&dst->sysno, tmppath, rGroup, 0))
168 dirs_add (di, src, dst->sysno, e_src[i_src].ctime);
170 dst = dirs_read (di);
173 repositoryUpdateR (di, dst, base, src, rGroup);
174 dst = dirs_last (di);
175 logf (LOG_DEBUG, "last is %s", dst ? dst->path : "null");
178 dst = dirs_read (di);
185 strcpy (src + src_len+1, e_src[i_src].name);
186 sprintf (tmppath, "%s%s", base, src);
188 switch (e_src[i_src].kind)
191 if (fileExtract (&sysno, tmppath, rGroup, 0))
192 dirs_add (di, src, sysno, e_src[i_src].ctime);
195 repositoryUpdateR (di, dst, base, src, rGroup);
197 dst = dirs_last (di);
210 void repositoryUpdate (struct recordGroup *rGroup)
212 struct dirs_info *di;
216 dict = dict_open ("repdict", 40, 1);
218 assert (rGroup->path);
219 di = dirs_open (dict, rGroup->path);
221 repositoryUpdateR (di, dirs_read (di), rGroup->path, src, rGroup);
227 void repositoryDelete (struct recordGroup *rGroup)
231 assert (rGroup->path);
232 strcpy (src, rGroup->path);
233 repositoryExtractR (1, src, rGroup);
236 void repositoryAdd (struct recordGroup *rGroup)
240 assert (rGroup->path);
241 strcpy (src, rGroup->path);
242 repositoryExtractR (0, src, rGroup);