aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJason Woodward2008-11-25 05:08:34 +0000
committerJason Woodward2008-11-25 05:08:34 +0000
commit9c93560701f95046335c0a69cac26a81969df01e (patch)
treed04c7f3a66373268cc00982d2e6c40ee83ff8073 /src
parent8d31622d3a7d3d6dc6fd109756baf56b56a7c799 (diff)
downloadslapt-get-9c93560701f95046335c0a69cac26a81969df01e.tar.gz
* (libslapt) added slapt_write_rc_config (incorporating from gslapt)
* (libslapt) added parsing of disabled sources (instead of ignoring what gslapt creates). * test updates * Added source priority support based on patch submitted by Ken Milmore
Diffstat (limited to 'src')
-rw-r--r--src/action.c8
-rw-r--r--src/common.c36
-rw-r--r--src/common.h19
-rw-r--r--src/configuration.c265
-rw-r--r--src/configuration.h28
-rw-r--r--src/package.c108
-rw-r--r--src/package.h5
7 files changed, 352 insertions, 117 deletions
diff --git a/src/action.c b/src/action.c
index 899dddf..489fcfa 100644
--- a/src/action.c
+++ b/src/action.c
@@ -429,6 +429,7 @@ void slapt_pkg_action_show(const char *pkg_name)
printf(gettext("Package Name: %s\n"),pkg->name);
printf(gettext("Package Mirror: %s\n"),pkg->mirror);
+ printf(gettext("Package Priority: %s\n"),slapt_priority_to_str(pkg->priority));
printf(gettext("Package Location: %s\n"),pkg->location);
printf(gettext("Package Version: %s\n"),pkg->version);
printf(gettext("Package Size: %d K\n"),pkg->size_c);
@@ -781,10 +782,9 @@ void slapt_pkg_action_add_keys(const slapt_rc_config *global_config)
for(s = 0; s < global_config->sources->count; s++)
{
FILE *gpg_key = NULL;
- printf(gettext("Retrieving GPG key [%s]..."), global_config->sources->url[s]);
- gpg_key = slapt_get_pkg_source_gpg_key (global_config,
- global_config->sources->url[s],
- &compressed);
+ const char *source_url = global_config->sources->src[s]->url;
+ printf(gettext("Retrieving GPG key [%s]..."), source_url);
+ gpg_key = slapt_get_pkg_source_gpg_key (global_config, source_url, &compressed);
if (gpg_key != NULL)
{
slapt_code_t r = slapt_add_pkg_source_gpg_key(gpg_key);
diff --git a/src/common.c b/src/common.c
index b3ca397..94bca2c 100644
--- a/src/common.c
+++ b/src/common.c
@@ -36,7 +36,12 @@ FILE *slapt_open_file(const char *file_name,const char *mode)
/* initialize regex structure and compile the regular expression */
slapt_regex_t *slapt_init_regex(const char *regex_string)
{
- slapt_regex_t *r = slapt_malloc(sizeof *r);
+ slapt_regex_t *r;
+
+ if (regex_string == NULL)
+ return NULL;
+
+ r = slapt_malloc(sizeof *r);
r->nmatch = SLAPT_MAX_REGEX_PARTS;
r->reg_return = -1;
@@ -321,8 +326,33 @@ const char *slapt_strerror(slapt_code_t code)
case SLAPT_CHECKSUMS_MISSING_KEY:
return gettext("No key for verification");
#endif
- };
-
+ default:
return gettext("Unknown error");
+ };
}
+const char *slapt_priority_to_str(SLAPT_PRIORITY_T priority)
+{
+
+ switch(priority) {
+ case SLAPT_PRIORITY_DEFAULT:
+ return gettext("Default");
+ case SLAPT_PRIORITY_DEFAULT_PATCH:
+ return gettext("Default Patch");
+ case SLAPT_PRIORITY_PREFERRED:
+ return gettext("Preferred");
+ case SLAPT_PRIORITY_PREFERRED_PATCH:
+ return gettext("Preferred Patch");
+ case SLAPT_PRIORITY_OFFICIAL:
+ return gettext("Official");
+ case SLAPT_PRIORITY_OFFICIAL_PATCH:
+ return gettext("Official Patch");
+ case SLAPT_PRIORITY_CUSTOM:
+ return gettext("Custom");
+ case SLAPT_PRIORITY_CUSTOM_PATCH:
+ return gettext("Custom Patch");
+ default:
+ return NULL;
+ };
+
+}
diff --git a/src/common.h b/src/common.h
index 27d4a3d..2aa29b3 100644
--- a/src/common.h
+++ b/src/common.h
@@ -26,6 +26,22 @@ typedef enum {
SLAPT_DOWNLOAD_INCOMPLETE
} slapt_code_t;
+typedef enum {
+ SLAPT_PRIORITY_DEFAULT = 0,
+ SLAPT_PRIORITY_DEFAULT_PATCH,
+ SLAPT_PRIORITY_PREFERRED,
+ SLAPT_PRIORITY_PREFERRED_PATCH,
+ SLAPT_PRIORITY_OFFICIAL,
+ SLAPT_PRIORITY_OFFICIAL_PATCH,
+ SLAPT_PRIORITY_CUSTOM,
+ SLAPT_PRIORITY_CUSTOM_PATCH
+} SLAPT_PRIORITY_T;
+
+#define SLAPT_PRIORITY_DEFAULT_TOKEN "DEFAULT"
+#define SLAPT_PRIORITY_PREFERRED_TOKEN "PREFERRED"
+#define SLAPT_PRIORITY_OFFICIAL_TOKEN "OFFICIAL"
+#define SLAPT_PRIORITY_CUSTOM_TOKEN "CUSTOM"
+
typedef struct {
regmatch_t pmatch[SLAPT_MAX_REGEX_PARTS];
regex_t regex;
@@ -54,4 +70,5 @@ __inline void *slapt_calloc(size_t n,size_t s);
/* return human readable error */
const char *slapt_strerror(slapt_code_t code);
-
+/* return human readable priority */
+const char *slapt_priority_to_str(SLAPT_PRIORITY_T priority);
diff --git a/src/configuration.c b/src/configuration.c
index 120e223..88f9b09 100644
--- a/src/configuration.c
+++ b/src/configuration.c
@@ -69,33 +69,42 @@ slapt_rc_config *slapt_read_rc_config(const char *file_name)
/* check to see if it has our key and value seperated by our token */
/* and extract them */
- if ( getline_buffer[0] == '#' ) {
- continue;
- }
-
- if ( strstr(getline_buffer,SOURCE_TOKEN) != NULL ) {
+ if ( strstr(getline_buffer,SLAPT_SOURCE_TOKEN) != NULL ) {
/* SOURCE URL */
- if ( strlen(getline_buffer) > strlen(SOURCE_TOKEN) ) {
- slapt_add_source(global_config->sources,getline_buffer +
- strlen(SOURCE_TOKEN));
+ if ( strlen(getline_buffer) > strlen(SLAPT_SOURCE_TOKEN) ) {
+ slapt_source_t *s = slapt_init_source(getline_buffer + strlen(SLAPT_SOURCE_TOKEN));
+ if (s != NULL) {
+ slapt_add_source(global_config->sources,s);
+ }
+ }
+
+ } else if ( strstr(getline_buffer,SLAPT_DISABLED_SOURCE_TOKEN) != NULL ) {
+ /* DISABLED SOURCE */
+
+ if (strlen(getline_buffer) > strlen(SLAPT_DISABLED_SOURCE_TOKEN) ) {
+ slapt_source_t *s = slapt_init_source(getline_buffer + strlen(SLAPT_DISABLED_SOURCE_TOKEN));
+ if (s != NULL) {
+ s->disabled = SLAPT_TRUE;
+ slapt_add_source(global_config->sources,s);
+ }
}
- } else if ( strstr(getline_buffer,WORKINGDIR_TOKEN) != NULL ) {
+ } else if ( strstr(getline_buffer,SLAPT_WORKINGDIR_TOKEN) != NULL ) {
/* WORKING DIR */
- if ( strlen(getline_buffer) > strlen(WORKINGDIR_TOKEN) ) {
+ if ( strlen(getline_buffer) > strlen(SLAPT_WORKINGDIR_TOKEN) ) {
strncpy(
global_config->working_dir,
- getline_buffer + strlen(WORKINGDIR_TOKEN),
- (strlen(getline_buffer) - strlen(WORKINGDIR_TOKEN))
+ getline_buffer + strlen(SLAPT_WORKINGDIR_TOKEN),
+ (strlen(getline_buffer) - strlen(SLAPT_WORKINGDIR_TOKEN))
);
global_config->working_dir[
- (strlen(getline_buffer) - strlen(WORKINGDIR_TOKEN))
+ (strlen(getline_buffer) - strlen(SLAPT_WORKINGDIR_TOKEN))
] = '\0';
}
- } else if ( strstr(getline_buffer,EXCLUDE_TOKEN) != NULL ) {
+ } else if ( strstr(getline_buffer,SLAPT_EXCLUDE_TOKEN) != NULL ) {
/* exclude list */
slapt_free_exclude_list(global_config->exclude_list);
global_config->exclude_list = parse_exclude(getline_buffer);
@@ -286,93 +295,58 @@ void slapt_free_exclude_list(struct slapt_exclude_list *list)
struct slapt_source_list *slapt_init_source_list(void)
{
struct slapt_source_list *list = slapt_malloc(sizeof *list);
- list->url = slapt_malloc(sizeof *list->url);
+ list->src = slapt_malloc(sizeof *list->src);
list->count = 0;
return list;
}
-void slapt_add_source(struct slapt_source_list *list,const char *s)
+void slapt_add_source(struct slapt_source_list *list,slapt_source_t *s)
{
- char **realloc_tmp;
- int source_len = 0;
+ slapt_source_t **realloc_tmp;
if ( s == NULL )
return;
- source_len = strlen(s);
-
- realloc_tmp = realloc(list->url,sizeof *list->url * (list->count + 1) );
+ realloc_tmp = realloc(list->src,sizeof *list->src * (list->count + 1) );
if ( realloc_tmp == NULL )
return;
- list->url = realloc_tmp;
-
- if ( s[source_len - 1] == '/' ) {
-
- list->url[ list->count ] = strndup(s,source_len);
- list->url[ list->count ][source_len] = '\0';
-
- } else {
-
- list->url[ list->count ] = slapt_malloc(
- sizeof *list->url[list->count] * (source_len + 2)
- );
- list->url[list->count][0] = '\0';
-
- list->url[list->count] = strncat(
- list->url[list->count],
- s,
- source_len
- );
-
- if (isblank(list->url[list->count][source_len - 1]) == 0) {
- list->url[list->count] = strncat(list->url[list->count], "/", 1);
- } else {
- if (list->url[list->count][source_len - 2] == '/') {
- list->url[list->count][source_len - 2] = '/';
- list->url[list->count][source_len - 1] = '\0';
- } else {
- list->url[list->count][source_len - 1] = '/';
- }
- }
-
- list->url[list->count][source_len + 1] = '\0';
-
- }
+ list->src = realloc_tmp;
+ list->src[list->count] = s;
++list->count;
}
void slapt_remove_source (struct slapt_source_list *list, const char *s)
{
- char *tmp = NULL;
+ slapt_source_t *src_to_discard = NULL;
unsigned int i = 0;
while ( i < list->count ) {
- if ( strcmp(s,list->url[i]) == 0 && tmp == NULL ) {
- tmp = list->url[i];
+ if ( strcmp(s,list->src[i]->url) == 0 && src_to_discard == NULL ) {
+ src_to_discard = list->src[i];
}
- if ( tmp != NULL && (i+1 < list->count) ) {
- list->url[i] = list->url[i + 1];
+ if ( src_to_discard != NULL && (i+1 < list->count) ) {
+ list->src[i] = list->src[i + 1];
}
++i;
}
- if ( tmp != NULL ) {
- char **realloc_tmp;
+ if ( src_to_discard != NULL ) {
+ slapt_source_t **realloc_tmp;
int count = list->count - 1;
if ( count < 1 )
count = 1;
- free(tmp);
+ slapt_free_source(src_to_discard);
- realloc_tmp = realloc(list->url,sizeof *list->url * count );
+ realloc_tmp = realloc(list->src,sizeof *list->src * count );
if ( realloc_tmp != NULL ) {
- list->url = realloc_tmp;
+ list->src = realloc_tmp;
if (list->count > 0)
--list->count;
}
@@ -386,9 +360,9 @@ void slapt_free_source_list(struct slapt_source_list *list)
unsigned int i;
for (i = 0; i < list->count; ++i) {
- free(list->url[i]);
+ slapt_free_source(list->src[i]);
}
- free(list->url);
+ free(list->src);
free(list);
}
@@ -401,3 +375,160 @@ SLAPT_BOOL_T slapt_is_interactive(const slapt_rc_config *global_config)
return interactive;
}
+
+static void slapt_source_parse_attributes(slapt_source_t *s, const char *string)
+{
+ int offset = 0;
+ int len = strlen(string);
+
+ while (offset < len) {
+ char *token = NULL;
+
+ if (strchr(string + offset, ',') != NULL) {
+ size_t token_len = strcspn(string + offset, ",");
+ if (token_len > 0) {
+ token = strndup(string + offset, token_len);
+ offset += token_len + 1;
+ }
+ } else {
+ token = strdup(string + offset);
+ offset += len;
+ }
+
+ if (token != NULL) {
+
+ if (strcmp(token,SLAPT_PRIORITY_DEFAULT_TOKEN) == 0) {
+ s->priority = SLAPT_PRIORITY_DEFAULT;
+ } else if (strcmp(token,SLAPT_PRIORITY_PREFERRED_TOKEN) == 0) {
+ s->priority = SLAPT_PRIORITY_PREFERRED;
+ } else if (strcmp(token,SLAPT_PRIORITY_OFFICIAL_TOKEN) == 0) {
+ s->priority = SLAPT_PRIORITY_OFFICIAL;
+ } else if (strcmp(token,SLAPT_PRIORITY_CUSTOM_TOKEN) == 0) {
+ s->priority = SLAPT_PRIORITY_CUSTOM;
+ } else {
+ fprintf(stderr,"Unknown token: %s\n", token);
+ }
+ }
+
+ }
+
+}
+
+slapt_source_t *slapt_init_source(const char *s)
+{
+ slapt_source_t *src;
+ unsigned int source_len = 0;
+ unsigned int attribute_len = 0;
+ slapt_regex_t *attribute_regex = NULL;
+ char *source_string = NULL;
+ char *attribute_string = NULL;
+
+ if (s == NULL)
+ return NULL;
+
+ src = slapt_malloc(sizeof *src);
+ src->priority = SLAPT_PRIORITY_DEFAULT;
+ src->disabled = SLAPT_FALSE;
+ source_len = strlen(s);
+
+ /* parse for :[attr] in the source url */
+ if ((attribute_regex = slapt_init_regex(SLAPT_SOURCE_ATTRIBUTE_REGEX)) == NULL) {
+ exit(EXIT_FAILURE);
+ }
+ slapt_execute_regex(attribute_regex,s);
+ if (attribute_regex->reg_return == 0) {
+ /* if we find an attribute string, extract it */
+ attribute_string = slapt_regex_extract_match(attribute_regex, s, 1);
+ attribute_len = strlen(attribute_string);
+ source_string = strndup(s, source_len - attribute_len);
+ } else {
+ /* otherwise we just dup the const string */
+ source_string = strndup(s, source_len);
+ }
+ slapt_free_regex(attribute_regex);
+
+
+ /* now add a trailing / if not already there */
+ source_len = strlen(source_string);
+ if ( source_string[source_len - 1] == '/' ) {
+
+ src->url = strdup(source_string);
+
+ } else {
+
+ src->url = slapt_malloc(sizeof *src->url * (source_len + 2));
+ src->url[0] = '\0';
+
+ src->url = strncat(
+ src->url,
+ source_string,
+ source_len
+ );
+
+ if (isblank(src->url[source_len - 1]) == 0) {
+ src->url = strncat(src->url, "/", 1);
+ } else {
+ if (src->url[source_len - 2] == '/') {
+ src->url[source_len - 2] = '/';
+ src->url[source_len - 1] = '\0';
+ } else {
+ src->url[source_len - 1] = '/';
+ }
+ }
+
+ src->url[source_len + 1] = '\0';
+
+ }
+
+ free(source_string);
+
+ /* now parse the attribute string */
+ if (attribute_string != NULL) {
+ slapt_source_parse_attributes(src, attribute_string + 1);
+ free(attribute_string);
+ }
+
+ return src;
+}
+
+void slapt_free_source(slapt_source_t *src)
+{
+ free(src->url);
+ free(src);
+}
+
+int slapt_write_rc_config(const slapt_rc_config *global_config, const char *location)
+{
+ unsigned int i;
+ FILE *rc;
+
+ rc = slapt_open_file(location,"w+");
+ if (rc == NULL)
+ return -1;
+
+ fprintf(rc,"%s%s\n",SLAPT_WORKINGDIR_TOKEN,global_config->working_dir);
+
+ fprintf(rc,"%s",SLAPT_EXCLUDE_TOKEN);
+ for (i = 0;i < global_config->exclude_list->count;++i) {
+ if ( i+1 == global_config->exclude_list->count) {
+ fprintf(rc,"%s",global_config->exclude_list->excludes[i]);
+ }else{
+ fprintf(rc,"%s,",global_config->exclude_list->excludes[i]);
+ }
+ }
+ fprintf(rc,"\n");
+
+ for (i = 0; i < global_config->sources->count;++i) {
+ slapt_source_t *src = global_config->sources->src[i];
+
+ if (global_config->sources->src[i]->disabled == SLAPT_TRUE)
+ fprintf(rc,"%s%s\n",SLAPT_DISABLED_SOURCE_TOKEN, src->url);
+ else
+ fprintf(rc,"%s%s\n",SLAPT_SOURCE_TOKEN, src->url);
+ }
+
+ fclose(rc);
+
+ return 0;
+}
+
diff --git a/src/configuration.h b/src/configuration.h
index 388e6f0..7dbeb39 100644
--- a/src/configuration.h
+++ b/src/configuration.h
@@ -1,21 +1,29 @@
-#define SOURCE_TOKEN "SOURCE="
-#define WORKINGDIR_TOKEN "WORKINGDIR="
-#define WORKINGDIR_TOKEN_LEN 256
-#define EXCLUDE_TOKEN "EXCLUDE="
+#define SLAPT_SOURCE_TOKEN "SOURCE="
+#define SLAPT_DISABLED_SOURCE_TOKEN "#DISABLED="
+#define SLAPT_WORKINGDIR_TOKEN "WORKINGDIR="
+#define SLAPT_WORKINGDIR_TOKEN_LEN 256
+#define SLAPT_EXCLUDE_TOKEN "EXCLUDE="
+#define SLAPT_SOURCE_ATTRIBUTE_REGEX "(:[A-Z_,]+)$"
struct slapt_exclude_list {
char **excludes;
unsigned int count;
};
+typedef struct {
+ char *url;
+ SLAPT_PRIORITY_T priority;
+ SLAPT_BOOL_T disabled;
+} slapt_source_t;
+
struct slapt_source_list {
- char **url;
+ slapt_source_t **src;
unsigned int count;
};
typedef struct {
- char working_dir[WORKINGDIR_TOKEN_LEN];
+ char working_dir[SLAPT_WORKINGDIR_TOKEN_LEN];
struct slapt_source_list *sources;
struct slapt_exclude_list *exclude_list;
int(*progress_cb)(void *,double,double,double,double);
@@ -55,13 +63,19 @@ void slapt_add_exclude(struct slapt_exclude_list *list,const char *e);
void slapt_remove_exclude(struct slapt_exclude_list *list,const char *e);
void slapt_free_exclude_list(struct slapt_exclude_list *list);
+/* create, destroy the source struct */
+slapt_source_t *slapt_init_source(const char *s);
+void slapt_free_source(slapt_source_t *src);
+
/*
add or remove a package source url to the source list.
commonly called with global_config->source_list
*/
struct slapt_source_list *slapt_init_source_list(void);
-void slapt_add_source(struct slapt_source_list *list,const char *s);
+void slapt_add_source(struct slapt_source_list *list, slapt_source_t *s);
void slapt_remove_source (struct slapt_source_list *list, const char *s);
void slapt_free_source_list(struct slapt_source_list *list);
SLAPT_BOOL_T slapt_is_interactive(const slapt_rc_config *);
+
+int slapt_write_rc_config(const slapt_rc_config *global_config, const char *location);
diff --git a/src/package.c b/src/package.c
index 0dd10ac..a623a60 100644
--- a/src/package.c
+++ b/src/package.c
@@ -66,6 +66,7 @@ struct slapt_pkg_list *slapt_parse_packages_txt(FILE *pkg_list_fh)
{
slapt_regex_t *name_regex = NULL,
*mirror_regex = NULL,
+ *priority_regex = NULL,
*location_regex = NULL,
*size_c_regex = NULL,
*size_u_regex = NULL;
@@ -85,6 +86,9 @@ struct slapt_pkg_list *slapt_parse_packages_txt(FILE *pkg_list_fh)
if ((mirror_regex = slapt_init_regex(SLAPT_PKG_MIRROR_PATTERN)) == NULL) {
exit(EXIT_FAILURE);
}
+ if ((priority_regex = slapt_init_regex(SLAPT_PKG_PRIORITY_PATTERN)) == NULL) {
+ exit(EXIT_FAILURE);
+ }
if ((location_regex = slapt_init_regex(SLAPT_PKG_LOCATION_PATTERN)) == NULL) {
exit(EXIT_FAILURE);
}
@@ -138,6 +142,20 @@ struct slapt_pkg_list *slapt_parse_packages_txt(FILE *pkg_list_fh)
}
}
+ /* priority */
+ f_pos = ftell(pkg_list_fh);
+ if (getline(&getline_buffer, &getline_len, pkg_list_fh) != EOF) {
+
+ slapt_execute_regex(priority_regex, getline_buffer);
+
+ if (priority_regex->reg_return == 0) {
+ tmp_pkg->priority = atoi(slapt_regex_extract_match(priority_regex, getline_buffer, 1));
+ } else {
+ /* priority isn't provided... rewind one line */
+ fseek(pkg_list_fh, (ftell(pkg_list_fh) - f_pos) * -1, SEEK_CUR);
+ }
+ }
+
/* location */
if ((getline(&getline_buffer,&getline_len,pkg_list_fh) != EOF)) {
@@ -655,6 +673,9 @@ struct slapt_pkg_list *slapt_get_installed_pkgs(void)
tmp_pkg->mirror[0] = '\0';
}
+ /* mark as installed */
+ tmp_pkg->installed = SLAPT_TRUE;
+
slapt_add_pkg_to_pkg_list(list,tmp_pkg);
tmp_pkg = NULL;
@@ -1011,6 +1032,25 @@ static void slapt_free_pkg_version_parts(struct slapt_pkg_version_parts *parts)
free(parts);
}
+int slapt_cmp_pkgs(slapt_pkg_info_t *a, slapt_pkg_info_t *b)
+{
+ int greater = 1,lesser = -1,equal = 0;
+
+ /* if either of the two packages is installed, we look
+ for the same version to bail out early if possible */
+ if (a->installed == SLAPT_TRUE || b->installed == SLAPT_TRUE)
+ if (strcasecmp(a->version,b->version) == 0)
+ return equal;
+
+ /* check the priorities */
+ if(a->priority > b->priority)
+ return greater;
+ else if(a->priority < b->priority)
+ return lesser;
+
+ return slapt_cmp_pkg_versions(a->version, b->version);
+}
+
int slapt_cmp_pkg_versions(const char *a, const char *b)
{
unsigned int position = 0;
@@ -1115,7 +1155,7 @@ int slapt_cmp_pkg_versions(const char *a, const char *b)
/*
* If both have the same # of version parts, non-standard version convention,
- * then we fall back on strcmp.
+ * then we fall back on strverscmp.
*/
if (strchr(a,'-') == NULL && strchr(b,'-') == NULL)
return strverscmp(a,b);
@@ -1210,6 +1250,7 @@ void slapt_write_pkg_data(const char *source_url,FILE *d_file,
} else {
fprintf(d_file,"PACKAGE MIRROR: %s\n",source_url);
}
+ fprintf(d_file,"PACKAGE PRIORITY: %d\n", pkgs->pkgs[i]->priority);
fprintf(d_file,"PACKAGE LOCATION: %s\n",pkgs->pkgs[i]->location);
fprintf(d_file,"PACKAGE SIZE (compressed): %d K\n",pkgs->pkgs[i]->size_c);
fprintf(d_file,"PACKAGE SIZE (uncompressed): %d K\n",pkgs->pkgs[i]->size_u);
@@ -1887,46 +1928,39 @@ int slapt_update_pkg_cache(const slapt_rc_config *global_config)
FILE *tmp_signature_f = NULL;
FILE *tmp_checksum_to_verify_f = NULL;
#endif
+ const char *source_url = global_config->sources->src[i]->url;
+ SLAPT_PRIORITY_T source_priority = global_config->sources->src[i]->priority;
+
+ if (global_config->sources->src[i]->disabled == SLAPT_TRUE)
+ continue;
/* download our SLAPT_PKG_LIST */
- printf(gettext("Retrieving package data [%s]..."),
- global_config->sources->url[i]);
- available_pkgs =
- slapt_get_pkg_source_packages(global_config,
- global_config->sources->url[i],
- &compressed);
+ printf(gettext("Retrieving package data [%s]..."), source_url);
+
+ available_pkgs = slapt_get_pkg_source_packages(global_config, source_url, &compressed);
if (available_pkgs == NULL) {
source_dl_failed = 1;
continue;
}
/* download SLAPT_PATCHES_LIST */
- printf(gettext("Retrieving patch list [%s]..."),
- global_config->sources->url[i]);
- patch_pkgs =
- slapt_get_pkg_source_patches(global_config,
- global_config->sources->url[i],
- &compressed);
+ printf(gettext("Retrieving patch list [%s]..."), source_url);
+
+ patch_pkgs = slapt_get_pkg_source_patches(global_config, source_url, &compressed);
/* download checksum file */
- printf(gettext("Retrieving checksum list [%s]..."),
- global_config->sources->url[i]);
- tmp_checksum_f =
- slapt_get_pkg_source_checksums(global_config,
- global_config->sources->url[i],
- &compressed);
+ printf(gettext("Retrieving checksum list [%s]..."), source_url);
+ tmp_checksum_f = slapt_get_pkg_source_checksums(global_config, source_url, &compressed);
#ifdef SLAPT_HAS_GPGME
- printf(gettext("Retrieving checksum signature [%s]..."), global_config->sources->url[i]);
- tmp_signature_f = slapt_get_pkg_source_checksums_signature (global_config,
- global_config->sources->url[i],
- &compressed);
+ printf(gettext("Retrieving checksum signature [%s]..."), source_url);
+ tmp_signature_f = slapt_get_pkg_source_checksums_signature (global_config,source_url, &compressed);
+
/* if we downloaded the compressed checksums, open it raw (w/o gunzipping) */
if (compressed == 1)
{
- char *filename = slapt_gen_filename_from_url(global_config->sources->url[i],
- SLAPT_CHECKSUM_FILE_GZ);
+ char *filename = slapt_gen_filename_from_url(source_url, SLAPT_CHECKSUM_FILE_GZ);
tmp_checksum_to_verify_f = slapt_open_file(filename,"r");
free(filename);
} else {
@@ -1935,7 +1969,7 @@ int slapt_update_pkg_cache(const slapt_rc_config *global_config)
if (tmp_signature_f != NULL && tmp_checksum_to_verify_f != NULL) {
slapt_code_t verified = SLAPT_CHECKSUMS_NOT_VERIFIED;
- printf(gettext("Verifying checksum signature [%s]..."), global_config->sources->url[i]);
+ printf(gettext("Verifying checksum signature [%s]..."), source_url);
verified = slapt_gpg_verify_checksums(tmp_checksum_to_verify_f, tmp_signature_f);
if (verified == SLAPT_CHECKSUMS_VERIFIED) {
printf("%s\n",gettext("Verified"));
@@ -1962,11 +1996,8 @@ int slapt_update_pkg_cache(const slapt_rc_config *global_config)
#endif
if (source_dl_failed != 1) {
- printf(gettext("Retrieving ChangeLog.txt [%s]..."),
- global_config->sources->url[i]);
- slapt_get_pkg_source_changelog(global_config,
- global_config->sources->url[i],
- &compressed);
+ printf(gettext("Retrieving ChangeLog.txt [%s]..."), source_url);
+ slapt_get_pkg_source_changelog(global_config, source_url, &compressed);
}
if (tmp_checksum_f != NULL) {
@@ -1987,9 +2018,12 @@ int slapt_update_pkg_cache(const slapt_rc_config *global_config)
if (mirror_len == 0)
free(p->mirror);
- p->mirror = strdup(global_config->sources->url[i]);
+ p->mirror = strdup(source_url);
}
+ /* set the priority of the package based on the source */
+ p->priority = source_priority;
+
slapt_add_pkg_to_pkg_list(new_pkgs,p);
}
available_pkgs->free_pkgs = SLAPT_FALSE;
@@ -2006,9 +2040,12 @@ int slapt_update_pkg_cache(const slapt_rc_config *global_config)
if (mirror_len == 0)
free(p->mirror);
- p->mirror = strdup(global_config->sources->url[i]);
+ p->mirror = strdup(source_url);
}
+ /* set the priority of the package based on the source, plus 1 for the patch priority */
+ p->priority = source_priority + 1;
+
slapt_add_pkg_to_pkg_list(new_pkgs,p);
}
patch_pkgs->free_pkgs = SLAPT_FALSE;
@@ -2112,9 +2149,12 @@ __inline slapt_pkg_info_t *slapt_init_pkg(void)
pkg->suggests = slapt_malloc(sizeof *pkg->suggests);
pkg->suggests[0] = '\0';
-
pkg->md5[0] = '\0';
+ pkg->priority = SLAPT_PRIORITY_DEFAULT;
+
+ pkg->installed = SLAPT_FALSE;
+
return pkg;
}
diff --git a/src/package.h b/src/package.h
index 835b377..7bf2d9d 100644
--- a/src/package.h
+++ b/src/package.h
@@ -4,6 +4,7 @@
#define SLAPT_PKG_VER "(.*)[\\-](.*)[\\-](.*)"
#define SLAPT_PKG_NAME_PATTERN "^PACKAGE NAME:[ ]{1,}(.*{1,})\\-(.*[\\-].*[\\-].*)(\\.[tgblzik]+)[ ]{0,}$"
#define SLAPT_PKG_MIRROR_PATTERN "^PACKAGE MIRROR:[ ]+(.*)$"
+#define SLAPT_PKG_PRIORITY_PATTERN "^PACKAGE PRIORITY:[ ]+([0-9]{1,})$"
#define SLAPT_PKG_LOCATION_PATTERN "^PACKAGE LOCATION:[ ]+(.*)$"
#define SLAPT_PKG_SIZEC_PATTERN "^PACKAGE SIZE [(]+compressed[)]{1,}:[ ]{1,}([0-9]{1,}) K$"
#define SLAPT_PKG_SIZEU_PATTERN "^PACKAGE SIZE [(]+uncompressed[)]{1,}:[ ]{1,}([0-9]{1,}) K$"
@@ -46,6 +47,8 @@ typedef struct {
char *file_ext;
unsigned int size_c;
unsigned int size_u;
+ unsigned int priority;
+ SLAPT_BOOL_T installed;
} slapt_pkg_info_t;
struct slapt_pkg_list {
@@ -206,7 +209,7 @@ size_t slapt_get_pkg_file_size(const slapt_rc_config *global_config,
0 if a and b are equal
*/
int slapt_cmp_pkg_versions(const char *a, const char *b);
-#define slapt_cmp_pkgs(x,y) slapt_cmp_pkg_versions(x->version,y->version)
+int slapt_cmp_pkgs(slapt_pkg_info_t *a, slapt_pkg_info_t *b);
/*
resolve dependencies