-/* $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
#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)
{
}
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 */
{
-/* $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
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
-/* $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
#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);
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
-/* $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
}
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);
-/* $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
}
}
-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];
-/* $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
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
{