[Pkg-gnupg-commit] [gnupg2] 35/159: gpg: Improve the keyblock cache's transparency.
Daniel Kahn Gillmor
dkg at fifthhorseman.net
Wed Jan 27 13:23:51 UTC 2016
This is an automated email from the git hooks/post-receive script.
dkg pushed a commit to branch master
in repository gnupg2.
commit f369efd6712148dc7ed40dba6d1ff5b0e169431a
Author: Neal H. Walfield <neal at g10code.com>
Date: Tue Dec 15 13:09:27 2015 +0100
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 at g10code.com>
---
g10/keydb.c | 6 ++++++
kbx/keybox-search.c | 29 +++++++++++++++++++++++++++++
kbx/keybox.h | 4 ++--
3 files changed, 37 insertions(+), 2 deletions(-)
diff --git a/g10/keydb.c b/g10/keydb.c
index 860187f..b308199 100644
--- a/g10/keydb.c
+++ b/g10/keydb.c
@@ -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;
}
diff --git a/kbx/keybox-search.c b/kbx/keybox-search.c
index df959b6..1edb4ae 100644
--- a/kbx/keybox-search.c
+++ b/kbx/keybox-search.c
@@ -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;
+}
diff --git a/kbx/keybox.h b/kbx/keybox.h
index c91a282..8b75db4 100644
--- a/kbx/keybox.h
+++ b/kbx/keybox.h
@@ -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,
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gnupg2.git
More information about the Pkg-gnupg-commit
mailing list