[pacman-dev] [PATCH 03/13] Add files option to handle
This option will be used to determine if the .files database should be used for reading sync information. Signed-off-by: Allan McRae <allan@archlinux.org> --- lib/libalpm/alpm.h | 9 +++++++++ lib/libalpm/handle.c | 13 +++++++++++++ lib/libalpm/handle.h | 1 + 3 files changed, 23 insertions(+) diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 06e080b..a6cabc9 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -155,6 +155,12 @@ typedef enum _alpm_pkgfrom_t { ALPM_PKG_FROM_SYNCDB } alpm_pkgfrom_t; +/** Database extension options */ +typedef enum _alpm_dbtype_t { + ALPM_DBTYPE_DB, + ALPM_DBTYPE_FILES +} alpm_dbtype_t; + /** Method used to validate a package. */ typedef enum _alpm_pkgvalidation_t { ALPM_PKG_VALIDATION_UNKNOWN = 0, @@ -859,6 +865,9 @@ int alpm_option_set_deltaratio(alpm_handle_t *handle, double ratio); int alpm_option_get_checkspace(alpm_handle_t *handle); int alpm_option_set_checkspace(alpm_handle_t *handle, int checkspace); +alpm_dbtype_t alpm_option_get_dbtype(alpm_handle_t *handle); +int alpm_option_set_dbtype(alpm_handle_t *handle, alpm_dbtype_t dbtype); + alpm_siglevel_t alpm_option_get_default_siglevel(alpm_handle_t *handle); int alpm_option_set_default_siglevel(alpm_handle_t *handle, alpm_siglevel_t level); diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c index 4915d0b..df81f0d 100644 --- a/lib/libalpm/handle.c +++ b/lib/libalpm/handle.c @@ -284,6 +284,12 @@ int SYMEXPORT alpm_option_get_checkspace(alpm_handle_t *handle) return handle->checkspace; } +alpm_dbtype_t SYMEXPORT alpm_option_get_dbtype(alpm_handle_t *handle) +{ + CHECK_HANDLE(handle, return -1); + return handle->dbtype; +} + int SYMEXPORT alpm_option_set_logcb(alpm_handle_t *handle, alpm_cb_log cb) { CHECK_HANDLE(handle, return -1); @@ -664,6 +670,13 @@ int SYMEXPORT alpm_option_set_checkspace(alpm_handle_t *handle, int checkspace) return 0; } +int SYMEXPORT alpm_option_set_dbtype(alpm_handle_t *handle, alpm_dbtype_t dbtype) +{ + CHECK_HANDLE(handle, return -1); + handle->dbtype = dbtype; + return 0; +} + int SYMEXPORT alpm_option_set_default_siglevel(alpm_handle_t *handle, alpm_siglevel_t level) { diff --git a/lib/libalpm/handle.h b/lib/libalpm/handle.h index 5893139..7fd470e 100644 --- a/lib/libalpm/handle.h +++ b/lib/libalpm/handle.h @@ -95,6 +95,7 @@ struct __alpm_handle_t { double deltaratio; /* Download deltas if possible; a ratio value */ int usesyslog; /* Use syslog instead of logfile? */ /* TODO move to frontend */ int checkspace; /* Check disk space before installing */ + alpm_dbtype_t dbtype; /* Set the database type (extension) */ alpm_siglevel_t siglevel; /* Default signature verification level */ alpm_siglevel_t localfilesiglevel; /* Signature verification level for local file upgrade operations */ -- 2.4.4
Reads from the .db or .files database depending on the flags in the handle. Signed-off-by: Allan McRae <allan@archlinux.org> --- lib/libalpm/be_sync.c | 18 ++++++++++++------ lib/libalpm/db.c | 19 +++++++++++++++++-- lib/libalpm/db.h | 1 + 3 files changed, 30 insertions(+), 8 deletions(-) diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c index ea979e6..dfe78ea 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,8 @@ int SYMEXPORT alpm_db_update(int force, alpm_db_t *db) RET_ERR(handle, ALPM_ERR_HANDLE_LOCK, -1); } + db_suffix = _alpm_db_suffix(db); + for(i = db->servers; i; i = i->next) { const char *server = i->data, *final_db_url = NULL; struct dload_payload payload; @@ -220,10 +223,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 +248,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 +260,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 +270,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..949a01f 100644 --- a/lib/libalpm/db.c +++ b/lib/libalpm/db.c @@ -375,10 +375,12 @@ 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 = _alpm_db_suffix(db); + + 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); @@ -386,6 +388,19 @@ const char *_alpm_db_path(alpm_db_t *db) return db->_path; } +const char *_alpm_db_suffix(alpm_db_t *db) { + const char *suffix = NULL; + switch(db->handle->dbtype) { + case ALPM_DBTYPE_DB: + suffix = ".db"; + break; + case ALPM_DBTYPE_FILES: + suffix = ".files"; + break; + } + return suffix; +} + int _alpm_db_cmp(const void *d1, const void *d2) { const alpm_db_t *db1 = d1; diff --git a/lib/libalpm/db.h b/lib/libalpm/db.h index b19cb3f..3378c9e 100644 --- a/lib/libalpm/db.h +++ b/lib/libalpm/db.h @@ -88,6 +88,7 @@ alpm_db_t *_alpm_db_register_local(alpm_handle_t *handle); alpm_db_t *_alpm_db_register_sync(alpm_handle_t *handle, const char *treename, alpm_siglevel_t level); void _alpm_db_unregister(alpm_db_t *db); +const char *_alpm_db_suffix(alpm_db_t *db); /* be_*.c, backend specific calls */ int _alpm_local_db_prepare(alpm_db_t *db, alpm_pkg_t *info); -- 2.4.4
participants (1)
-
Allan McRae