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 <[email protected]>
---
 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

Reply via email to