2 * Copyright (C) 1995, Index Data I/S
4 * Sebastian Hammer, Adam Dickmeiss
7 * Revision 1.2 1995-09-04 12:33:43 adam
8 * Various cleanup. YAZ util used instead.
10 * Revision 1.1 1995/09/01 14:06:36 adam
11 * Split of work into more files.
19 #include <sys/types.h>
26 static void repository_extract_r (int cmd, char *rep)
31 size_t rep_len = strlen (rep);
36 if (rep[rep_len-1] != '/')
40 for (i=0; e[i].name; i++)
42 strcpy (rep +rep_len+1, e[i].name);
44 switch (fs.st_mode & S_IFMT)
47 file_extract (cmd, rep, rep);
50 repository_extract_r (cmd, rep);
57 void copy_file (const char *dst, const char *src)
59 int d_fd = open (dst, O_WRONLY|O_CREAT, 0666);
60 int s_fd = open (src, O_RDONLY);
66 logf (LOG_FATAL|LOG_ERRNO, "Cannot create %s", dst);
71 logf (LOG_FATAL|LOG_ERRNO, "Cannot open %s", src);
74 if (!(buf = malloc (4096)))
76 logf (LOG_FATAL|LOG_ERRNO, "malloc");
79 while ((r=read (s_fd, buf, 4096))>0)
80 for (w = 0; w < r; w += i)
82 i = write (d_fd, buf + w, r - w);
85 logf (LOG_FATAL|LOG_ERRNO, "write");
91 logf (LOG_FATAL|LOG_ERRNO, "read");
99 void del_file (const char *dst)
104 void del_dir (const char *dst)
106 logf (LOG_DEBUG, "rmdir of %s", dst);
107 if (rmdir (dst) == -1)
108 logf (LOG_ERRNO|LOG_WARN, "rmdir");
111 void repository_update_r (int cmd, char *dst, char *src);
113 void repository_add_tree (int cmd, char *dst, char *src)
116 repository_update_r (cmd, dst, src);
119 void repository_del_tree (int cmd, char *dst, char *src)
121 size_t dst_len = strlen (dst);
122 size_t src_len = strlen (src);
123 struct dir_entry *e_dst;
127 e_dst = dir_open (dst);
131 if (src[src_len-1] != '/')
135 if (dst[dst_len-1] != '/')
139 while (e_dst[i_dst].name)
141 strcpy (dst +dst_len+1, e_dst[i_dst].name);
142 strcpy (src +src_len+1, e_dst[i_dst].name);
145 switch (fs_dst.st_mode & S_IFMT)
148 file_extract ('d', dst, dst);
152 repository_del_tree (cmd, dst, src);
165 void repository_update_r (int cmd, char *dst, char *src)
167 struct dir_entry *e_dst, *e_src;
168 int i_dst = 0, i_src = 0;
169 struct stat fs_dst, fs_src;
170 size_t dst_len = strlen (dst);
171 size_t src_len = strlen (src);
173 e_dst = dir_open (dst);
174 e_src = dir_open (src);
176 if (!e_dst && !e_src)
181 repository_add_tree (cmd, dst, src);
187 repository_del_tree (cmd, dst, src);
194 if (src[src_len-1] != '/')
198 if (dst[dst_len-1] != '/')
202 while (e_dst[i_dst].name || e_src[i_src].name)
206 if (e_dst[i_dst].name && e_src[i_src].name)
207 sd = strcmp (e_dst[i_dst].name, e_src[i_src].name);
208 else if (e_src[i_src].name)
215 strcpy (dst +dst_len+1, e_dst[i_dst].name);
216 strcpy (src +src_len+1, e_src[i_src].name);
218 /* check type, date, length */
223 switch (fs_dst.st_mode & S_IFMT)
226 if (fs_src.st_ctime > fs_dst.st_ctime)
228 file_extract ('d', dst, dst);
229 file_extract ('a', src, dst);
230 copy_file (dst, src);
234 repository_update_r (cmd, dst, src);
242 strcpy (dst +dst_len+1, e_src[i_src].name);
243 strcpy (src +src_len+1, e_src[i_src].name);
246 switch (fs_src.st_mode & S_IFMT)
249 file_extract ('a', src, dst);
250 copy_file (dst, src);
253 repository_add_tree (cmd, dst, src);
260 strcpy (dst +dst_len+1, e_dst[i_dst].name);
261 strcpy (src +src_len+1, e_dst[i_dst].name);
264 switch (fs_dst.st_mode & S_IFMT)
267 file_extract ('d', dst, dst);
271 repository_del_tree (cmd, dst, src);
281 void repository (int cmd, const char *rep, const char *base_path)
286 strcpy (rep_tmp1, rep);
289 strcpy (rep_tmp2, base_path);
290 repository_update_r (cmd, rep_tmp2, rep_tmp1);
293 repository_extract_r (cmd, rep_tmp1);