+Added zebraidx command, adelete, which attempts to delete records.
+It's like 'delete', but does not fail if a record does not exist.
+
--- 2.0.20 2007/12/19
Added experimental support for faceted results. This is implemented
<!ENTITY % idcommon SYSTEM "common/common.ent">
%idcommon;
]>
-<!-- $Id: zebraidx.xml,v 1.14 2007-05-24 13:44:09 adam Exp $ -->
+<!-- $Id: zebraidx.xml,v 1.15 2007-12-20 11:15:41 adam Exp $ -->
<refentry id="zebraidx">
<refentryinfo>
<productname>zebra</productname>
</listitem>
</varlistentry>
<varlistentry>
+ <term>adelete <replaceable>directory</replaceable></term>
+ <listitem>
+ <para>
+ Remove the records corresponding to the files found under
+ <replaceable>directory</replaceable> from the register.
+ Unlike command <literal>delete</literal> this command does not
+ fail if a record does not exist (but which is attempted deleted).
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
<term>commit</term>
<listitem>
<para>
-/* $Id: api.h,v 1.53 2007-10-31 16:56:14 adam Exp $
+/* $Id: api.h,v 1.54 2007-12-20 11:15:41 adam Exp $
Copyright (C) 1995-2007
Index Data ApS
ZEBRA_RES zebra_compact(ZebraHandle zh);
YAZ_EXPORT
+ZEBRA_RES zebra_repository_index(ZebraHandle zh, const char *path,
+ enum zebra_recctrl_action_t action);
+
+YAZ_EXPORT
ZEBRA_RES zebra_repository_update(ZebraHandle zh, const char *path);
YAZ_EXPORT
-/* $Id: recctrl.h,v 1.39 2007-11-30 12:19:08 adam Exp $
+/* $Id: recctrl.h,v 1.40 2007-12-20 11:15:41 adam Exp $
Copyright (C) 1995-2007
Index Data ApS
void (*destroy)(struct ZebraRecStream *s);
};
+/** record update action */
enum zebra_recctrl_action_t {
+ /** insert record (fail if it exists already) */
action_insert = 1,
+ /** replace record (fail it it does not exist) */
action_replace,
+ /** delete record (fail if it does not exist) */
action_delete,
- action_update /* insert or replace as needed */
+ /** insert or replace */
+ action_update,
+ /** delete record (ignore if it does not exist) */
+ action_a_delete
};
/** \brief record extract for indexing */
-/* $Id: extract.c,v 1.274 2007-12-17 08:44:07 adam Exp $
+/* $Id: extract.c,v 1.275 2007-12-20 11:15:42 adam Exp $
Copyright (C) 1995-2007
Index Data ApS
ZEBRA_RES zebra_extract_file(ZebraHandle zh, zint *sysno, const char *fname,
- int deleteFlag)
+ enum zebra_recctrl_action_t action)
{
ZEBRA_RES r = ZEBRA_OK;
int i, fd;
default:
yaz_log(YLOG_WARN, "Bad filter version: %s", zh->m_record_type);
}
- if (sysno && deleteFlag)
+ if (sysno && (action == action_delete || action == action_a_delete))
{
streamp = 0;
fi = 0;
zebra_create_stream_fd(streamp, fd, 0);
}
r = zebra_extract_records_stream(zh, streamp,
- deleteFlag ?
- action_delete : action_update,
+ action,
0, /* tst_mode */
zh->m_record_type,
sysno,
if (! *sysno)
{
- /* new record */
+ /* new record AKA does not exist already */
if (action == action_delete)
{
- yaz_log(YLOG_LOG, "delete %s %s " ZINT_FORMAT, recordType,
- pr_fname, (zint) start_offset);
+ yaz_log(YLOG_LOG, "delete %s %s " ZINT_FORMAT, recordType,
+ pr_fname, (zint) start_offset);
yaz_log(YLOG_WARN, "cannot delete record above (seems new)");
return ZEBRA_FAIL;
}
+ else if (action == action_a_delete)
+ {
+ if (show_progress)
+ yaz_log(YLOG_LOG, "delete %s %s " ZINT_FORMAT, recordType,
+ pr_fname, (zint) start_offset);
+ return ZEBRA_OK;
+ }
else if (action == action_replace)
{
yaz_log(YLOG_LOG, "update %s %s " ZINT_FORMAT, recordType,
extract_flush_record_keys(zh, *sysno, 0, delkeys,
recordAttr->staticrank);
#endif
- if (action == action_delete)
+ if (action == action_delete || action == action_a_delete)
{
/* record going to be deleted */
#if FLUSH2
-/* $Id: index.h,v 1.213 2007-12-13 11:09:20 adam Exp $
+/* $Id: index.h,v 1.214 2007-12-20 11:15:42 adam Exp $
Copyright (C) 1995-2007
Index Data ApS
ZEBRA_RES zebra_extract_explain(void *handle, Record rec, data1_node *n);
ZEBRA_RES zebra_extract_file(ZebraHandle zh, zint *sysno, const char *fname,
- int deleteFlag);
+ enum zebra_recctrl_action_t action);
ZEBRA_RES zebra_begin_read(ZebraHandle zh);
ZEBRA_RES zebra_end_read(ZebraHandle zh);
int *numerical);
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_update_from_path(ZebraHandle zh, const char *path,
+ enum zebra_recctrl_action_t action);
ZEBRA_RES zebra_remove_file_match(ZebraHandle zh);
struct rpn_char_map_info
-/* $Id: update_file.c,v 1.6 2007-10-29 09:25:41 adam Exp $
+/* $Id: update_file.c,v 1.7 2007-12-20 11:15:42 adam Exp $
Copyright (C) 1995-2007
Index Data ApS
{
case dirs_file:
sprintf(tmppath, "%s%s", base, dst->path);
- zebra_extract_file(zh, &dst->sysno, tmppath, 1);
-
+ zebra_extract_file(zh, &dst->sysno, tmppath, action_delete);
strcpy(tmppath, dst->path);
dst = dirs_read(di);
dirs_del(di, tmppath);
case dirs_file:
if (e_src[i_src].mtime > dst->mtime)
{
- if (zebra_extract_file(zh, &dst->sysno, tmppath, 0) == ZEBRA_OK)
+ if (zebra_extract_file(zh, &dst->sysno, tmppath, action_update) == ZEBRA_OK)
{
dirs_add(di, src, dst->sysno, e_src[i_src].mtime);
}
switch (e_src[i_src].kind)
{
case dirs_file:
- if (zebra_extract_file(zh, &sysno, tmppath, 0) == ZEBRA_OK)
+ if (zebra_extract_file(zh, &sysno, tmppath, action_update) == ZEBRA_OK)
dirs_add(di, src, sysno, e_src[i_src].mtime);
break;
case dirs_dir:
switch (dst->kind)
{
case dirs_file:
- zebra_extract_file(zh, &dst->sysno, tmppath, 1);
+ zebra_extract_file(zh, &dst->sysno, tmppath, action_delete);
dirs_del(di, dst->path);
dst = dirs_read(di);
break;
if (e_dst)
{
if (sbuf.st_mtime > e_dst->mtime)
- if (zebra_extract_file(zh, &e_dst->sysno, src, 0) == ZEBRA_OK)
+ if (zebra_extract_file(zh, &e_dst->sysno, src, action_update) == ZEBRA_OK)
dirs_add(di, src, e_dst->sysno, sbuf.st_mtime);
}
else
{
zint sysno = 0;
- if (zebra_extract_file(zh, &sysno, src, 0) == ZEBRA_OK)
+ if (zebra_extract_file(zh, &sysno, src, action_update) == ZEBRA_OK)
dirs_add(di, src, sysno, sbuf.st_mtime);
}
dirs_free(&di);
-/* $Id: update_path.c,v 1.4 2007-10-29 09:25:41 adam Exp $
+/* $Id: update_path.c,v 1.5 2007-12-20 11:15:42 adam Exp $
Copyright (C) 1995-2007
Index Data ApS
#include "index.h"
-static void repositoryExtractR(ZebraHandle zh, int deleteFlag, char *rep,
- int level)
+static void repositoryExtractR(ZebraHandle zh, char *rep, int level,
+ enum zebra_recctrl_action_t action)
{
struct dir_entry *e;
int i;
switch (e[i].kind)
{
case dirs_file:
- zebra_extract_file(zh, NULL, rep, deleteFlag);
+ zebra_extract_file(zh, NULL, rep, action);
break;
case dirs_dir:
- repositoryExtractR(zh, deleteFlag, rep, level+1);
+ repositoryExtractR(zh, rep, level+1, action);
break;
}
}
}
static void repositoryExtract(ZebraHandle zh,
- int deleteFlag, const char *path)
+ const char *path,
+ enum zebra_recctrl_action_t action)
+
{
struct stat sbuf;
char src[1024];
if (ret == -1)
yaz_log(YLOG_WARN|YLOG_ERRNO, "Cannot access path %s", src);
else if (S_ISREG(sbuf.st_mode))
- zebra_extract_file(zh, NULL, src, deleteFlag);
+ zebra_extract_file(zh, NULL, src, action);
else if (S_ISDIR(sbuf.st_mode))
- repositoryExtractR(zh, deleteFlag, src, 0);
+ repositoryExtractR(zh, src, 0, action);
else
yaz_log(YLOG_WARN, "Skipping path %s", src);
}
-static void repositoryExtractG(ZebraHandle zh, const char *path,
- int deleteFlag)
+
+ZEBRA_RES zebra_update_from_path(ZebraHandle zh, const char *path,
+ enum zebra_recctrl_action_t action)
{
if (!strcmp(path, "") || !strcmp(path, "-"))
{
char src[1024];
while (scanf("%1020s", src) == 1)
- repositoryExtract(zh, deleteFlag, src);
+ repositoryExtract(zh, src, action);
}
else
- repositoryExtract(zh, deleteFlag, path);
-}
-
-ZEBRA_RES zebra_update_from_path(ZebraHandle zh, const char *path)
-{
- assert(path);
- repositoryExtractG(zh, path, 0);
- return ZEBRA_OK;
-}
-
-ZEBRA_RES zebra_delete_from_path(ZebraHandle zh, const char *path)
-{
- assert(path);
- repositoryExtractG(zh, path, 1);
+ repositoryExtract(zh, path, action);
return ZEBRA_OK;
}
-/* $Id: zebraapi.c,v 1.268 2007-12-18 13:55:28 adam Exp $
+/* $Id: zebraapi.c,v 1.269 2007-12-20 11:15:42 adam Exp $
Copyright (C) 1995-2007
Index Data ApS
ZEBRA_RES zebra_repository_update(ZebraHandle zh, const char *path)
{
- ASSERTZH;
- assert(path);
- yaz_log(log_level, "updating %s", path);
-
- if (zh->m_record_id && !strcmp(zh->m_record_id, "file"))
- return zebra_update_file_match(zh, path);
- else
- return zebra_update_from_path(zh, path);
+ return zebra_repository_index(zh, path, action_update);
}
ZEBRA_RES zebra_repository_delete(ZebraHandle zh, const char *path)
{
+ return zebra_repository_index(zh, path, action_delete);
+}
+
+ZEBRA_RES zebra_repository_index(ZebraHandle zh, const char *path,
+ enum zebra_recctrl_action_t action)
+{
ASSERTZH;
assert(path);
- yaz_log(log_level, "deleting %s", path);
- return zebra_delete_from_path(zh, path);
+
+ if (action == action_update)
+ yaz_log(log_level, "updating %s", path);
+ else if (action == action_delete)
+ yaz_log(log_level, "deleting %s", path);
+ else if (action == action_a_delete)
+ yaz_log(log_level, "attempt deleting %s", path);
+ else
+ yaz_log(log_level, "update action=%d", (int) action);
+
+ if (zh->m_record_id && !strcmp(zh->m_record_id, "file"))
+ return zebra_update_file_match(zh, path);
+ else
+ return zebra_update_from_path(zh, path, action);
}
ZEBRA_RES zebra_repository_show(ZebraHandle zh, const char *path)
-/* $Id: zebraidx.c,v 1.10 2007-11-08 09:30:05 adam Exp $
+/* $Id: zebraidx.c,v 1.11 2007-12-20 11:15:43 adam Exp $
Copyright (C) 1995-2007
Index Data ApS
cmd = 's';
else if (!strcmp(arg, "del") || !strcmp(arg, "delete"))
cmd = 'd';
+ else if (!strcmp(arg, "adelete"))
+ cmd = 'a';
else if (!strcmp(arg, "init"))
{
zebra_init(zh);
switch (cmd)
{
case 'u':
- res = zebra_repository_update(zh, arg);
+ res = zebra_repository_index(zh, arg, action_update);
break;
case 'd':
- res = zebra_repository_delete(zh, arg);
+ res = zebra_repository_index(zh, arg, action_delete);
+ break;
+ case 'a':
+ res = zebra_repository_index(zh, arg, action_a_delete);
break;
case 's':
res = zebra_repository_show(zh, arg);