[pacman-dev] [PATCH 04/13] libalpm: handle both .db and .files extensions

Andrew Gregory andrew.gregory.8 at gmail.com
Sat Jun 20 13:29:01 UTC 2015


On 06/20/15 at 05:42pm, Allan McRae wrote:
> Reads from the .db or .files database depending on the flags in the handle.
> 
> Signed-off-by: Allan McRae <allan at archlinux.org>
> ---
>  lib/libalpm/be_sync.c | 23 +++++++++++++++++------
>  lib/libalpm/db.c      | 10 ++++++++--
>  2 files changed, 25 insertions(+), 8 deletions(-)

I don't really like hard-coding a distinction between normal db's and
file db's in alpm.  We already have to teach alpm to handle multiple
db extensions, so we could just make the extension configurable and
allow the front-end to do the selection.  That way alpm would simply
use whatever it's given and treat all sync db's the same.  With proper
front-end support, which could easily be added later, this would allow
a distribution to choose to provide only a files db in order to
prevent the primary and files db's from getting out of sync.

In order to reduce unnecessary overhead, the files option could be
retained solely to indicate whether or not to actually load the files
from syncdb's or we could lazy load them as we do for local packages,
although we would probably want to load all file lists from a given db
at once.

apg

> diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c
> index ea979e6..2214edf 100644
> --- a/lib/libalpm/be_sync.c
> +++ b/lib/libalpm/be_sync.c
> @@ -174,6 +174,7 @@ valid:
>  int SYMEXPORT alpm_db_update(int force, alpm_db_t *db)
>  {
>  	char *syncpath;
> +	const char *db_suffix = NULL;
>  	alpm_list_t *i;
>  	int ret = -1;
>  	mode_t oldmask;
> @@ -208,6 +209,13 @@ int SYMEXPORT alpm_db_update(int force, alpm_db_t *db)
>  		RET_ERR(handle, ALPM_ERR_HANDLE_LOCK, -1);
>  	}
>  
> +	/* determine db suffix */
> +	if(handle->files == 0) {
> +		db_suffix = ".db";
> +	} else {
> +		db_suffix = ".files";
> +	}
> +
>  	for(i = db->servers; i; i = i->next) {
>  		const char *server = i->data, *final_db_url = NULL;
>  		struct dload_payload payload;
> @@ -220,10 +228,11 @@ int SYMEXPORT alpm_db_update(int force, alpm_db_t *db)
>  		payload.max_size = 25 * 1024 * 1024;
>  
>  		/* print server + filename into a buffer */
> -		len = strlen(server) + strlen(db->treename) + 5;
> +		len = strlen(server) + strlen(db->treename) + strlen(db_suffix) + 2;
>  		/* TODO fix leak syncpath and umask unset */
>  		MALLOC(payload.fileurl, len, RET_ERR(handle, ALPM_ERR_MEMORY, -1));
> -		snprintf(payload.fileurl, len, "%s/%s.db", server, db->treename);
> +		snprintf(payload.fileurl, len, "%s/%s%s", server, db->treename, db_suffix);
> +
>  		payload.handle = handle;
>  		payload.force = force;
>  		payload.unlink_on_fail = 1;
> @@ -244,7 +253,9 @@ int SYMEXPORT alpm_db_update(int force, alpm_db_t *db)
>  
>  			/* check if the final URL from internal downloader looks reasonable */
>  			if(final_db_url != NULL) {
> -				if(strlen(final_db_url) < 3 || strcmp(final_db_url + strlen(final_db_url) - 3, ".db") != 0) {
> +				if(strlen(final_db_url) < 3 ||
> +						strcmp(final_db_url + strlen(final_db_url) - strlen(db_suffix),
> +								db_suffix) != 0) {
>  					final_db_url = NULL;
>  				}
>  			}
> @@ -254,8 +265,8 @@ int SYMEXPORT alpm_db_update(int force, alpm_db_t *db)
>  				/* print final_db_url into a buffer (leave space for .sig) */
>  				len = strlen(final_db_url) + 5;
>  			} else {
> -				/* print server + filename into a buffer (leave space for separator and .db.sig) */
> -				len = strlen(server) + strlen(db->treename) + 9;
> +				/* print server + filename into a buffer (leave space for separator and .sig) */
> +				len = strlen(server) + 1 + strlen(db->treename) + strlen(db_suffix) + 5;
>  			}
>  
>  			/* TODO fix leak syncpath and umask unset */
> @@ -264,7 +275,7 @@ int SYMEXPORT alpm_db_update(int force, alpm_db_t *db)
>  			if(final_db_url != NULL) {
>  				snprintf(payload.fileurl, len, "%s.sig", final_db_url);
>  			} else {
> -				snprintf(payload.fileurl, len, "%s/%s.db.sig", server, db->treename);
> +				snprintf(payload.fileurl, len, "%s/%s%s.sig", server, db->treename, db_suffix);
>  			}
>  
>  			payload.handle = handle;
> diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c
> index fe208be..7c79e1c 100644
> --- a/lib/libalpm/db.c
> +++ b/lib/libalpm/db.c
> @@ -375,10 +375,16 @@ const char *_alpm_db_path(alpm_db_t *db)
>  			CALLOC(db->_path, 1, pathsize, RET_ERR(db->handle, ALPM_ERR_MEMORY, NULL));
>  			sprintf(db->_path, "%s%s/", dbpath, db->treename);
>  		} else {
> -			pathsize = strlen(dbpath) + 5 + strlen(db->treename) + 4;
> +			const char *suffix;
> +			if(db->handle->files == 0) {
> +				suffix = ".db";
> +			} else {
> +				suffix = ".files";
> +			}
> +			pathsize = strlen(dbpath) + 5 + strlen(db->treename) + strlen(suffix) + 1;
>  			CALLOC(db->_path, 1, pathsize, RET_ERR(db->handle, ALPM_ERR_MEMORY, NULL));
>  			/* all sync DBs now reside in the sync/ subdir of the dbpath */
> -			sprintf(db->_path, "%ssync/%s.db", dbpath, db->treename);
> +			sprintf(db->_path, "%ssync/%s%s", dbpath, db->treename, suffix);
>  		}
>  		_alpm_log(db->handle, ALPM_LOG_DEBUG, "database path for tree %s set to %s\n",
>  				db->treename, db->_path);
> -- 
> 2.4.4


More information about the pacman-dev mailing list