mirror of
git://git.gnupg.org/gnupg.git
synced 2024-12-22 10:19:57 +01:00
gpg: Improve the keyblock cache's transparency.
* kbx/keybox-search.c (keybox_seek): New function. * g10/keydb.c (keydb_search): When reading from the cache, seek to just after the cached record. -- Signed-off-by: Neal H. Walfield <neal@g10code.com>
This commit is contained in:
parent
2e4e10c1dc
commit
f369efd671
@ -1717,6 +1717,12 @@ keydb_search (KEYDB_HANDLE hd, KEYDB_SEARCH_DESC *desc,
|
||||
/* (DESCINDEX is already set). */
|
||||
if (DBG_CLOCK)
|
||||
log_clock ("keydb_search leave (cached)");
|
||||
|
||||
hd->current = hd->keyblock_cache.resource;
|
||||
/* HD->KEYBLOCK_CACHE.OFFSET is the last byte in the record.
|
||||
Seek just beyond that. */
|
||||
keybox_seek (hd->active[hd->current].u.kb,
|
||||
hd->keyblock_cache.offset + 1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1196,3 +1196,32 @@ keybox_offset (KEYBOX_HANDLE hd)
|
||||
return 0;
|
||||
return ftello (hd->fp);
|
||||
}
|
||||
|
||||
gpg_error_t
|
||||
keybox_seek (KEYBOX_HANDLE hd, off_t offset)
|
||||
{
|
||||
int err;
|
||||
|
||||
if (hd->error)
|
||||
return hd->error; /* still in error state */
|
||||
|
||||
if (! hd->fp)
|
||||
{
|
||||
if (offset == 0)
|
||||
/* No need to open the file. An unopened file is effectively at
|
||||
offset 0. */
|
||||
return 0;
|
||||
|
||||
hd->fp = fopen (hd->kb->fname, "rb");
|
||||
if (!hd->fp)
|
||||
{
|
||||
hd->error = gpg_error_from_syserror ();
|
||||
return hd->error;
|
||||
}
|
||||
}
|
||||
|
||||
err = fseeko (hd->fp, offset, SEEK_SET);
|
||||
hd->error = gpg_error_from_errno (err);
|
||||
|
||||
return hd->error;
|
||||
}
|
||||
|
@ -77,8 +77,6 @@ int keybox_set_ephemeral (KEYBOX_HANDLE hd, int yes);
|
||||
|
||||
int keybox_lock (KEYBOX_HANDLE hd, int yes);
|
||||
|
||||
off_t keybox_offset (KEYBOX_HANDLE hd);
|
||||
|
||||
/*-- keybox-file.c --*/
|
||||
/* Fixme: This function does not belong here: Provide a better
|
||||
interface to create a new keybox file. */
|
||||
@ -97,6 +95,8 @@ int keybox_search (KEYBOX_HANDLE hd, KEYBOX_SEARCH_DESC *desc, size_t ndesc,
|
||||
keybox_blobtype_t want_blobtype,
|
||||
size_t *r_descindex, unsigned long *r_skipped);
|
||||
|
||||
off_t keybox_offset (KEYBOX_HANDLE hd);
|
||||
gpg_error_t keybox_seek (KEYBOX_HANDLE hd, off_t offset);
|
||||
|
||||
/*-- keybox-update.c --*/
|
||||
gpg_error_t keybox_insert_keyblock (KEYBOX_HANDLE hd,
|
||||
|
Loading…
x
Reference in New Issue
Block a user