[pacman-dev] [PATCH 1/2] Add function to set and get expiry time for a repo database
Signed-off-by: Allan McRae <allan@archlinux.org> --- lib/libalpm/alpm.h | 14 ++++++++++++++ lib/libalpm/db.c | 14 ++++++++++++++ lib/libalpm/db.h | 2 ++ 3 files changed, 30 insertions(+) diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 956284bd..0a4d7fe7 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -1026,6 +1026,20 @@ int alpm_db_set_usage(alpm_db_t *db, int usage); */ int alpm_db_get_usage(alpm_db_t *db, int *usage); + +/** Sets the expiry time of a database. + * @param db pointer to the package database to set the status for + * @param expiry number of days old a database can be before expiry + * @return 0 on success, or -1 on error + */ +int alpm_db_set_expiry(alpm_db_t *db, int expiry); + +/** Gets the expiry time of a database. + * @param db pointer to the package database to get the status of + * @return expiry time + */ +int alpm_db_get_expiry(alpm_db_t *db); + /** @} */ /** @addtogroup alpm_api_packages Package Functions diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c index 43ca1fc8..a4fd4353 100644 --- a/lib/libalpm/db.c +++ b/lib/libalpm/db.c @@ -325,6 +325,20 @@ int SYMEXPORT alpm_db_get_usage(alpm_db_t *db, int *usage) return 0; } +/** Sets the expiry time for a repo */ +int SYMEXPORT alpm_db_set_expiry(alpm_db_t *db, int expiry) +{ + ASSERT(db != NULL, return -1); + db->expiry = expiry; + return 0; +} + +/** Gets the expiry time for a repo */ +int SYMEXPORT alpm_db_get_expiry(alpm_db_t *db) +{ + ASSERT(db != NULL, return -1); + return db->expiry; +} /** @} */ diff --git a/lib/libalpm/db.h b/lib/libalpm/db.h index e7ad98f5..76947247 100644 --- a/lib/libalpm/db.h +++ b/lib/libalpm/db.h @@ -79,6 +79,8 @@ struct __alpm_db_t { int siglevel; /* alpm_db_usage_t */ int usage; + + int expiry; }; -- 2.24.1
RepoExpiry is an integer value representing the number of days after creation that a repo is expired. This can be set globally, and per repo. Signed-off-by: Allan McRae <allan@archlinux.org> --- src/pacman/conf.c | 41 ++++++++++++++++++++++++++++++++++++++++- src/pacman/conf.h | 3 +++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/pacman/conf.c b/src/pacman/conf.c index 3b475151..5137bd41 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -110,6 +110,7 @@ config_t *config_new(void) newconfig->localfilesiglevel = ALPM_SIG_USE_DEFAULT; newconfig->remotefilesiglevel = ALPM_SIG_USE_DEFAULT; } + newconfig->repoexpiry = -1; newconfig->colstr.colon = ":: "; newconfig->colstr.title = ""; @@ -677,6 +678,22 @@ static int _parse_options(const char *key, char *value, return 1; } FREELIST(values); + } else if(strcmp(key, "RepoExpiry") == 0) { + char *end = NULL; + long expiry = strtol(value, &end, 10); + if(*end) { + pm_printf(ALPM_LOG_ERROR, + _("config file %s, line %d: '%s' value '%s' not recognized\n"), + file, linenum, "RepoExpiry", value); + return 1; + } + if(expiry > INT_MAX) { + pm_printf(ALPM_LOG_ERROR, + _("config file %s, line %d: '%s' value '%s' is too large\n"), + file, linenum, "RepoExpiry", value); + return 1; + } + config->repoexpiry = (int)expiry; } else { pm_printf(ALPM_LOG_WARNING, _("config file %s, line %d: directive '%s' in section '%s' not recognized.\n"), @@ -745,6 +762,11 @@ static int register_repo(config_repo_t *repo) } } + int expiry = ( repo->expiry != -1 ? repo->expiry : config->repoexpiry); + pm_printf(ALPM_LOG_DEBUG, "setting expiry of %d for %s repository\n", + expiry, repo->name); + alpm_db_set_expiry(db, expiry); + return 0; } @@ -908,7 +930,6 @@ static int process_usage(alpm_list_t *values, int *usage, return ret; } - static int _parse_repo(const char *key, char *value, const char *file, int line, struct section_t *section) { @@ -946,6 +967,23 @@ static int _parse_repo(const char *key, char *value, const char *file, } FREELIST(values); } + } else if(strcmp(key, "RepoExpiry") == 0) { + CHECK_VALUE(value); + char *end = NULL; + long expiry = strtol(value, &end, 10); + if(*end) { + pm_printf(ALPM_LOG_ERROR, + _("config file %s, line %d: '%s' value '%s' not recognized\n"), + file, line, "RepoExpiry", value); + return 1; + } + if(expiry > INT_MAX) { + pm_printf(ALPM_LOG_ERROR, + _("config file %s, line %d: '%s' value '%s' is too large\n"), + file, line, "RepoExpiry", value); + return 1; + } + repo->expiry = (int)expiry; } else { pm_printf(ALPM_LOG_WARNING, _("config file %s, line %d: directive '%s' in section '%s' not recognized.\n"), @@ -1038,6 +1076,7 @@ static int _parse_directive(const char *file, int linenum, const char *name, section->repo->name = strdup(name); section->repo->siglevel = ALPM_SIG_USE_DEFAULT; section->repo->usage = 0; + section->repo->expiry = -1; config->repos = alpm_list_add(config->repos, section->repo); } return 0; diff --git a/src/pacman/conf.h b/src/pacman/conf.h index 03a15a48..91f1c797 100644 --- a/src/pacman/conf.h +++ b/src/pacman/conf.h @@ -40,6 +40,7 @@ typedef struct __config_repo_t { int usage; int siglevel; int siglevel_mask; + int expiry; } config_repo_t; typedef struct __config_t { @@ -107,6 +108,8 @@ typedef struct __config_t { int localfilesiglevel_mask; int remotefilesiglevel_mask; + int repoexpiry; + /* conf file options */ /* I Love Candy! */ unsigned short chomp; -- 2.24.1
participants (1)
-
Allan McRae