From: Adam Dickmeiss Date: Mon, 11 Sep 2006 22:57:54 +0000 (+0000) Subject: Fixed bug #657: Problem with drop database and recordId: file. X-Git-Tag: ZEBRA.2.0.2~20 X-Git-Url: http://sru.miketaylor.org.uk/cgi-bin?a=commitdiff_plain;h=10d6b6813c5bb9e7b19a12c241ac4e05f5741605;p=idzebra-moved-to-github.git Fixed bug #657: Problem with drop database and recordId: file. --- diff --git a/dict/open.c b/dict/open.c index a8f241f..0db5336 100644 --- a/dict/open.c +++ b/dict/open.c @@ -1,4 +1,4 @@ -/* $Id: open.c,v 1.26 2006-08-14 10:40:09 adam Exp $ +/* $Id: open.c,v 1.27 2006-09-11 22:57:54 adam Exp $ Copyright (C) 1995-2006 Index Data ApS @@ -28,6 +28,25 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA #include "dict-p.h" +void dict_clean(Dict dict) +{ + int page_size = dict->head.page_size; + void *head_buf; + int compact_flag = dict->head.compact_flag; + + memset (dict->head.magic_str, 0, sizeof(dict->head.magic_str)); + strcpy (dict->head.magic_str, DICT_MAGIC); + dict->head.last = 1; + dict->head.root = 0; + dict->head.freelist = 0; + dict->head.page_size = page_size; + dict->head.compact_flag = compact_flag; + + /* create header with information (page 0) */ + if (dict->rw) + dict_bf_newp (dict->dbf, 0, &head_buf, page_size); +} + Dict dict_open (BFiles bfs, const char *name, int cache, int rw, int compact_flag, int page_size) { @@ -58,17 +77,9 @@ Dict dict_open (BFiles bfs, const char *name, int cache, int rw, } if (dict_bf_readp (dict->dbf, 0, &head_buf) <= 0) { - memset (dict->head.magic_str, 0, sizeof(dict->head.magic_str)); - strcpy (dict->head.magic_str, DICT_MAGIC); - dict->head.last = 1; - dict->head.root = 0; - dict->head.freelist = 0; dict->head.page_size = page_size; - dict->head.compact_flag = compact_flag; - - /* create header with information (page 0) */ - if (rw) - dict_bf_newp (dict->dbf, 0, &head_buf, page_size); + dict->head.compact_flag = compact_flag; + dict_clean(dict); } else /* header was there, check magic and page size */ { diff --git a/include/idzebra/dict.h b/include/idzebra/dict.h index 968afbf..6691142 100644 --- a/include/idzebra/dict.h +++ b/include/idzebra/dict.h @@ -1,4 +1,4 @@ -/* $Id: dict.h,v 1.11 2006-09-05 12:50:56 adam Exp $ +/* $Id: dict.h,v 1.12 2006-09-11 22:57:54 adam Exp $ Copyright (C) 1995-2006 Index Data ApS @@ -187,6 +187,13 @@ void dict_grep_cmap(Dict dict, void *vp, YAZ_EXPORT int dict_copy_compact(BFiles bfs, const char *from, const char *to); +/** \brief reset Dictionary (makes it empty) + \param dict dictionary handle +*/ +YAZ_EXPORT +void dict_clean(Dict dict); + + YAZ_END_CDECL #endif diff --git a/index/index.h b/index/index.h index a147563..824cf4e 100644 --- a/index/index.h +++ b/index/index.h @@ -1,4 +1,4 @@ -/* $Id: index.h,v 1.175 2006-09-08 14:40:52 adam Exp $ +/* $Id: index.h,v 1.176 2006-09-11 22:57:54 adam Exp $ Copyright (C) 1995-2006 Index Data ApS @@ -127,7 +127,7 @@ int key_SU_code (int ch, char *out); #define FNAME_CONFIG "zebra.cfg" #define GMATCH_DICT "gmatch" -#define FMATCH_DICT "fmatch" +#define FMATCH_DICT "fmatch%d" struct strtab *strtab_mk (void); int strtab_src (struct strtab *t, const char *name, void ***infop); @@ -452,6 +452,8 @@ ZEBRA_RES zebra_sort_get_ord(ZebraHandle zh, ZEBRA_RES zebra_update_file_match(ZebraHandle zh, const char *path); ZEBRA_RES zebra_update_from_path(ZebraHandle zh, const char *path); ZEBRA_RES zebra_delete_from_path(ZebraHandle zh, const char *path); +ZEBRA_RES zebra_remove_file_match(ZebraHandle zh); + #define FIRST_IN_FIELD_STR "\001^" #define FIRST_IN_FIELD_LEN 2 diff --git a/index/main.c b/index/main.c index 5d22025..6034820 100644 --- a/index/main.c +++ b/index/main.c @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.130 2006-08-14 10:40:15 adam Exp $ +/* $Id: main.c,v 1.131 2006-09-11 22:57:54 adam Exp $ Copyright (C) 1995-2006 Index Data ApS @@ -231,7 +231,17 @@ int main (int argc, char **argv) } if (res != ZEBRA_OK) { - yaz_log(YLOG_WARN, "Operation failed"); + const char *add = zebra_errAdd(zh); + yaz_log(YLOG_FATAL, "Operation failed: %s %s", + zebra_errString(zh), add ? add : ""); + + if (trans_started) + if (zebra_end_trans (zh) != ZEBRA_OK) + yaz_log (YLOG_WARN, "zebra_end_trans failed"); + + + zebra_close (zh); + zebra_stop (zs); exit(1); } log_event_end (NULL, NULL); diff --git a/index/update_file.c b/index/update_file.c index aaeca2d..7b211c0 100644 --- a/index/update_file.c +++ b/index/update_file.c @@ -1,4 +1,4 @@ -/* $Id: update_file.c,v 1.2 2006-08-14 10:40:15 adam Exp $ +/* $Id: update_file.c,v 1.3 2006-09-11 22:57:54 adam Exp $ Copyright (C) 1995-2006 Index Data ApS @@ -297,15 +297,47 @@ static void file_update_top(ZebraHandle zh, Dict dict, const char *path) } } -ZEBRA_RES zebra_update_file_match(ZebraHandle zh, const char *path) +static ZEBRA_RES zebra_open_fmatch(ZebraHandle zh, Dict *dictp) { - Dict dict; - if (!(dict = dict_open_res (zh->reg->bfs, FMATCH_DICT, 50, + char fmatch_fname[1024]; + int ord; + + ord = zebraExplain_get_database_ord(zh->reg->zei); + sprintf(fmatch_fname, FMATCH_DICT, ord); + if (!(*dictp = dict_open_res (zh->reg->bfs, fmatch_fname, 50, zh->m_flag_rw, 0, zh->res))) { - yaz_log (YLOG_FATAL, "dict_open fail of %s", FMATCH_DICT); + yaz_log (YLOG_FATAL, "dict_open fail of %s", fmatch_fname); return ZEBRA_FAIL; } + return ZEBRA_OK; +} + +ZEBRA_RES zebra_remove_file_match(ZebraHandle zh) +{ + Dict dict; + + if (zebra_open_fmatch(zh, &dict) != ZEBRA_OK) + return ZEBRA_FAIL; + + dict_clean(dict); + dict_close(dict); + + return ZEBRA_OK; +} + +ZEBRA_RES zebra_update_file_match(ZebraHandle zh, const char *path) +{ + Dict dict; + + if (zebraExplain_curDatabase (zh->reg->zei, zh->basenames[0])) + { + if (zebraExplain_newDatabase(zh->reg->zei, zh->basenames[0], 0)) + return ZEBRA_FAIL; + } + if (zebra_open_fmatch(zh, &dict) != ZEBRA_OK) + return ZEBRA_FAIL; + if (!strcmp(path, "") || !strcmp(path, "-")) { char src[1024]; diff --git a/index/zebraapi.c b/index/zebraapi.c index 84c8e7a..6b60956 100644 --- a/index/zebraapi.c +++ b/index/zebraapi.c @@ -1,4 +1,4 @@ -/* $Id: zebraapi.c,v 1.226 2006-08-29 08:27:59 adam Exp $ +/* $Id: zebraapi.c,v 1.227 2006-09-11 22:57:54 adam Exp $ Copyright (C) 1995-2006 Index Data ApS @@ -1485,12 +1485,20 @@ ZEBRA_RES zebra_drop_database(ZebraHandle zh, const char *db) if (zh->reg->isamb) { int db_ord; - zebraExplain_curDatabase (zh->reg->zei, db); - db_ord = zebraExplain_get_database_ord(zh->reg->zei); - dict_delete_subtree_ord(zh->reg->matchDict, db_ord, - 0 /* handle */, 0 /* func */); - zebraExplain_trav_ord(zh->reg->zei, zh, delete_SU_handle); - zebraExplain_removeDatabase(zh->reg->zei, zh); + if (zebraExplain_curDatabase (zh->reg->zei, db)) + { + zebra_setError(zh, YAZ_BIB1_DATABASE_DOES_NOT_EXIST, db); + ret = ZEBRA_FAIL; + } + else + { + db_ord = zebraExplain_get_database_ord(zh->reg->zei); + dict_delete_subtree_ord(zh->reg->matchDict, db_ord, + 0 /* handle */, 0 /* func */); + zebraExplain_trav_ord(zh->reg->zei, zh, delete_SU_handle); + zebraExplain_removeDatabase(zh->reg->zei, zh); + zebra_remove_file_match(zh); + } } else {