X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=index%2Ftrav.c;h=78746c4894fc89c412f02c75334cd44cb371d41e;hb=85df66537199c30a492ad54be4fbe25fa77e18c8;hp=c929e51de2145b9433ec5fcd903e879cc33724ee;hpb=9f9b9eeb79d92c7793ffaba8805537bd401bdfbe;p=idzebra-moved-to-github.git diff --git a/index/trav.c b/index/trav.c index c929e51..78746c4 100644 --- a/index/trav.c +++ b/index/trav.c @@ -4,7 +4,31 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: trav.c,v $ - * Revision 1.10 1995-11-21 15:01:16 adam + * Revision 1.15 1995-12-07 17:38:48 adam + * Work locking mechanisms for concurrent updates/commit. + * + * Revision 1.14 1995/12/06 12:41:26 adam + * New command 'stat' for the index program. + * Filenames can be read from stdin by specifying '-'. + * Bug fix/enhancement of the transformation from terms to regular + * expressons in the search engine. + * + * Revision 1.13 1995/11/28 09:09:46 adam + * Zebra config renamed. + * Use setting 'recordId' to identify record now. + * Bug fix in recindex.c: rec_release_blocks was invokeded even + * though the blocks were already released. + * File traversal properly deletes records when needed. + * + * Revision 1.12 1995/11/24 11:31:37 adam + * Commands add & del read filenames from stdin if source directory is + * empty. + * Match criteria supports 'constant' strings. + * + * Revision 1.11 1995/11/22 17:19:19 adam + * Record management uses the bfile system. + * + * Revision 1.10 1995/11/21 15:01:16 adam * New general match criteria implemented. * New feature: document groups. * @@ -56,7 +80,8 @@ static int repComp (const char *a, const char *b, size_t len) return memcmp (a, b, len); } -static void repositoryExtractR (char *rep, struct recordGroup *rGroup) +static void repositoryExtractR (int deleteFlag, char *rep, + struct recordGroup *rGroup) { struct dir_entry *e; int i; @@ -75,10 +100,10 @@ static void repositoryExtractR (char *rep, struct recordGroup *rGroup) switch (e[i].kind) { case dirs_file: - fileExtract (NULL, rep, rGroup, 0); + fileExtract (NULL, rep, rGroup, deleteFlag); break; case dirs_dir: - repositoryExtractR (rep, rGroup); + repositoryExtractR (deleteFlag, rep, rGroup); break; } } @@ -86,6 +111,45 @@ static void repositoryExtractR (char *rep, struct recordGroup *rGroup) } +static void stdinExtractR (int deleteFlag, struct recordGroup *rGroup) +{ + char tmppath[256]; + + logf (LOG_LOG, "stdinExtractR"); + while (scanf ("%s", tmppath) == 1) + fileExtract (NULL, tmppath, rGroup, deleteFlag); +} + +static void repositoryDeleteR (struct dirs_info *di, struct dirs_entry *dst, + const char *base, char *src, + struct recordGroup *rGroup) +{ + char tmppath[256]; + size_t src_len = strlen (src); + + while (dst && !repComp (dst->path, src, src_len+1)) + { + switch (dst->kind) + { + case dirs_file: + sprintf (tmppath, "%s%s", base, dst->path); + fileExtract (&dst->sysno, tmppath, rGroup, 1); + + strcpy (tmppath, dst->path); + dst = dirs_read (di); + dirs_del (di, tmppath); + break; + case dirs_dir: + strcpy (tmppath, dst->path); + dst = dirs_read (di); + dirs_rmdir (di, tmppath); + break; + default: + dst = dirs_read (di); + } + } +} + static void repositoryUpdateR (struct dirs_info *di, struct dirs_entry *dst, const char *base, char *src, struct recordGroup *rGroup) @@ -116,7 +180,8 @@ static void repositoryUpdateR (struct dirs_info *di, struct dirs_entry *dst, } else if (!e_src) { - /* delete tree dst */ + strcpy (src, dst->path); + repositoryDeleteR (di, dst, base, src, rGroup); return; } else @@ -161,7 +226,10 @@ static void repositoryUpdateR (struct dirs_info *di, struct dirs_entry *dst, if (e_src[i_src].ctime > dst->ctime) { if (fileExtract (&dst->sysno, tmppath, rGroup, 0)) + { + logf (LOG_LOG, "dirs_add"); dirs_add (di, src, dst->sysno, e_src[i_src].ctime); + } } dst = dirs_read (di); break; @@ -197,34 +265,81 @@ static void repositoryUpdateR (struct dirs_info *di, struct dirs_entry *dst, } else /* sd < 0 */ { - assert (0); + strcpy (src, dst->path); + sprintf (tmppath, "%s%s", base, dst->path); + + switch (dst->kind) + { + case dirs_file: + fileExtract (&dst->sysno, tmppath, rGroup, 1); + dirs_del (di, dst->path); + dst = dirs_read (di); + break; + case dirs_dir: + repositoryDeleteR (di, dst, base, src, rGroup); + dst = dirs_last (di); + } } } dir_free (&e_src); } +static void groupRes (struct recordGroup *rGroup) +{ + char resStr[256]; + char gPrefix[256]; + + if (!rGroup->groupName || !*rGroup->groupName) + *gPrefix = '\0'; + else + sprintf (gPrefix, "%s.", rGroup->groupName); + + sprintf (resStr, "%srecordId", gPrefix); + rGroup->recordId = res_get (common_resource, resStr); +} + void repositoryUpdate (struct recordGroup *rGroup) { - struct dirs_info *di; char src[256]; - Dict dict; - dict = dict_open ("repdict", 40, 1); - - assert (rGroup->path); - di = dirs_open (dict, rGroup->path); - strcpy (src, ""); - repositoryUpdateR (di, dirs_read (di), rGroup->path, src, rGroup); - dirs_free (&di); + groupRes (rGroup); + if (rGroup->recordId && !strcmp (rGroup->recordId, "file")) + { + Dict dict; + struct dirs_info *di; - dict_close (dict); + if (!(dict = dict_open (FMATCH_DICT, 50, 1))) + { + logf (LOG_FATAL, "dict_open fail of %s", FMATCH_DICT); + exit (1); + } + assert (rGroup->path); + di = dirs_open (dict, rGroup->path); + strcpy (src, ""); + repositoryUpdateR (di, dirs_read (di), rGroup->path, src, rGroup); + dirs_free (&di); + dict_close (dict); + } + else + { + strcpy (src, rGroup->path); + if (*src == '\0' || !strcmp (src, "-")) + stdinExtractR (0, rGroup); + else + repositoryExtractR (0, src, rGroup); + } } -void repositoryExtract (struct recordGroup *rGroup) +void repositoryDelete (struct recordGroup *rGroup) { char src[256]; assert (rGroup->path); + groupRes (rGroup); strcpy (src, rGroup->path); - repositoryExtractR (src, rGroup); + if (*src == '\0' || !strcmp(src, "-")) + stdinExtractR (1, rGroup); + else + repositoryExtractR (1, src, rGroup); } +