- r = (*recType->extract)(recTypeClientData, &extractCtrl);
-
- yaz_log_init_prefix2 (0);
- if (r == RECCTRL_EXTRACT_EOF)
- return ZEBRA_FAIL;
- else if (r == RECCTRL_EXTRACT_ERROR_GENERIC)
- {
- /* error occured during extraction ... */
- if (zh->m_flag_rw &&
- zh->records_processed < zh->m_file_verbose_limit)
- {
- yaz_log (YLOG_WARN, "fail %s %s " PRINTF_OFF_T, zh->m_record_type,
- fname, recordOffset);
- }
- return ZEBRA_FAIL;
- }
- else if (r == RECCTRL_EXTRACT_ERROR_NO_SUCH_FILTER)
- {
- /* error occured during extraction ... */
- if (zh->m_flag_rw &&
- zh->records_processed < zh->m_file_verbose_limit)
- {
- yaz_log (YLOG_WARN, "no filter for %s %s "
- PRINTF_OFF_T, zh->m_record_type,
- fname, recordOffset);
- }
- return ZEBRA_FAIL;
- }
- all_matches_add(&extractCtrl);
- if (extractCtrl.match_criteria[0])
- matchStr = extractCtrl.match_criteria;
- }
-
- /* if matchStr is set now - we assume it's printable .
- For internal matchStr (see below) we don't print */
- if (matchStr)
- match_str_to_print = matchStr;
-
- /* perform internal match if sysno not known and if match criteria is
- specified already */
- if (!sysno)
- {
- sysnotmp = 0;
- sysno = &sysnotmp;
-
- if (matchStr == 0 && zh->m_record_id && *zh->m_record_id)
- {
- matchStr = fileMatchStr (zh, zh->reg->keys, fname,
- zh->m_record_id);
- if (!matchStr)
- {
- yaz_log(YLOG_WARN, "Bad match criteria");
-
- if (zebra_rec_keys_empty(zh->reg->keys))
- {
- yaz_log(YLOG_WARN, "And no index keys");
- }
- return ZEBRA_FAIL;
- }
- }
- if (matchStr)
- {
- int db_ord = zebraExplain_get_database_ord(zh->reg->zei);
- char *rinfo = dict_lookup_ord(zh->reg->matchDict, db_ord,
- matchStr);
- if (rinfo)
- {
- assert(*rinfo == sizeof(*sysno));
- memcpy (sysno, rinfo+1, sizeof(*sysno));
- }
- }
- }
- if (! *sysno && zebra_rec_keys_empty(zh->reg->keys) )
- {
- /* the extraction process returned no information - the record
- is probably empty - unless flagShowRecords is in use */
- if (!zh->m_flag_rw)
- return ZEBRA_OK;
-
- if (zh->records_processed < zh->m_file_verbose_limit)
- yaz_log (YLOG_WARN, "empty %s %s " PRINTF_OFF_T, zh->m_record_type,
- fname, recordOffset);
- return ZEBRA_OK;
- }
-
- if (! *sysno)
- {
- /* new record */
- if (deleteFlag)
- {
- yaz_log (YLOG_LOG, "delete %s %s " PRINTF_OFF_T, zh->m_record_type,
- fname, recordOffset);
- yaz_log (YLOG_WARN, "cannot delete record above (seems new)");
- return ZEBRA_OK;
- }
-
- rec = rec_new (zh->reg->records);
-
- *sysno = rec->sysno;
-
- if (zh->records_processed < zh->m_file_verbose_limit)
- {
- yaz_log(YLOG_LOG, "add %s %s " PRINTF_OFF_T
- " " ZINT_FORMAT " %s" ,
- zh->m_record_type,
- fname, recordOffset, *sysno, match_str_to_print);
- }
- recordAttr = rec_init_attr (zh->reg->zei, rec);
- recordAttr->staticrank = extractCtrl.staticrank;
-
- if (matchStr)
- {
- int db_ord = zebraExplain_get_database_ord(zh->reg->zei);
- dict_insert_ord(zh->reg->matchDict, db_ord, matchStr,
- sizeof(*sysno), sysno);
- }
-
-
- extract_flushSortKeys (zh, *sysno, 1, zh->reg->sortKeys);
- extract_flushRecordKeys (zh, *sysno, 1, zh->reg->keys,
- recordAttr->staticrank);
- zh->records_inserted++;
- }
- else
- {
- /* record already exists */
- zebra_rec_keys_t delkeys = zebra_rec_keys_open();
-
- zebra_rec_keys_t sortKeys = zebra_rec_keys_open();
-
- rec = rec_get (zh->reg->records, *sysno);
- assert (rec);
-
- recordAttr = rec_init_attr (zh->reg->zei, rec);
-
- zebra_rec_keys_set_buf(delkeys,
- rec->info[recInfo_delKeys],
- rec->size[recInfo_delKeys],
- 0);
-
- zebra_rec_keys_set_buf(sortKeys,
- rec->info[recInfo_sortKeys],
- rec->size[recInfo_sortKeys],
- 0);
- extract_flushSortKeys (zh, *sysno, 0, sortKeys);
- extract_flushRecordKeys (zh, *sysno, 0, delkeys,
- recordAttr->staticrank); /* old values */
- if (deleteFlag)
- {
- /* record going to be deleted */
- if (zebra_rec_keys_empty(delkeys))
- {
- yaz_log (YLOG_LOG, "delete %s %s " PRINTF_OFF_T
- " " ZINT_FORMAT,
- zh->m_record_type, fname, recordOffset, *sysno);
- yaz_log (YLOG_WARN, "cannot delete file above, storeKeys false (1)");
- }
- else
- {
- if (zh->records_processed < zh->m_file_verbose_limit)
- {
- yaz_log(YLOG_LOG, "delete %s %s " PRINTF_OFF_T
- " " ZINT_FORMAT " %s" ,
- zh->m_record_type,
- fname, recordOffset, *sysno, match_str_to_print);
- }
- zh->records_deleted++;
- if (matchStr)
- {
- int db_ord = zebraExplain_get_database_ord(zh->reg->zei);
- dict_delete_ord(zh->reg->matchDict, db_ord, matchStr);
- }
- rec_del (zh->reg->records, &rec);
- }
- rec_rm (&rec);
- logRecord (zh);
- return ZEBRA_OK;
- }
- else
- {
- /* flush new keys for sort&search etc */
- if (zh->records_processed < zh->m_file_verbose_limit)
- {
- yaz_log(YLOG_LOG, "update %s %s " PRINTF_OFF_T
- " " ZINT_FORMAT " %s" ,
- zh->m_record_type,
- fname, recordOffset, *sysno, match_str_to_print);
- }
- recordAttr->staticrank = extractCtrl.staticrank;
- extract_flushSortKeys (zh, *sysno, 1, zh->reg->sortKeys);
- extract_flushRecordKeys (zh, *sysno, 1, zh->reg->keys,
- recordAttr->staticrank);
- zh->records_updated++;
- }
- zebra_rec_keys_close(delkeys);
- zebra_rec_keys_close(sortKeys);
- }
- /* update file type */
- xfree (rec->info[recInfo_fileType]);
- rec->info[recInfo_fileType] =
- rec_strdup (zh->m_record_type, &rec->size[recInfo_fileType]);
-
- /* update filename */
- xfree (rec->info[recInfo_filename]);
- rec->info[recInfo_filename] =
- rec_strdup (fname, &rec->size[recInfo_filename]);
-
- /* update delete keys */
- xfree (rec->info[recInfo_delKeys]);
- if (!zebra_rec_keys_empty(zh->reg->keys) && zh->m_store_keys == 1)
- {
- zebra_rec_keys_get_buf(zh->reg->keys,
- &rec->info[recInfo_delKeys],
- &rec->size[recInfo_delKeys]);
- }
- else
- {
- rec->info[recInfo_delKeys] = NULL;
- rec->size[recInfo_delKeys] = 0;
- }
-
- /* update sort keys */
- xfree (rec->info[recInfo_sortKeys]);
-
- zebra_rec_keys_get_buf(zh->reg->sortKeys,
- &rec->info[recInfo_sortKeys],
- &rec->size[recInfo_sortKeys]);
-
- /* save file size of original record */
- zebraExplain_recordBytesIncrement (zh->reg->zei,
- - recordAttr->recordSize);
- recordAttr->recordSize = fi->file_moffset - recordOffset;
- if (!recordAttr->recordSize)
- recordAttr->recordSize = fi->file_max - recordOffset;
- zebraExplain_recordBytesIncrement (zh->reg->zei,
- recordAttr->recordSize);
-
- /* set run-number for this record */
- recordAttr->runNumber = zebraExplain_runNumberIncrement (zh->reg->zei,
- 0);
-
- /* update store data */
- xfree (rec->info[recInfo_storeData]);
- if (zh->store_data_buf)
- {
- rec->size[recInfo_storeData] = zh->store_data_size;
- rec->info[recInfo_storeData] = zh->store_data_buf;
- zh->store_data_buf = 0;
- }
- else if (zh->m_store_data)
- {
- rec->size[recInfo_storeData] = recordAttr->recordSize;
- rec->info[recInfo_storeData] = (char *)
- xmalloc (recordAttr->recordSize);
- if (lseek (fi->fd, recordOffset, SEEK_SET) < 0)
- {
- yaz_log (YLOG_ERRNO|YLOG_FATAL, "seek to " PRINTF_OFF_T " in %s",
- recordOffset, fname);
- exit (1);
- }
- if (read (fi->fd, rec->info[recInfo_storeData], recordAttr->recordSize)
- < recordAttr->recordSize)
- {
- yaz_log (YLOG_ERRNO|YLOG_FATAL, "read %d bytes of %s",
- recordAttr->recordSize, fname);
- exit (1);
- }
- }
- else
- {
- rec->info[recInfo_storeData] = NULL;
- rec->size[recInfo_storeData] = 0;
- }
- /* update database name */
- xfree (rec->info[recInfo_databaseName]);
- rec->info[recInfo_databaseName] =
- rec_strdup (zh->basenames[0], &rec->size[recInfo_databaseName]);
-
- /* update offset */
- recordAttr->recordOffset = recordOffset;
-
- /* commit this record */
- rec_put (zh->reg->records, &rec);
- logRecord (zh);
- return ZEBRA_OK;
-}
-
-ZEBRA_RES zebra_extract_file(ZebraHandle zh, SYSNO *sysno, const char *fname,
- int deleteFlag)
-{
- ZEBRA_RES r = ZEBRA_OK;
- int i, fd;
- char gprefix[128];
- char ext[128];
- char ext_res[128];
- struct file_read_info *fi;
- const char *original_record_type = 0;
- RecType recType;
- void *recTypeClientData;
-
- if (!zh->m_group || !*zh->m_group)
- *gprefix = '\0';
- else
- sprintf (gprefix, "%s.", zh->m_group);
-
- yaz_log (YLOG_DEBUG, "fileExtract %s", fname);