From 5dae577a87795e7666f05613cf9aa7207fd17346 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Mon, 24 Jan 2011 17:48:54 -0600 Subject: Get estimated package count when populating databases This works for both local and sync databases in slightly different ways. For the local database, we can use the directory hard link count on the local/ folder. For sync databases, we use the archive size coupled with some computed average per-package sizes to determine an estimate. This is currently a dead assignment once calculated, but could be used to set the initial size of a hash table. Signed-off-by: Dan McGee Signed-off-by: Allan McRae --- lib/libalpm/be_local.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'lib/libalpm/be_local.c') diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c index c7110faf..b97fca71 100644 --- a/lib/libalpm/be_local.c +++ b/lib/libalpm/be_local.c @@ -367,7 +367,8 @@ static int is_dir(const char *path, struct dirent *entry) static int local_db_populate(pmdb_t *db) { - int count = 0; + int est_count, count = 0; + struct stat buf; struct dirent *ent = NULL; const char *dbpath; DIR *dbdir; @@ -384,6 +385,11 @@ static int local_db_populate(pmdb_t *db) if(dbdir == NULL) { return(0); } + if(fstat(dirfd(dbdir), &buf) != 0) { + return(0); + } + /* subtract the two always-there pointers to get # of children */ + est_count = (int)buf.st_nlink - 2; while((ent = readdir(dbdir)) != NULL) { const char *name = ent->d_name; -- cgit v1.2.3-24-g4f1b