2 * Copyright (C) 1994-1995, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.6 1995-11-17 15:54:42 adam
8 * Started work on virtual directory structure.
10 * Revision 1.5 1995/10/17 18:02:09 adam
11 * New feature: databases. Implemented as prefix to words in dictionary.
13 * Revision 1.4 1995/09/28 09:19:46 adam
14 * xfree/xmalloc used everywhere.
15 * Extract/retrieve method seems to work for text records.
17 * Revision 1.3 1995/09/06 16:11:18 adam
18 * Option: only one word key per file.
20 * Revision 1.2 1995/09/04 12:33:43 adam
21 * Various cleanup. YAZ util used instead.
23 * Revision 1.1 1995/09/01 14:06:36 adam
24 * Split of work into more files.
32 #include <sys/types.h>
39 static void repository_extract_r (int cmd, char *rep, char *databaseName)
44 size_t rep_len = strlen (rep);
49 if (rep[rep_len-1] != '/')
53 for (i=0; e[i].name; i++)
55 strcpy (rep +rep_len+1, e[i].name);
57 switch (fs.st_mode & S_IFMT)
60 file_extract (cmd, rep, rep, databaseName);
63 repository_extract_r (cmd, rep, databaseName);
70 void copy_file (const char *dst, const char *src)
72 int d_fd = open (dst, O_WRONLY|O_CREAT, 0666);
73 int s_fd = open (src, O_RDONLY);
79 logf (LOG_FATAL|LOG_ERRNO, "Cannot create %s", dst);
84 logf (LOG_FATAL|LOG_ERRNO, "Cannot open %s", src);
88 while ((r=read (s_fd, buf, 4096))>0)
89 for (w = 0; w < r; w += i)
91 i = write (d_fd, buf + w, r - w);
94 logf (LOG_FATAL|LOG_ERRNO, "write");
100 logf (LOG_FATAL|LOG_ERRNO, "read");
108 void del_file (const char *dst)
113 void del_dir (const char *dst)
115 logf (LOG_DEBUG, "rmdir of %s", dst);
116 if (rmdir (dst) == -1)
117 logf (LOG_ERRNO|LOG_WARN, "rmdir");
120 void repository_update_r (int cmd, char *dst, char *src, char *databaseName);
122 void repository_add_tree (int cmd, char *dst, char *src, char *databaseName)
125 repository_update_r (cmd, dst, src, databaseName);
128 void repository_del_tree (int cmd, char *dst, char *src, char *databaseName)
130 size_t dst_len = strlen (dst);
131 size_t src_len = strlen (src);
132 struct dir_entry *e_dst;
136 e_dst = dir_open (dst);
140 if (src[src_len-1] != '/')
144 if (dst[dst_len-1] != '/')
148 while (e_dst[i_dst].name)
150 strcpy (dst +dst_len+1, e_dst[i_dst].name);
151 strcpy (src +src_len+1, e_dst[i_dst].name);
154 switch (fs_dst.st_mode & S_IFMT)
157 file_extract ('d', dst, dst, databaseName);
161 repository_del_tree (cmd, dst, src, databaseName);
174 void repository_update_r (int cmd, char *dst, char *src, char *databaseName)
176 struct dir_entry *e_dst, *e_src;
177 int i_dst = 0, i_src = 0;
178 struct stat fs_dst, fs_src;
179 size_t dst_len = strlen (dst);
180 size_t src_len = strlen (src);
182 e_dst = dir_open (dst);
183 e_src = dir_open (src);
185 if (!e_dst && !e_src)
190 repository_add_tree (cmd, dst, src, databaseName);
196 repository_del_tree (cmd, dst, src, databaseName);
203 if (src[src_len-1] != '/')
207 if (dst[dst_len-1] != '/')
211 while (e_dst[i_dst].name || e_src[i_src].name)
215 if (e_dst[i_dst].name && e_src[i_src].name)
216 sd = strcmp (e_dst[i_dst].name, e_src[i_src].name);
217 else if (e_src[i_src].name)
224 strcpy (dst +dst_len+1, e_dst[i_dst].name);
225 strcpy (src +src_len+1, e_src[i_src].name);
227 /* check type, date, length */
232 switch (fs_dst.st_mode & S_IFMT)
235 if (fs_src.st_ctime > fs_dst.st_ctime)
237 file_extract ('d', dst, dst, databaseName);
238 file_extract ('a', src, dst, databaseName);
239 copy_file (dst, src);
243 repository_update_r (cmd, dst, src, databaseName);
251 strcpy (dst +dst_len+1, e_src[i_src].name);
252 strcpy (src +src_len+1, e_src[i_src].name);
255 switch (fs_src.st_mode & S_IFMT)
258 file_extract ('a', src, dst, databaseName);
259 copy_file (dst, src);
262 repository_add_tree (cmd, dst, src, databaseName);
269 strcpy (dst +dst_len+1, e_dst[i_dst].name);
270 strcpy (src +src_len+1, e_dst[i_dst].name);
273 switch (fs_dst.st_mode & S_IFMT)
276 file_extract ('d', dst, dst, databaseName);
280 repository_del_tree (cmd, dst, src, databaseName);
290 void repository (int cmd, const char *rep, const char *base_path,
296 strcpy (rep_tmp1, rep);
299 strcpy (rep_tmp2, base_path);
300 repository_update_r (cmd, rep_tmp2, rep_tmp1, databaseName);
303 repository_extract_r (cmd, rep_tmp1, databaseName);
306 void repositoryUpdate (const char *src, char *databaseName)
308 struct dir_entry *e_src;
311 size_t src_len = strlen (src);
313 e_src = dir_open (src);