From: Adam Dickmeiss Date: Tue, 21 Nov 1995 15:01:14 +0000 (+0000) Subject: New general match criteria implemented. X-Git-Tag: ZEBRA.1.0~671 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=9f9b9eeb79d92c7793ffaba8805537bd401bdfbe;p=idzebra-moved-to-github.git New general match criteria implemented. New feature: document groups. --- diff --git a/index/extract.c b/index/extract.c index e65939d..76e4938 100644 --- a/index/extract.c +++ b/index/extract.c @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: extract.c,v $ - * Revision 1.28 1995-11-21 09:20:30 adam + * Revision 1.29 1995-11-21 15:01:14 adam + * New general match criteria implemented. + * New feature: document groups. + * + * Revision 1.28 1995/11/21 09:20:30 adam * Yet more work on record match. * * Revision 1.27 1995/11/20 16:59:45 adam @@ -105,7 +109,7 @@ #include "recindex.h" -static Dict file_idx; +static Dict matchDict; static Records records = NULL; @@ -115,6 +119,12 @@ static size_t ptr_i; static size_t key_buf_used; static int key_file_no; +static int records_inserted = 0; +static int records_updated = 0; +static int records_deleted = 0; + +#define MATCH_DICT "match" + void key_open (int mem) { if (mem < 50000) @@ -126,9 +136,9 @@ void key_open (int mem) key_buf_used = 0; key_file_no = 0; - if (!(file_idx = dict_open (FNAME_FILE_DICT, 40, 1))) + if (!(matchDict = dict_open (MATCH_DICT, 20, 1))) { - logf (LOG_FATAL, "dict_open fail of %s", "fileidx"); + logf (LOG_FATAL, "dict_open fail of %s", MATCH_DICT); exit (1); } assert (!records); @@ -247,8 +257,11 @@ int key_close (void) key_flush (); xfree (key_buf); rec_close (&records); - dict_close (file_idx); + dict_close (matchDict); + logf (LOG_LOG, "Records inserted %6d", records_inserted); + logf (LOG_LOG, "Records updated %6d", records_updated); + logf (LOG_LOG, "Records deleted %6d", records_deleted); return key_file_no; } @@ -333,6 +346,7 @@ static void flushRecordKeys (SYSNO sysno, int cmd, struct recKeys *reckeys, attrSet, attrUse, databaseName); while (*src) ((char*)key_buf) [key_buf_used++] = index_char_cvt (*src++); + src++; ((char*)key_buf) [key_buf_used++] = '\0'; ((char*) key_buf)[key_buf_used++] = cmd; @@ -344,89 +358,62 @@ static void flushRecordKeys (SYSNO sysno, int cmd, struct recKeys *reckeys, key_buf_used += sizeof(key); off = src - reckeys->buf; } - assert (off = reckeys->buf_used); + assert (off == reckeys->buf_used); } -#if 0 -static int key_cmd; -static int key_sysno; -static const char *key_databaseName; -static int key_del_max; -static int key_del_used; -static char *key_del_buf; - -static void wordAdd (const RecWord *p) +static const char **searchRecordKey (struct recKeys *reckeys, + int attrSetS, int attrUseS) { - struct it_key key; - size_t i; - - if (key_buf_used + 1024 > (ptr_top-ptr_i)*sizeof(char*)) - key_flush (); - ++ptr_i; - key_buf[ptr_top-ptr_i] = (char*)key_buf + key_buf_used; - key_buf_used += index_word_prefix ((char*)key_buf + key_buf_used, - p->attrSet, p->attrUse, - key_databaseName); - switch (p->which) - { - case Word_String: - for (i = 0; p->u.string[i]; i++) - ((char*)key_buf) [key_buf_used++] = - index_char_cvt (p->u.string[i]); - ((char*)key_buf) [key_buf_used++] = '\0'; - break; - default: - return ; - } - ((char*) key_buf)[key_buf_used++] = ((key_cmd == 'a') ? 1 : 0); - key.sysno = key_sysno; - key.seqno = p->seqno; - memcpy ((char*)key_buf + key_buf_used, &key, sizeof(key)); - key_buf_used += sizeof(key); + static const char *ws[32]; + int off = 0; + int startSeq = -1; + int i; - if (key_cmd == 'a' && key_del_used >= 0) + for (i = 0; i<32; i++) + ws[i] = NULL; + + while (off < reckeys->buf_used) { + const char *src = reckeys->buf + off; char attrSet; short attrUse; - if (key_del_used + 1024 > key_del_max) - { - char *kbn; - - if (!(kbn = malloc (key_del_max += 64000))) - { - logf (LOG_FATAL, "malloc"); - exit (1); - } - if (key_del_buf) - memcpy (kbn, key_del_buf, key_del_used); - free (key_del_buf); - key_del_buf = kbn; - } - switch (p->which) + int seqno; + const char *wstart; + + memcpy (&attrSet, src, sizeof(attrSet)); + src += sizeof(attrSet); + + memcpy (&attrUse, src, sizeof(attrUse)); + src += sizeof(attrUse); + + wstart = src; + while (*src++) + ; + + memcpy (&seqno, src, sizeof(seqno)); + src += sizeof(seqno); + +#if 0 + logf (LOG_LOG, "(%d,%d) %d %s", attrSet, attrUse, seqno, wstart); +#endif + if (attrUseS == attrUse && attrSetS == attrSet) { - case Word_String: - for (i = 0; p->u.string[i]; i++) - ((char*)key_del_buf) [key_del_used++] = p->u.string[i]; - ((char*)key_del_buf) [key_del_used++] = '\0'; - break; - default: - return ; - } - attrSet = p->attrSet; - memcpy (key_del_buf + key_del_used, &attrSet, sizeof(attrSet)); - key_del_used += sizeof(attrSet); + int woff; - attrUse = p->attrUse; - memcpy (key_del_buf + key_del_used, &attrUse, sizeof(attrUse)); - key_del_used += sizeof(attrUse); - memcpy (key_del_buf + key_del_used, &p->seqno, sizeof(p->seqno)); - key_del_used += sizeof(p->seqno); + if (startSeq == -1) + startSeq = seqno; + woff = seqno - startSeq; + if (woff >= 0 && woff < 31) + ws[woff] = wstart; + } + + off = src - reckeys->buf; } + assert (off == reckeys->buf_used); + return ws; } -#endif - static void addRecordKeyAny (const RecWord *p) { if (p->attrSet != 1 || p->attrUse != 1016) @@ -502,19 +489,156 @@ static int file_read (int fd, char *buf, size_t count) return count; } -int fileExtract (SYSNO *sysno, const char *fname, const char *databaseName, +static int atois (const char **s) +{ + int val = 0, c; + while ( (c=**s) >= '0' && c <= '9') + { + val = val*10 + c - '0'; + ++(*s); + } + return val; +} + +static char *fileMatchStr (struct recKeys *reckeys, struct recordGroup *rGroup, + const char *fname, + const char *recordType, + const char *spec) +{ + static char dstBuf[2048]; + char *dst = dstBuf; + const char *s = spec; + static const char **w; + int i; + + while (1) + { + while (*s == ' ' || *s == '\t') + s++; + if (!*s) + break; + if (*s == '(') + { + char matchFlag[32]; + int attrSet, attrUse; + int first = 1; + + s++; + attrSet = atois (&s); + if (*s != ',') + { + logf (LOG_WARN, "Missing , in match criteria %s in group %s", + spec, rGroup->groupName ? rGroup->groupName : "none"); + return NULL; + } + s++; + attrUse = atois (&s); + w = searchRecordKey (reckeys, attrSet, attrUse); + assert (w); + + if (*s == ')') + { + for (i = 0; i<32; i++) + matchFlag[i] = 1; + } + else + { + logf (LOG_WARN, "Missing ) in match criteria %s in group %s", + spec, rGroup->groupName ? rGroup->groupName : "none"); + return NULL; + } + s++; + + for (i = 0; i<32; i++) + if (matchFlag[i] && w[i]) + { + if (first) + { + *dst++ = ' '; + first = 0; + } + strcpy (dst, w[i]); + dst += strlen(w[i]); + } + if (first) + { + logf (LOG_WARN, "Record in file %s didn't contain match" + " fields in (%d,%d)", fname, attrSet, attrUse); + return NULL; + } + } + else if (*s == '$') + { + int spec_len; + char special[32]; + const char *spec_src = NULL; + const char *s1 = ++s; + while (*s1 && *s1 != ' ' && *s1 != '\t') + s1++; + + spec_len = s1 - s; + if (spec_len > 31) + spec_len = 31; + memcpy (special, s, spec_len); + special[spec_len] = '\0'; + s = s1; + + if (strcmp (special, "group")) + spec_src = rGroup->groupName; + else if (strcmp (special, "database")) + spec_src = rGroup->databaseName; + else if (strcmp (special, "filename")) + spec_src = fname; + else if (strcmp (special, "type")) + spec_src = recordType; + else + spec_src = NULL; + if (spec_src) + { + strcpy (dst, spec_src); + dst += strlen(spec_src); + } + } + else + { + logf (LOG_WARN, "Syntax error in match criteria %s in group %s", + spec, rGroup->groupName ? rGroup->groupName : "none"); + return NULL; + } + *dst++ = 1; + } + if (dst == dstBuf) + { + logf (LOG_WARN, "No match criteria for record %s in group %s", + fname, rGroup->groupName ? rGroup->groupName : "none"); + return NULL; + } + return dstBuf; +} + +int fileExtract (SYSNO *sysno, const char *fname, struct recordGroup *rGroup, int deleteFlag) { + SYSNO sysnotmp; int i, r; + char gprefix[128]; char ext[128]; char ext_res[128]; const char *file_type; + const char *file_match; struct recExtractCtrl extractCtrl; - RecType rt; + RecType recType; Record rec; + char *matchStr; + + if (!rGroup->groupName || !*rGroup->groupName) + *gprefix = '\0'; + else + sprintf (gprefix, "%s.", rGroup->groupName); logf (LOG_DEBUG, "fileExtractAdd %s", fname); + /* determine file extension */ for (i = strlen(fname); --i >= 0; ) if (fname[i] == '/') { @@ -526,18 +650,43 @@ int fileExtract (SYSNO *sysno, const char *fname, const char *databaseName, strcpy (ext, fname+i+1); break; } - sprintf (ext_res, "fileExtension.%s", ext); + /* determine file type - depending on extension */ + sprintf (ext_res, "%sfileExtension.%s", gprefix, ext); if (!(file_type = res_get (common_resource, ext_res))) return 0; - if (!(rt = recType_byName (file_type))) + if (!(recType = recType_byName (file_type))) return 0; + /* determine match criteria */ + sprintf (ext_res, "%sfileMatch.%s", gprefix, ext); + file_match = res_get (common_resource, ext_res); + if (!file_match) + { + sprintf (ext_res, "%sfileMatch", gprefix); + file_match = res_get (common_resource, ext_res); + } + + /* determine database name */ + if (!rGroup->databaseName) + { + sprintf (ext_res, "%sdatabase.%s", gprefix, ext); + if (!(rGroup->databaseName = res_get (common_resource, ext_res))) + { + sprintf (ext_res, "%sdatabase", gprefix); + rGroup->databaseName = res_get (common_resource, ext_res); + } + } + if (!rGroup->databaseName) + rGroup->databaseName = "Default"; + + /* open input file */ if ((extractCtrl.fd = open (fname, O_RDONLY)) == -1) { logf (LOG_WARN|LOG_ERRNO, "open %s", fname); return 0; } + /* extract keys */ extractCtrl.subType = ""; extractCtrl.init = wordInit; extractCtrl.add = addRecordKeyAny; @@ -545,7 +694,7 @@ int fileExtract (SYSNO *sysno, const char *fname, const char *databaseName, reckeys.buf_used = 0; file_read_start (extractCtrl.fd); extractCtrl.readf = file_read; - r = (*rt->extract)(&extractCtrl); + r = (*recType->extract)(&extractCtrl); file_read_stop (extractCtrl.fd); close (extractCtrl.fd); @@ -554,13 +703,44 @@ int fileExtract (SYSNO *sysno, const char *fname, const char *databaseName, logf (LOG_WARN, "Couldn't extract file %s, code %d", fname, r); return 0; } - if (! *sysno) /* match criteria */ + + /* perform match if sysno not known and if match criteria is specified */ + + matchStr = NULL; + if (!sysno && file_match) + { + char *rinfo; + + sysno = &sysnotmp; + matchStr = fileMatchStr(&reckeys, rGroup, fname, file_type, + file_match); + if (matchStr) + { + rinfo = dict_lookup (matchDict, matchStr); + if (rinfo) + memcpy (sysno, rinfo+1, sizeof(*sysno)); + else + *sysno = 0; + } + else + { + logf (LOG_WARN, "Record not inserted"); + return 0; + } + } + + /* new record ? */ + if (! *sysno) { logf (LOG_LOG, "add record %s", fname); rec = rec_new (records); *sysno = rec->sysno; - flushRecordKeys (*sysno, 1, &reckeys, databaseName); + if (matchStr) + dict_insert (matchDict, matchStr, sizeof(*sysno), sysno); + flushRecordKeys (*sysno, 1, &reckeys, rGroup->databaseName); + + records_inserted++; } else { @@ -571,7 +751,9 @@ int fileExtract (SYSNO *sysno, const char *fname, const char *databaseName, delkeys.buf_used = rec->size[2]; delkeys.buf = rec->info[2]; flushRecordKeys (*sysno, 0, &delkeys, rec->info[3]); - flushRecordKeys (*sysno, 1, &reckeys, databaseName); + flushRecordKeys (*sysno, 1, &reckeys, rGroup->databaseName); + + records_updated++; } free (rec->info[0]); rec->info[0] = rec_strdup (file_type, &rec->size[0]); @@ -592,7 +774,7 @@ int fileExtract (SYSNO *sysno, const char *fname, const char *databaseName, rec->size[2] = 0; } free (rec->info[3]); - rec->info[3] = rec_strdup (databaseName, &rec->size[3]); + rec->info[3] = rec_strdup (rGroup->databaseName, &rec->size[3]); rec_put (records, &rec); return 1; diff --git a/index/index.h b/index/index.h index 025c256..7c931e6 100644 --- a/index/index.h +++ b/index/index.h @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: index.h,v $ - * Revision 1.23 1995-11-20 16:59:45 adam + * Revision 1.24 1995-11-21 15:01:15 adam + * New general match criteria implemented. + * New feature: document groups. + * + * Revision 1.23 1995/11/20 16:59:45 adam * New update method: the 'old' keys are saved for each records. * * Revision 1.22 1995/11/20 11:56:26 adam @@ -106,6 +110,12 @@ struct dirs_entry { int ctime; }; +struct recordGroup { + char *groupName; + char *databaseName; + char *path; +}; + struct dirs_info *dirs_open (Dict dict, const char *rep); struct dirs_entry *dirs_read (struct dirs_info *p); struct dirs_entry *dirs_last (struct dirs_info *p); @@ -118,12 +128,9 @@ void dirs_free (struct dirs_info **pp); struct dir_entry *dir_open (const char *rep); void dir_sort (struct dir_entry *e); void dir_free (struct dir_entry **e_p); -void repository (int cmd, const char *rep, const char *base_path, - char *databaseName); -void repositoryUpdate (const char *path, char *databaseName); -SYSNO file_extract (int cmd, const char *fname, const char *kname, - char *databaseName); +void repositoryUpdate (struct recordGroup *rGroup); +void repositoryExtract (struct recordGroup *rGroup); void key_open (int mem); int key_close (void); @@ -156,5 +163,5 @@ int index_char_cvt (int c); int index_word_prefix (char *string, int attset_ordinal, int local_attribute, const char *databaseName); -int fileExtract (SYSNO *sysno, const char *fname, const char *databaseName, - int deleteFlag); +int fileExtract (SYSNO *sysno, const char *fname, + struct recordGroup *rGroup, int deleteFlag); diff --git a/index/main.c b/index/main.c index 92ea245..1650899 100644 --- a/index/main.c +++ b/index/main.c @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: main.c,v $ - * Revision 1.16 1995-11-20 11:56:27 adam + * Revision 1.17 1995-11-21 15:01:16 adam + * New general match criteria implemented. + * New feature: document groups. + * + * Revision 1.16 1995/11/20 11:56:27 adam * Work on new traversal. * * Revision 1.15 1995/11/01 16:25:51 quinn @@ -65,36 +69,35 @@ char *prog; size_t mem_max = 4*1024*1024; +extern char *data1_tabpath; int main (int argc, char **argv) { int ret; int cmd = 0; char *arg; - char *base_name = NULL; - char *base_path = NULL; - char *databaseName = "Default"; + char *configName = NULL; int nsections; int key_open_flag = 0; + struct recordGroup rGroup; + + rGroup.groupName = NULL; + rGroup.databaseName = NULL; + rGroup.path = NULL; + prog = *argv; - while ((ret = options ("r:v:m:d:", argv, argc, &arg)) != -2) + if (argc < 2) + { + fprintf (stderr, "index [-v log] [-m meg] [-c config] [-d base]" + " [-g group] cmd1 dir1 cmd2 dir2 ...\n"); + exit (1); + } + while ((ret = options ("c:g:v:m:d:", argv, argc, &arg)) != -2) { if (ret == 0) { - if (!base_name) - { - base_name = arg; - - common_resource = res_open (base_name); - if (!common_resource) - { - logf (LOG_FATAL, "Cannot open resource `%s'", base_name); - exit (1); - } - data1_tabpath = res_get(common_resource, "data1_tabpath"); - } - else if(cmd == 0) /* command */ + if(cmd == 0) /* command */ { if (!strcmp (arg, "add")) { @@ -104,6 +107,10 @@ int main (int argc, char **argv) { cmd = 'd'; } + else if (!strcmp (arg, "update")) + { + cmd = 'u'; + } else { logf (LOG_FATAL, "Unknown command: %s", arg); @@ -112,16 +119,34 @@ int main (int argc, char **argv) } else { + if (!common_resource) + { + common_resource = res_open (configName ? + configName : "base"); + if (!common_resource) + { + logf (LOG_FATAL, "Cannot open resource `%s'", + configName); + exit (1); + } + data1_tabpath = res_get (common_resource, "data1_tabpath"); + assert (data1_tabpath); + } if (!key_open_flag) { key_open (mem_max); key_open_flag = 1; } -#if 0 - repository (cmd, arg, base_path, databaseName); -#else - repositoryUpdate (arg, databaseName); -#endif + rGroup.path = arg; + if (cmd == 'u') + repositoryUpdate (&rGroup); + else if (cmd == 'a') + repositoryExtract (&rGroup); + else if (cmd == 'd') + { + logf (LOG_FATAL, "Not implemented yet."); + exit (1); + } cmd = 0; } } @@ -129,30 +154,26 @@ int main (int argc, char **argv) { log_init (log_mask_str(arg), prog, NULL); } - else if (ret == 'r') - { - base_path = arg; - } else if (ret == 'm') { mem_max = 1024*1024*atoi(arg); } else if (ret == 'd') { - databaseName = arg; + rGroup.databaseName = arg; + } + else if (ret == 'g') + { + rGroup.groupName = arg; } + else if (ret == 'c') + configName = arg; else { logf (LOG_FATAL, "Unknown option '-%s'", arg); exit (1); } } - if (!base_name) - { - fprintf (stderr, "index [-v log] [-r repository] [-m meg] [-d base]" - " base cmd1 dir1 cmd2 dir2 ...\n"); - exit (1); - } if (!key_open_flag) exit (0); nsections = key_close (); diff --git a/index/trav.c b/index/trav.c index 12fa18c..c929e51 100644 --- a/index/trav.c +++ b/index/trav.c @@ -4,7 +4,11 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: trav.c,v $ - * Revision 1.9 1995-11-21 09:20:32 adam + * Revision 1.10 1995-11-21 15:01:16 adam + * New general match criteria implemented. + * New feature: document groups. + * + * Revision 1.9 1995/11/21 09:20:32 adam * Yet more work on record match. * * Revision 1.8 1995/11/20 16:59:46 adam @@ -45,12 +49,17 @@ #include #include "index.h" -#if 0 -static void repository_extract_r (int cmd, char *rep, char *databaseName) +static int repComp (const char *a, const char *b, size_t len) +{ + if (!len) + return 0; + return memcmp (a, b, len); +} + +static void repositoryExtractR (char *rep, struct recordGroup *rGroup) { struct dir_entry *e; int i; - struct stat fs; size_t rep_len = strlen (rep); e = dir_open (rep); @@ -63,266 +72,23 @@ static void repository_extract_r (int cmd, char *rep, char *databaseName) for (i=0; e[i].name; i++) { strcpy (rep +rep_len+1, e[i].name); - stat (rep, &fs); - switch (fs.st_mode & S_IFMT) + switch (e[i].kind) { - case S_IFREG: - file_extract (cmd, rep, rep, databaseName); + case dirs_file: + fileExtract (NULL, rep, rGroup, 0); break; - case S_IFDIR: - repository_extract_r (cmd, rep, databaseName); + case dirs_dir: + repositoryExtractR (rep, rGroup); break; } } dir_free (&e); -} - -void copy_file (const char *dst, const char *src) -{ - int d_fd = open (dst, O_WRONLY|O_CREAT, 0666); - int s_fd = open (src, O_RDONLY); - char *buf; - size_t i, r, w; - - if (d_fd == -1) - { - logf (LOG_FATAL|LOG_ERRNO, "Cannot create %s", dst); - exit (1); - } - if (s_fd == -1) - { - logf (LOG_FATAL|LOG_ERRNO, "Cannot open %s", src); - exit (1); - } - buf = xmalloc (4096); - while ((r=read (s_fd, buf, 4096))>0) - for (w = 0; w < r; w += i) - { - i = write (d_fd, buf + w, r - w); - if (i == -1) - { - logf (LOG_FATAL|LOG_ERRNO, "write"); - exit (1); - } - } - if (r) - { - logf (LOG_FATAL|LOG_ERRNO, "read"); - exit (1); - } - xfree (buf); - close (d_fd); - close (s_fd); -} - -void del_file (const char *dst) -{ - unlink (dst); -} - -void del_dir (const char *dst) -{ - logf (LOG_DEBUG, "rmdir of %s", dst); - if (rmdir (dst) == -1) - logf (LOG_ERRNO|LOG_WARN, "rmdir"); -} - -void repository_update_r (int cmd, char *dst, char *src, char *databaseName); - -void repository_add_tree (int cmd, char *dst, char *src, char *databaseName) -{ - mkdir (dst, 0755); - repository_update_r (cmd, dst, src, databaseName); -} - -void repository_del_tree (int cmd, char *dst, char *src, char *databaseName) -{ - size_t dst_len = strlen (dst); - size_t src_len = strlen (src); - struct dir_entry *e_dst; - int i_dst = 0; - struct stat fs_dst; - - e_dst = dir_open (dst); - - dir_sort (e_dst); - - if (src[src_len-1] != '/') - src[src_len] = '/'; - else - --src_len; - if (dst[dst_len-1] != '/') - dst[dst_len] = '/'; - else - --dst_len; - while (e_dst[i_dst].name) - { - strcpy (dst +dst_len+1, e_dst[i_dst].name); - strcpy (src +src_len+1, e_dst[i_dst].name); - - stat (dst, &fs_dst); - switch (fs_dst.st_mode & S_IFMT) - { - case S_IFREG: - file_extract ('d', dst, dst, databaseName); - del_file (dst); - break; - case S_IFDIR: - repository_del_tree (cmd, dst, src, databaseName); - break; - } - i_dst++; - } - dir_free (&e_dst); - if (dst_len > 0) - { - dst[dst_len] = '\0'; - del_dir (dst); - } -} - -void repository_update_r (int cmd, char *dst, char *src, char *databaseName) -{ - struct dir_entry *e_dst, *e_src; - int i_dst = 0, i_src = 0; - struct stat fs_dst, fs_src; - size_t dst_len = strlen (dst); - size_t src_len = strlen (src); - - e_dst = dir_open (dst); - e_src = dir_open (src); - - if (!e_dst && !e_src) - return; - if (!e_dst) - { - dir_free (&e_src); - repository_add_tree (cmd, dst, src, databaseName); - return; - } - else if (!e_src) - { - dir_free (&e_dst); - repository_del_tree (cmd, dst, src, databaseName); - return; - } - - dir_sort (e_src); - dir_sort (e_dst); - - if (src[src_len-1] != '/') - src[src_len] = '/'; - else - --src_len; - if (dst[dst_len-1] != '/') - dst[dst_len] = '/'; - else - --dst_len; - while (e_dst[i_dst].name || e_src[i_src].name) - { - int sd; - - if (e_dst[i_dst].name && e_src[i_src].name) - sd = strcmp (e_dst[i_dst].name, e_src[i_src].name); - else if (e_src[i_src].name) - sd = 1; - else - sd = -1; - - if (sd == 0) - { - strcpy (dst +dst_len+1, e_dst[i_dst].name); - strcpy (src +src_len+1, e_src[i_src].name); - - /* check type, date, length */ - - stat (dst, &fs_dst); - stat (src, &fs_src); - - switch (fs_dst.st_mode & S_IFMT) - { - case S_IFREG: - if (fs_src.st_ctime > fs_dst.st_ctime) - { - file_extract ('d', dst, dst, databaseName); - file_extract ('a', src, dst, databaseName); - copy_file (dst, src); - } - break; - case S_IFDIR: - repository_update_r (cmd, dst, src, databaseName); - break; - } - i_src++; - i_dst++; - } - else if (sd > 0) - { - strcpy (dst +dst_len+1, e_src[i_src].name); - strcpy (src +src_len+1, e_src[i_src].name); - - stat (src, &fs_src); - switch (fs_src.st_mode & S_IFMT) - { - case S_IFREG: - file_extract ('a', src, dst, databaseName); - copy_file (dst, src); - break; - case S_IFDIR: - repository_add_tree (cmd, dst, src, databaseName); - break; - } - i_src++; - } - else - { - strcpy (dst +dst_len+1, e_dst[i_dst].name); - strcpy (src +src_len+1, e_dst[i_dst].name); - - stat (dst, &fs_dst); - switch (fs_dst.st_mode & S_IFMT) - { - case S_IFREG: - file_extract ('d', dst, dst, databaseName); - del_file (dst); - break; - case S_IFDIR: - repository_del_tree (cmd, dst, src, databaseName); - break; - } - i_dst++; - } - } - dir_free (&e_dst); - dir_free (&e_src); -} -void repository (int cmd, const char *rep, const char *base_path, - char *databaseName) -{ - char rep_tmp1[2048]; - char rep_tmp2[2048]; - - strcpy (rep_tmp1, rep); - if (base_path) - { - strcpy (rep_tmp2, base_path); - repository_update_r (cmd, rep_tmp2, rep_tmp1, databaseName); - } - else - repository_extract_r (cmd, rep_tmp1, databaseName); -} -#endif - -static int repComp (const char *a, const char *b, size_t len) -{ - if (!len) - return 0; - return memcmp (a, b, len); } static void repositoryUpdateR (struct dirs_info *di, struct dirs_entry *dst, - const char *base, char *src, char *databaseName) + const char *base, char *src, + struct recordGroup *rGroup) { struct dir_entry *e_src; int i_src = 0; @@ -394,13 +160,13 @@ static void repositoryUpdateR (struct dirs_info *di, struct dirs_entry *dst, case dirs_file: if (e_src[i_src].ctime > dst->ctime) { - if (fileExtract (&dst->sysno, tmppath, databaseName, 0)) + if (fileExtract (&dst->sysno, tmppath, rGroup, 0)) dirs_add (di, src, dst->sysno, e_src[i_src].ctime); } dst = dirs_read (di); break; case dirs_dir: - repositoryUpdateR (di, dst, base, src, databaseName); + repositoryUpdateR (di, dst, base, src, rGroup); dst = dirs_last (di); logf (LOG_DEBUG, "last is %s", dst ? dst->path : "null"); break; @@ -418,11 +184,11 @@ static void repositoryUpdateR (struct dirs_info *di, struct dirs_entry *dst, switch (e_src[i_src].kind) { case dirs_file: - if (fileExtract (&sysno, tmppath, databaseName, 0)) + if (fileExtract (&sysno, tmppath, rGroup, 0)) dirs_add (di, src, sysno, e_src[i_src].ctime); break; case dirs_dir: - repositoryUpdateR (di, dst, base, src, databaseName); + repositoryUpdateR (di, dst, base, src, rGroup); if (dst) dst = dirs_last (di); break; @@ -437,18 +203,28 @@ static void repositoryUpdateR (struct dirs_info *di, struct dirs_entry *dst, dir_free (&e_src); } -void repositoryUpdate (const char *path, char *databaseName) +void repositoryUpdate (struct recordGroup *rGroup) { struct dirs_info *di; char src[256]; Dict dict; dict = dict_open ("repdict", 40, 1); - - di = dirs_open (dict, path); + + assert (rGroup->path); + di = dirs_open (dict, rGroup->path); strcpy (src, ""); - repositoryUpdateR (di, dirs_read (di), path, src, databaseName); + repositoryUpdateR (di, dirs_read (di), rGroup->path, src, rGroup); dirs_free (&di); dict_close (dict); } + +void repositoryExtract (struct recordGroup *rGroup) +{ + char src[256]; + + assert (rGroup->path); + strcpy (src, rGroup->path); + repositoryExtractR (src, rGroup); +}