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.
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: extract.c,v $
- * Revision 1.33 1995-11-27 09:56:20 adam
+ * Revision 1.34 1995-11-28 09:09:38 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.33 1995/11/27 09:56:20 adam
* Record info elements better enumerated. Internal store of records.
*
* Revision 1.32 1995/11/25 10:24:05 adam
static char *fileMatchStr (struct recKeys *reckeys, struct recordGroup *rGroup,
const char *fname,
- const char *recordType,
const char *spec)
{
static char dstBuf[2048];
else if (strcmp (special, "filename"))
spec_src = fname;
else if (strcmp (special, "type"))
- spec_src = recordType;
+ spec_src = rGroup->recordType;
else
spec_src = NULL;
if (spec_src)
static int recordExtract (SYSNO *sysno, const char *fname,
struct recordGroup *rGroup, int deleteFlag,
int fd,
- const char *file_type,
RecType recType)
{
struct recExtractCtrl extractCtrl;
SYSNO sysnotmp;
Record rec;
- extractCtrl.fd = fd;
-
- /* extract keys */
- extractCtrl.subType = "";
- extractCtrl.init = wordInit;
- extractCtrl.add = addRecordKeyAny;
-
- reckeys.buf_used = 0;
- extractCtrl.readf = file_read;
- r = (*recType->extract)(&extractCtrl);
-
- if (r)
+ if (fd != -1)
{
- logf (LOG_WARN, "Couldn't extract file %s, code %d", fname, r);
- return 0;
+ extractCtrl.fd = fd;
+ /* extract keys */
+ extractCtrl.subType = "";
+ extractCtrl.init = wordInit;
+ extractCtrl.add = addRecordKeyAny;
+
+ reckeys.buf_used = 0;
+ extractCtrl.readf = file_read;
+ r = (*recType->extract)(&extractCtrl);
+
+ if (r)
+ {
+ logf (LOG_WARN, "Couldn't extract file %s, code %d", fname, r);
+ return 0;
+ }
}
/* perform match if sysno not known and if match criteria is specified */
{
sysnotmp = 0;
sysno = &sysnotmp;
- if (rGroup->fileMatch)
+ if (rGroup->recordId && *rGroup->recordId)
{
char *rinfo;
- matchStr = fileMatchStr(&reckeys, rGroup, fname, file_type,
- rGroup->fileMatch);
+ matchStr = fileMatchStr (&reckeys, rGroup, fname,
+ rGroup->recordId);
if (matchStr)
{
rinfo = dict_lookup (matchDict, matchStr);
logf (LOG_LOG, "? record %s", fname);
return 1;
}
- logf (LOG_LOG, "add record %s", fname);
+ logf (LOG_LOG, "add %s record %s", rGroup->recordType, fname);
rec = rec_new (records);
*sysno = rec->sysno;
fname);
}
else
- logf (LOG_LOG, "delete record %s", fname);
+ logf (LOG_LOG, "delete %s record %s", rGroup->recordType,
+ fname);
records_deleted++;
rec_del (records, &rec);
return 1;
}
else
{
- logf (LOG_LOG, "update record %s", fname);
+ logf (LOG_LOG, "update %s record %s", rGroup->recordType,
+ fname);
flushRecordKeys (*sysno, 1, &reckeys, rGroup->databaseName);
records_updated++;
}
}
free (rec->info[recInfo_fileType]);
rec->info[recInfo_fileType] =
- rec_strdup (file_type, &rec->size[recInfo_fileType]);
+ rec_strdup (rGroup->recordType, &rec->size[recInfo_fileType]);
free (rec->info[recInfo_filename]);
rec->info[recInfo_filename] =
return 1;
}
-int fileExtract (SYSNO *sysno, const char *fname, struct recordGroup *rGroup,
- int deleteFlag)
+int fileExtract (SYSNO *sysno, const char *fname,
+ const struct recordGroup *rGroupP, int deleteFlag)
{
int i, fd;
char gprefix[128];
char ext[128];
char ext_res[128];
- const char *file_type;
RecType recType;
+ struct recordGroup rGroupM;
+ struct recordGroup *rGroup = &rGroupM;
+ memcpy (rGroup, rGroupP, sizeof(*rGroupP));
+
if (!rGroup->groupName || !*rGroup->groupName)
*gprefix = '\0';
else
break;
}
/* determine file type - depending on extension */
- sprintf (ext_res, "%sfileExtension.%s", gprefix, ext);
- if (!(file_type = res_get (common_resource, ext_res)))
+ if (!rGroup->recordType)
+ {
+ sprintf (ext_res, "%srecordType.%s", gprefix, ext);
+ if (!(rGroup->recordType = res_get (common_resource, ext_res)))
+ {
+ sprintf (ext_res, "%srecordType", gprefix);
+ if (!(rGroup->recordType = res_get (common_resource, ext_res)))
+ {
+ logf (LOG_LOG, "? record %s", fname);
+ return 0;
+ }
+ }
+ }
+ if (!rGroup->recordType)
+ {
+ logf (LOG_LOG, "? record %s", fname);
return 0;
- if (!(recType = recType_byName (file_type)))
+ }
+ if (!(recType = recType_byName (rGroup->recordType)))
+ {
+ logf (LOG_WARN, "No such record type: %s", rGroup->recordType);
return 0;
+ }
/* determine match criteria */
- if (rGroup->fileMatch)
+ if (!rGroup->recordId)
{
- sprintf (ext_res, "%sfileMatch.%s", gprefix, ext);
- rGroup->fileMatch = res_get (common_resource, ext_res);
- if (!rGroup->fileMatch)
- {
- sprintf (ext_res, "%sfileMatch", gprefix);
- rGroup->fileMatch = res_get (common_resource, ext_res);
- }
+ sprintf (ext_res, "%srecordId.%s", gprefix, ext);
+ rGroup->recordId = res_get (common_resource, ext_res);
}
/* determine database name */
if (rGroup->flagStoreKeys == -1)
rGroup->flagStoreKeys = 0;
- /* open input file */
- if ((fd = open (fname, O_RDONLY)) == -1)
+ if (sysno && deleteFlag)
+ fd = -1;
+ else
{
- logf (LOG_WARN|LOG_ERRNO, "open %s", fname);
- return 0;
+ if ((fd = open (fname, O_RDONLY)) == -1)
+ {
+ logf (LOG_WARN|LOG_ERRNO, "open %s", fname);
+ return 0;
+ }
}
file_read_start (fd);
- recordExtract (sysno, fname, rGroup, deleteFlag, fd,
- file_type, recType);
+ recordExtract (sysno, fname, rGroup, deleteFlag, fd, recType);
file_read_stop (fd);
- close (fd);
+ if (fd != -1)
+ close (fd);
return 1;
}
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: index.h,v $
- * Revision 1.28 1995-11-27 13:58:53 adam
+ * Revision 1.29 1995-11-28 09:09:40 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.28 1995/11/27 13:58:53 adam
* New option -t. storeStore data implemented in server.
*
* Revision 1.27 1995/11/25 10:24:06 adam
char *groupName;
char *databaseName;
char *path;
- char *fileMatch;
- char *fileType;
+ char *recordId;
+ char *recordType;
int flagStoreData;
int flagStoreKeys;
};
#define TEMP_FNAME "keys%d.tmp"
#define FNAME_WORD_DICT "worddict"
#define FNAME_WORD_ISAM "wordisam"
+#define FNAME_CONFIG "zebra.cfg"
struct strtab *strtab_mk (void);
int strtab_src (struct strtab *t, const char *name, void ***infop);
int local_attribute, const char *databaseName);
int fileExtract (SYSNO *sysno, const char *fname,
- struct recordGroup *rGroup, int deleteFlag);
+ const struct recordGroup *rGroup, int deleteFlag);
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: main.c,v $
- * Revision 1.21 1995-11-27 14:27:39 adam
+ * Revision 1.22 1995-11-28 09:09:42 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.21 1995/11/27 14:27:39 adam
* Renamed 'update' command to 'dir'.
*
* Revision 1.20 1995/11/27 13:58:53 adam
int nsections;
int key_open_flag = 0;
- struct recordGroup rGroup;
+ struct recordGroup rGroupDef;
- rGroup.groupName = NULL;
- rGroup.databaseName = NULL;
- rGroup.path = NULL;
- rGroup.fileMatch = NULL;
- rGroup.flagStoreData = -1;
- rGroup.flagStoreKeys = -1;
- rGroup.fileType = NULL;
+ rGroupDef.groupName = NULL;
+ rGroupDef.databaseName = NULL;
+ rGroupDef.path = NULL;
+ rGroupDef.recordId = NULL;
+ rGroupDef.recordType = NULL;
+ rGroupDef.flagStoreData = -1;
+ rGroupDef.flagStoreKeys = -1;
prog = *argv;
if (argc < 2)
{
fprintf (stderr, "index [-v log] [-m meg] [-c config] [-d base]"
- " [-g group] cmd1 dir1 cmd2 dir2 ...\n");
+ " [-g group] [update|del dir] ...\n");
exit (1);
}
while ((ret = options ("t:c:g:v:m:d:", argv, argc, &arg)) != -2)
{
if(cmd == 0) /* command */
{
- if (!strcmp (arg, "add"))
- {
- cmd = 'a';
- }
- else if (!strcmp (arg, "del"))
- {
- cmd = 'd';
- }
- else if (!strcmp (arg, "dir"))
- {
+ if (!strcmp (arg, "update"))
cmd = 'u';
- }
+ else if (!strcmp (arg, "del") || !strcmp(arg, "delete"))
+ cmd = 'd';
else
{
logf (LOG_FATAL, "Unknown command: %s", arg);
}
else
{
+ struct recordGroup rGroup;
+
+ memcpy (&rGroup, &rGroupDef, sizeof(rGroup));
if (!common_resource)
{
common_resource = res_open (configName ?
- configName : "base");
+ configName : FNAME_CONFIG);
if (!common_resource)
{
logf (LOG_FATAL, "Cannot open resource `%s'",
configName);
exit (1);
}
- data1_tabpath = res_get (common_resource, "data1_tabpath");
+ data1_tabpath = res_get (common_resource, "profilePath");
assert (data1_tabpath);
}
if (!key_open_flag)
rGroup.path = arg;
if (cmd == 'u')
repositoryUpdate (&rGroup);
- else if (cmd == 'a')
- repositoryAdd (&rGroup);
else if (cmd == 'd')
repositoryDelete (&rGroup);
cmd = 0;
}
else if (ret == 'd')
{
- rGroup.databaseName = arg;
+ rGroupDef.databaseName = arg;
}
else if (ret == 'g')
{
- rGroup.groupName = arg;
+ rGroupDef.groupName = arg;
}
else if (ret == 'c')
configName = arg;
else if (ret == 't')
- rGroup.fileType = arg;
+ rGroupDef.recordType = arg;
else
{
logf (LOG_FATAL, "Unknown option '-%s'", arg);
nsections = key_close ();
if (!nsections)
exit (0);
- logf (LOG_LOG, "Input");
+ logf (LOG_LOG, "Merging with index");
key_input (FNAME_WORD_DICT, FNAME_WORD_ISAM, nsections, 60);
exit (0);
}
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: recindex.c,v $
- * Revision 1.6 1995-11-25 10:24:06 adam
+ * Revision 1.7 1995-11-28 09:09:43 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.6 1995/11/25 10:24:06 adam
* More record fields - they are enumerated now.
* New options: flagStoreData flagStoreKey.
*
} head;
};
-enum recordCacheFlag { recordFlagNop, recordFlagWrite, recordFlagDelete };
+enum recordCacheFlag { recordFlagNop, recordFlagWrite, recordFlagNew,
+ recordFlagDelete };
struct record_cache_entry {
Record rec;
freeblock = entry.u.used.next;
assert (freeblock > 0);
dst_type = freeblock & 7;
+ assert (dst_type < REC_BLOCK_TYPES);
freeblock = freeblock / 8;
while (freeblock)
{
write_indx (p, rec->sysno, &entry, sizeof(entry));
}
+
static void rec_write_single (Records p, Record rec)
{
int i, size = 0;
int block_prev = -1, block_free;
struct record_index_entry entry;
- rec_release_blocks (p, rec->sysno);
-
for (i = 0; i < REC_NO_INFO; i++)
if (!rec->info[i])
size += sizeof(*rec->size);
sizeof(int) + (p->tmp_buf+size) - cptr, cptr);
}
+static void rec_update_single (Records p, Record rec)
+{
+ rec_release_blocks (p, rec->sysno);
+ rec_write_single (p, rec);
+}
Records rec_open (int rw)
{
for (i = 0; i<REC_BLOCK_TYPES; i++)
{
char str[80];
- sprintf (str, "recdata%d", i);
+ sprintf (str, "recdata%c", i + 'A');
p->data_fname[i] = malloc (strlen(str)+1);
strcpy (p->data_fname[i], str);
p->data_BFile[i] = NULL;
{
case recordFlagNop:
break;
- case recordFlagWrite:
+ case recordFlagNew:
rec_write_single (p, e->rec);
break;
+ case recordFlagWrite:
+ rec_update_single (p, e->rec);
+ break;
case recordFlagDelete:
rec_delete_single (p, e->rec);
break;
struct record_cache_entry *e = p->record_cache + i;
if (e->rec->sysno == sysno)
{
- if (flag != recordFlagNop)
+ if (flag != recordFlagNop && e->flag == recordFlagNop)
e->flag = flag;
return &e->rec;
}
read_indx (p, sysno, &entry, sizeof(entry), 0);
dst_type = entry.u.used.next & 7;
+ assert (dst_type < REC_BLOCK_TYPES);
freeblock = entry.u.used.next / 8;
assert (freeblock > 0);
rec->info[i] = NULL;
rec->size[i] = 0;
}
- rec_cache_insert (p, rec, recordFlagWrite);
+ rec_cache_insert (p, rec, recordFlagNew);
return rec;
}
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: recindex.h,v $
- * Revision 1.6 1995-11-27 09:56:21 adam
+ * Revision 1.7 1995-11-28 09:09:45 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.6 1995/11/27 09:56:21 adam
* Record info elements better enumerated. Internal store of records.
*
* Revision 1.5 1995/11/25 10:24:07 adam
typedef struct record_info {
int sysno;
+ int newFlag;
char *info[REC_NO_INFO];
size_t size[REC_NO_INFO];
} *Record;
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: trav.c,v $
- * Revision 1.12 1995-11-24 11:31:37 adam
+ * 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.
{
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)
}
else if (!e_src)
{
- /* delete tree dst */
+ strcpy (src, dst->path);
+ repositoryDeleteR (di, dst, base, src, rGroup);
return;
}
else
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;
}
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);
+ groupRes (rGroup);
+ if (rGroup->recordId && !strcmp (rGroup->recordId, "file"))
+ {
+ Dict dict;
+ struct dirs_info *di;
- assert (rGroup->path);
- di = dirs_open (dict, rGroup->path);
- strcpy (src, "");
- repositoryUpdateR (di, dirs_read (di), rGroup->path, src, rGroup);
- dirs_free (&di);
+ dict = dict_open ("repdict", 40, 1);
- dict_close (dict);
+ 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')
+ stdinExtractR (0, rGroup);
+ else
+ repositoryExtractR (0, src, rGroup);
+ }
}
void repositoryDelete (struct recordGroup *rGroup)
char src[256];
assert (rGroup->path);
+ groupRes (rGroup);
strcpy (src, rGroup->path);
if (*src == '\0')
stdinExtractR (1, rGroup);
repositoryExtractR (1, src, rGroup);
}
-void repositoryAdd (struct recordGroup *rGroup)
-{
- char src[256];
-
- assert (rGroup->path);
- strcpy (src, rGroup->path);
- if (*src == '\0')
- stdinExtractR (0, rGroup);
- else
- repositoryExtractR (0, src, rGroup);
-}
-
--- /dev/null
+# Zebra configuration file
+# $Id: zebra.cfg,v 1.1 1995-11-28 09:09:47 adam Exp $
+#
+#register: dir1:100M
+
+# News group. Indexed as normal text
+news.recordType.: text
+news.database: news
+
+# Grs group. Indexed as GRS.
+grs.recordType.grs: grs
+grs.recordId: $database (1,12)
+grs.database: esdd
+
+profilePath: /usr/local/yaz
+
+attset: bib1.att
+attset: gils.att
+
+wordisam.blocktypes: 64 1K 4K
+wordisam.maxkeys: 160 750
+wordisam.nicefill: 80 80 80
* Sebastian Hammer, Adam Dickmeiss
*
* $Log: zserver.c,v $
- * Revision 1.27 1995-11-27 13:58:54 adam
+ * Revision 1.28 1995-11-28 09:09:48 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.27 1995/11/27 13:58:54 adam
* New option -t. storeStore data implemented in server.
*
* Revision 1.26 1995/11/25 10:24:07 adam
}
}
- data1_tabpath = res_get(common_resource, "data1_tabpath");
+ data1_tabpath = res_get(common_resource, "profilePath");
server_info.sets = NULL;
server_info.records = rec_open (0);
return 0;
l = (l < count) ? l : count;
memcpy (buf, record_int_buf + record_int_pos, l);
- record_int_buf += l;
+ record_int_pos += l;
return l;
}
record_int_len = rec->size[recInfo_storeData];
record_int_buf = rec->info[recInfo_storeData];
record_int_pos = 0;
+ logf (LOG_DEBUG, "Internal retrieve. %d bytes", record_int_len);
}
else
{
struct statserv_options_block *sob;
sob = statserv_getcontrol ();
- strcpy (sob->configname, "base");
+ strcpy (sob->configname, FNAME_CONFIG);
statserv_setcontrol (sob);
return statserv_main (argc, argv);