From f7192b595881103f145a118d63d1b342ffd740b4 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Mon, 17 Nov 2008 21:47:55 -0600 Subject: Minor code cleanups Mostly noticed when compiling libalpm/pacman with ICC. Signed-off-by: Dan McGee --- lib/libalpm/be_files.c | 6 +++--- lib/libalpm/dload.c | 10 ++++------ src/pacman/sync.c | 3 ++- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/libalpm/be_files.c b/lib/libalpm/be_files.c index f5d4e826..0658a661 100644 --- a/lib/libalpm/be_files.c +++ b/lib/libalpm/be_files.c @@ -51,7 +51,7 @@ * Return the last update time as number of seconds from the epoch. * Returns 0 if the value is unknown or can't be read. */ -time_t getlastupdate(const pmdb_t *db) +static time_t getlastupdate(const pmdb_t *db) { FILE *fp; char *file; @@ -85,7 +85,7 @@ time_t getlastupdate(const pmdb_t *db) /* * writes the dbpath/.lastupdate file with the value in time */ -int setlastupdate(const pmdb_t *db, time_t time) +static int setlastupdate(const pmdb_t *db, time_t time) { FILE *fp; char *file; @@ -500,7 +500,7 @@ int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq) if(fgets(line, 512, fp) == NULL) { goto error; } - info->reason = atol(_alpm_strtrim(line)); + info->reason = (pmpkgreason_t)atol(_alpm_strtrim(line)); } else if(strcmp(line, "%SIZE%") == 0 || strcmp(line, "%CSIZE%") == 0) { /* NOTE: the CSIZE and SIZE fields both share the "size" field * in the pkginfo_t struct. This can be done b/c CSIZE diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c index c07040b5..9b082943 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -111,11 +111,11 @@ static int download_internal(const char *url, const char *localpath, FILE *dlf, *localf = NULL; struct url_stat ust; struct stat st; - int chk_resume = 0; - size_t dl_thisfile = 0; + int chk_resume = 0, ret = 0; + size_t dl_thisfile = 0, nread = 0; char *tempfile, *destfile, *filename; - int ret = 0; struct url *fileurl = url_for_string(url); + char buffer[PM_DLBUF_LEN]; if(!fileurl) { return(-1); @@ -200,9 +200,8 @@ static int download_internal(const char *url, const char *localpath, handle->dlcb(filename, 0, ust.size); } - size_t nread = 0; - char buffer[PM_DLBUF_LEN]; while((nread = fread(buffer, 1, PM_DLBUF_LEN, dlf)) > 0) { + size_t nwritten = 0; if(ferror(dlf)) { pm_errno = PM_ERR_LIBDOWNLOAD; _alpm_log(PM_LOG_ERROR, _("error downloading '%s': %s\n"), @@ -211,7 +210,6 @@ static int download_internal(const char *url, const char *localpath, goto cleanup; } - size_t nwritten = 0; while(nwritten < nread) { nwritten += fwrite(buffer, 1, (nread - nwritten), localf); if(ferror(localf)) { diff --git a/src/pacman/sync.c b/src/pacman/sync.c index 8d0c529a..00e477af 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -551,6 +551,7 @@ static int sync_trans(alpm_list_t *targets) int retval = 0; alpm_list_t *data = NULL; alpm_list_t *sync_dbs = alpm_option_get_syncdbs(); + alpm_list_t *packages = NULL; /* Step 1: create a new transaction... */ if(trans_init(PM_TRANS_TYPE_SYNC, config->flags) == -1) { @@ -659,7 +660,7 @@ static int sync_trans(alpm_list_t *targets) goto cleanup; } - alpm_list_t *packages = alpm_trans_get_pkgs(); + packages = alpm_trans_get_pkgs(); if(packages == NULL) { /* nothing to do: just exit without complaining */ printf(_(" local database is up to date\n")); -- cgit v1.2.3 From 346139298bc547d1cbeb5d41f2067577b96ff1fa Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sun, 30 Nov 2008 16:07:06 -0600 Subject: Simplify mercurial revision command Not only does this require less sed-magic, it also fixes FS#12286 where fetching the revision number fails if mercurial is in compact mode. Signed-off-by: Dan McGee --- scripts/makepkg.sh.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 599f0f9c..4cc255cc 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -1062,7 +1062,7 @@ devel_check() { hg clone $_hgroot/$_hgrepo ./src/$_hgrepo cd ./src/$_hgrepo fi - newpkgver=$(hg tip | sed -n '1s/[^0-9]*\([^:]*\):.*$/\1/p') + newpkgver=$(hg tip --template "{rev}") cd ../../ fi -- cgit v1.2.3 From a50b067470a8046dabdff66f6266d2208b2f8372 Mon Sep 17 00:00:00 2001 From: Nagy Gabor Date: Mon, 17 Nov 2008 17:02:43 +0100 Subject: Give an error message on alpm_db_register_sync() error This patch slightly modifies pacman.c/_parseconfig(): See FS#12148. Now pacman prints the following error message in that case: "error: could not register 'unstable' database (could not open database)" I also added an error message for alpm_db_setserver() error. I changed the "return(1);" scheme to "ret = 1; goto cleanup;" to make sure that we free allocated memory and close open files. Signed-off-by: Nagy Gabor Signed-off-by: Dan McGee --- src/pacman/pacman.c | 46 ++++++++++++++++++++++++++++++++++------------ 1 file changed, 34 insertions(+), 12 deletions(-) diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 0e133df6..c7db3b48 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -577,6 +577,7 @@ static int _parseconfig(const char *file, const char *givensection, int linenum = 0; char *ptr, *section = NULL; pmdb_t *db = NULL; + int ret = 0; pm_printf(PM_LOG_DEBUG, "config: attempting to read file %s\n", file); fp = fopen(file, "r"); @@ -619,7 +620,8 @@ static int _parseconfig(const char *file, const char *givensection, if(!strlen(section)) { pm_printf(PM_LOG_ERROR, _("config file %s, line %d: bad section name.\n"), file, linenum); - return(1); + ret = 1; + goto cleanup; } /* if we are not looking at the options section, register a db and also * ensure we have set all of our library paths as the library is too stupid @@ -627,6 +629,12 @@ static int _parseconfig(const char *file, const char *givensection, if(strcmp(section, "options") != 0) { setlibpaths(); db = alpm_db_register_sync(section); + if(db == NULL) { + pm_printf(PM_LOG_ERROR, _("could not register '%s' database (%s)\n"), + section, alpm_strerrorlast()); + ret = 1; + goto cleanup; + } } } else { /* directive */ @@ -641,13 +649,15 @@ static int _parseconfig(const char *file, const char *givensection, if(key == NULL) { pm_printf(PM_LOG_ERROR, _("config file %s, line %d: syntax error in config file- missing key.\n"), file, linenum); - return(1); + ret = 1; + goto cleanup; } /* For each directive, compare to the camelcase string. */ if(section == NULL) { pm_printf(PM_LOG_ERROR, _("config file %s, line %d: All directives must belong to a section.\n"), file, linenum); - return(1); + ret = 1; + goto cleanup; } if(ptr == NULL && strcmp(section, "options") == 0) { /* directives without settings, all in [options] */ @@ -672,7 +682,8 @@ static int _parseconfig(const char *file, const char *givensection, } else { pm_printf(PM_LOG_ERROR, _("config file %s, line %d: directive '%s' not recognized.\n"), file, linenum, key); - return(1); + ret = 1; + goto cleanup; } } else { /* directives with settings */ @@ -703,7 +714,8 @@ static int _parseconfig(const char *file, const char *givensection, if(alpm_option_add_cachedir(ptr) != 0) { pm_printf(PM_LOG_ERROR, _("problem adding cachedir '%s' (%s)\n"), ptr, alpm_strerrorlast()); - return(1); + ret = 1; + goto cleanup; } pm_printf(PM_LOG_DEBUG, "config: cachedir: %s\n", ptr); } else if(strcmp(key, "RootDir") == 0) { @@ -727,13 +739,15 @@ static int _parseconfig(const char *file, const char *givensection, config->cleanmethod = PM_CLEAN_KEEPCUR; } else { pm_printf(PM_LOG_ERROR, _("invalid value for 'CleanMethod' : '%s'\n"), ptr); - return(1); + ret = 1; + goto cleanup; } pm_printf(PM_LOG_DEBUG, "config: cleanmethod: %s\n", ptr); } else { pm_printf(PM_LOG_ERROR, _("config file %s, line %d: directive '%s' not recognized.\n"), file, linenum, key); - return(1); + ret = 1; + goto cleanup; } } else if(strcmp(key, "Server") == 0) { /* let's attempt a replacement for the current repo */ @@ -741,27 +755,35 @@ static int _parseconfig(const char *file, const char *givensection, if(alpm_db_setserver(db, server) != 0) { /* pm_errno is set by alpm_db_setserver */ - return(1); + pm_printf(PM_LOG_ERROR, _("could not add server URL to database '%s': %s (%s)\n"), + alpm_db_get_name(db), server, alpm_strerrorlast()); + free(server); + ret = 1; + goto cleanup; } free(server); } else { pm_printf(PM_LOG_ERROR, _("config file %s, line %d: directive '%s' not recognized.\n"), file, linenum, key); - return(1); + ret = 1; + goto cleanup; } } } } - fclose(fp); + +cleanup: + if(fp) { + fclose(fp); + } if(section){ free(section); } - /* call setlibpaths here to ensure we have called it at least once */ setlibpaths(); pm_printf(PM_LOG_DEBUG, "config: finished parsing %s\n", file); - return(0); + return(ret); } /** Parse a configuration file. -- cgit v1.2.3 From b99bebc008dcf944a88f99bb44ac9029557e4149 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sun, 30 Nov 2008 17:17:00 -0600 Subject: Add regex to delta code so we don't segfault when reading line If the delta line doesn't match our regex, we won't go and process it, possibly walking off the end of the string. Signed-off-by: Dan McGee --- lib/libalpm/be_files.c | 5 ++++- lib/libalpm/delta.c | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/libalpm/be_files.c b/lib/libalpm/be_files.c index 0658a661..b9ff6464 100644 --- a/lib/libalpm/be_files.c +++ b/lib/libalpm/be_files.c @@ -618,7 +618,10 @@ int _alpm_db_read(pmdb_t *db, pmpkg_t *info, pmdbinfrq_t inforeq) _alpm_strtrim(line); if(strcmp(line, "%DELTAS%") == 0) { while(fgets(line, 512, fp) && strlen(_alpm_strtrim(line))) { - info->deltas = alpm_list_add(info->deltas, _alpm_delta_parse(line)); + pmdelta_t *delta = _alpm_delta_parse(line); + if(delta) { + info->deltas = alpm_list_add(info->deltas, delta); + } } } } diff --git a/lib/libalpm/delta.c b/lib/libalpm/delta.c index 22d9beb4..8dce7e3b 100644 --- a/lib/libalpm/delta.c +++ b/lib/libalpm/delta.c @@ -22,6 +22,8 @@ #include #include #include +#include +#include /* libalpm */ #include "delta.h" @@ -257,6 +259,19 @@ pmdelta_t *_alpm_delta_parse(char *line) { pmdelta_t *delta; char *tmp = line, *tmp2; + regex_t reg; + + regcomp(®, + "^[^[:space:]]* [[:xdigit:]]{32}" + " [^[:space:]]* [[:xdigit:]]{32}" + " [^[:space:]]* [[:xdigit:]]{32} [[:digit:]]*$", + REG_EXTENDED | REG_NOSUB | REG_NEWLINE); + if(regexec(®, line, 0, 0, 0) != 0) { + /* delta line is invalid, return NULL */ + regfree(®); + return(NULL); + } + regfree(®); CALLOC(delta, 1, sizeof(pmdelta_t), RET_ERR(PM_ERR_MEMORY, NULL)); -- cgit v1.2.3 From 6d8a6aef094c162f46a8b9be6a118a502fabca61 Mon Sep 17 00:00:00 2001 From: Simo Leone Date: Mon, 24 Nov 2008 23:31:10 -0600 Subject: Add flush after downloading message When the output is going to a file, glibc seems to buffer way too much making it hard to monitor progress while tailing a file. Signed-off-by: Simo Leone Signed-off-by: Dan McGee --- src/pacman/callback.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pacman/callback.c b/src/pacman/callback.c index 82dabae3..6f41df7c 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -446,6 +446,7 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total) if(config->noprogressbar || file_total == -1) { if(file_xfered == 0) { printf(_("downloading %s...\n"), filename); + fflush(stdout); } return; } -- cgit v1.2.3 From a1f7c83dbf3bce492163362d2896e3a4176be616 Mon Sep 17 00:00:00 2001 From: Allan McRae Date: Tue, 2 Dec 2008 14:17:59 +1000 Subject: Add optdepends to PKGBUILD.proto Signed-off-by: Allan McRae Signed-off-by: Dan McGee --- PKGBUILD.proto | 1 + 1 file changed, 1 insertion(+) diff --git a/PKGBUILD.proto b/PKGBUILD.proto index 32655306..eddcf759 100644 --- a/PKGBUILD.proto +++ b/PKGBUILD.proto @@ -14,6 +14,7 @@ license=('GPL') groups=() depends=() makedepends=() +optdepends=() provides=() conflicts=() replaces=() -- cgit v1.2.3