+
+static int recordExtract (SYSNO *sysno, const char *fname,
+ struct recordGroup *rGroup, int deleteFlag,
+ int fd, RecType recType, char *subType)
+{
+ struct recExtractCtrl extractCtrl;
+ int r;
+ char *matchStr;
+ SYSNO sysnotmp;
+ Record rec;
+
+ if (fd != -1)
+ {
+ extractCtrl.fd = fd;
+ /* extract keys */
+ extractCtrl.subType = 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 */
+
+ matchStr = NULL;
+ if (!sysno)
+ {
+ sysnotmp = 0;
+ sysno = &sysnotmp;
+ if (rGroup->recordId && *rGroup->recordId)
+ {
+ char *rinfo;
+
+ matchStr = fileMatchStr (&reckeys, rGroup, fname,
+ rGroup->recordId);
+ if (matchStr)
+ {
+ rinfo = dict_lookup (matchDict, matchStr);
+ if (rinfo)
+ memcpy (sysno, rinfo+1, sizeof(*sysno));
+ }
+ else
+ {
+ logf (LOG_WARN, "Record not inserted");
+ return 0;
+ }
+ }
+ }
+
+ /* new record ? */
+ if (! *sysno)
+ {
+ if (deleteFlag)
+ {
+ logf (LOG_LOG, "? %s", fname);
+ return 1;
+ }
+ logf (LOG_LOG, "add %s %s", rGroup->recordType, fname);
+ rec = rec_new (records);
+ *sysno = rec->sysno;
+
+ if (matchStr)
+ {
+ dict_insert (matchDict, matchStr, sizeof(*sysno), sysno);
+ }
+ flushRecordKeys (*sysno, 1, &reckeys, rGroup->databaseName);
+
+ records_inserted++;
+ }
+ else
+ {
+ struct recKeys delkeys;
+
+ rec = rec_get (records, *sysno);
+ assert (rec);
+ delkeys.buf_used = rec->size[recInfo_delKeys];
+ delkeys.buf = rec->info[recInfo_delKeys];
+ flushRecordKeys (*sysno, 0, &delkeys, rec->info[recInfo_databaseName]);
+ if (deleteFlag)
+ {
+ if (!delkeys.buf_used)
+ {
+ logf (LOG_WARN, "cannot delete %s: storeKeys false",
+ fname);
+ }
+ else
+ {
+ logf (LOG_LOG, "delete %s %s", rGroup->recordType, fname);
+ records_deleted++;
+ if (matchStr)
+ dict_delete (matchDict, matchStr);
+ rec_del (records, &rec);
+ }
+ return 1;
+ }
+ else
+ {
+ if (!delkeys.buf_used)
+ {
+ logf (LOG_WARN, "cannot update %s: storeKeys false",
+ fname);
+ }
+ else
+ {
+ logf (LOG_LOG, "update %s %s", rGroup->recordType,
+ fname);
+ flushRecordKeys (*sysno, 1, &reckeys, rGroup->databaseName);
+ records_updated++;
+ }
+ }
+ }
+ xfree (rec->info[recInfo_fileType]);
+ rec->info[recInfo_fileType] =
+ rec_strdup (rGroup->recordType, &rec->size[recInfo_fileType]);
+
+ xfree (rec->info[recInfo_filename]);
+ rec->info[recInfo_filename] =
+ rec_strdup (fname, &rec->size[recInfo_filename]);
+
+ xfree (rec->info[recInfo_delKeys]);
+ if (reckeys.buf_used > 0 && rGroup->flagStoreKeys == 1)
+ {
+ rec->info[recInfo_delKeys] = xmalloc (reckeys.buf_used);
+ rec->size[recInfo_delKeys] = reckeys.buf_used;
+ memcpy (rec->info[recInfo_delKeys], reckeys.buf,
+ rec->size[recInfo_delKeys]);
+ }
+ else
+ {
+ rec->info[recInfo_delKeys] = NULL;
+ rec->size[recInfo_delKeys] = 0;
+ }
+
+ xfree (rec->info[recInfo_storeData]);
+ if (rGroup->flagStoreData == 1)
+ {
+ rec->size[recInfo_storeData] = file_noread;
+ rec->info[recInfo_storeData] = xmalloc (file_noread);
+#if FILE_READ_BUFSIZE
+ if (file_noread < FILE_READ_BUFSIZE)
+ memcpy (rec->info[recInfo_storeData], file_buf, file_noread);
+ else