From 541c2470b8ad8c1c0c925d2474da44384b5d7d66 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Tue, 29 Mar 2011 20:35:48 -0400 Subject: makepkg: avoid usage of tr to sidestep locale issues to quote dan: "turkish will FUCK YOU UP. this is not the first or the last time" Signed-off-by: Dave Reisner Signed-off-by: Allan McRae Signed-off-by: Dan McGee --- scripts/makepkg.sh.in | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index eb7c3701..dcc32343 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -1039,13 +1039,12 @@ create_package() { local comp_files=".PKGINFO" # check for changelog/install files - for i in 'changelog' 'install'; do - orig=${!i} - dest=$(tr '[:lower:]' '[:upper:]' <<<".$i") + for i in 'changelog/.CHANGELOG' 'install/.INSTALL'; do + IFS='/' read -r orig dest <<< "$i" - if [[ -n $orig ]]; then - msg2 "$(gettext "Adding %s file...")" "$i" - cp "$startdir/$orig" "$dest" + if [[ -n ${!orig} ]]; then + msg2 "$(gettext "Adding %s file...")" "$orig" + cp "$startdir/${!orig}" "$dest" chmod 644 "$dest" comp_files+=" $dest" fi -- cgit v1.2.3-55-g3dc8 From a164c8405a0fb08cc7783d51796fbb76d0e4f493 Mon Sep 17 00:00:00 2001 From: Allan McRae Date: Thu, 31 Mar 2011 11:12:58 +1000 Subject: makepkg: remove unnecessary tr usage The use of "tr" only leads to trouble. Remove unnecessary usage of it from within makepkg. Signed-off-by: Allan McRae Signed-off-by: Dan McGee --- scripts/makepkg.sh.in | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index dcc32343..193a1853 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -286,11 +286,10 @@ check_buildenv() { # ? - not found ## in_opt_array() { - local needle=$(tr '[:upper:]' '[:lower:]' <<< $1); shift + local needle=$1; shift local opt for opt in "$@"; do - opt=$(tr '[:upper:]' '[:lower:]' <<< $opt) if [[ $opt = $needle ]]; then echo 'y' # Enabled return @@ -578,7 +577,6 @@ generate_checksums() { local integ for integ in ${integlist[@]}; do - integ=$(tr '[:upper:]' '[:lower:]' <<< "$integ") case "$integ" in md5|sha1|sha256|sha384|sha512) : ;; *) -- cgit v1.2.3-55-g3dc8 From 20c4928ee155db7b43b9f5b440a2cb199f178bb4 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Fri, 1 Apr 2011 12:30:57 -0500 Subject: Ignore upcoming new values in sync backend PGPSIG and SHA256SUM are new and we can safely ignore them for now if we come across them. Signed-off-by: Dan McGee --- lib/libalpm/be_sync.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c index 98516fd8..5a13adda 100644 --- a/lib/libalpm/be_sync.c +++ b/lib/libalpm/be_sync.c @@ -418,6 +418,12 @@ static int sync_db_read(pmdb_t *db, struct archive *archive, pkg->isize = atol(line); } else if(strcmp(line, "%MD5SUM%") == 0) { READ_AND_STORE(pkg->md5sum); + } else if(strcmp(line, "%SHA256SUM%") == 0) { + /* we don't do anything with this value right now */ + READ_NEXT(line); + } else if(strcmp(line, "%PGPSIG%") == 0) { + /* we don't do anything with this value right now */ + READ_NEXT(line); } else if(strcmp(line, "%REPLACES%") == 0) { READ_AND_STORE_ALL(pkg->replaces); } else if(strcmp(line, "%DEPENDS%") == 0) { -- cgit v1.2.3-55-g3dc8 From 39fd8bc318d4a90aab704f892cd80c22f5c7345f Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Fri, 1 Apr 2011 14:31:50 -0500 Subject: Ensure dbpath is not null when populating sync database We didn't do this sanity check before trying to open an archive. If the alpm dbpath wasn't set, the sync database dbpath would be NULL, causing us to hang indefinitely in archive_read_open_filename() rather than erroring out. We already have a corresponding check in local_db_populate(). The following program will test this case, and hangs before this patch without the call to set_dbpath: int main(int argc, char *argv[]) { alpm_initialize(); // alpm_option_set_dbpath("/var/lib/pacman/"); pmdb_t *core = alpm_db_register_sync("core"); pmpkg_t *pkg = alpm_db_get_pkg(core, "pacman"); return 0; } Signed-off-by: Dan McGee --- lib/libalpm/be_sync.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c index 5a13adda..ef8517e3 100644 --- a/lib/libalpm/be_sync.c +++ b/lib/libalpm/be_sync.c @@ -209,6 +209,7 @@ static size_t estimate_package_count(struct stat *st, struct archive *archive) static int sync_db_populate(pmdb_t *db) { + const char *dbpath; size_t est_count; int count = 0; struct stat buf; @@ -226,14 +227,22 @@ static int sync_db_populate(pmdb_t *db) archive_read_support_compression_all(archive); archive_read_support_format_all(archive); - if(archive_read_open_filename(archive, _alpm_db_path(db), + dbpath = _alpm_db_path(db); + if(!dbpath) { + /* pm_errno set in _alpm_db_path() */ + return 1; + } + + _alpm_log(PM_LOG_DEBUG, "opening database archive %s\n", dbpath); + + if(archive_read_open_filename(archive, dbpath, ARCHIVE_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK) { - _alpm_log(PM_LOG_ERROR, _("could not open file %s: %s\n"), _alpm_db_path(db), + _alpm_log(PM_LOG_ERROR, _("could not open file %s: %s\n"), dbpath, archive_error_string(archive)); archive_read_finish(archive); RET_ERR(PM_ERR_DB_OPEN, 1); } - if(stat(_alpm_db_path(db), &buf) != 0) { + if(stat(dbpath, &buf) != 0) { RET_ERR(PM_ERR_DB_OPEN, 1); } est_count = estimate_package_count(&buf, archive); -- cgit v1.2.3-55-g3dc8 From 7f6d986ac93e3465db6a4ed5c3ac77b72d890e68 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Fri, 1 Apr 2011 15:13:37 -0500 Subject: Add default changelog functions to pkg_operations So we don't segfault when calling this on be_sync loaded packages. They return logical values as much as possible for indicating there is no changelog available. Signed-off-by: Dan McGee --- lib/libalpm/package.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c index adb1ce9e..589badff 100644 --- a/lib/libalpm/package.c +++ b/lib/libalpm/package.c @@ -123,6 +123,10 @@ static alpm_list_t *_pkg_get_deltas(pmpkg_t *pkg) { return pkg->deltas; } static alpm_list_t *_pkg_get_files(pmpkg_t *pkg) { return pkg->files; } static alpm_list_t *_pkg_get_backup(pmpkg_t *pkg) { return pkg->backup; } +static void *_pkg_changelog_open(pmpkg_t *pkg) { return NULL; } +static size_t _pkg_changelog_read(void *ptr, size_t size, const pmpkg_t *pkg, const void *fp) { return 0; } +static int _pkg_changelog_close(const pmpkg_t *pkg, void *fp) { return EOF; } + /** The standard package operations struct. Get fields directly from the * struct itself with no abstraction layer or any type of lazy loading. */ @@ -141,6 +145,7 @@ struct pkg_operations default_pkg_ops = { .get_isize = _pkg_get_isize, .get_reason = _pkg_get_reason, .has_scriptlet = _pkg_has_scriptlet, + .get_licenses = _pkg_get_licenses, .get_groups = _pkg_get_groups, .get_depends = _pkg_get_depends, @@ -151,6 +156,10 @@ struct pkg_operations default_pkg_ops = { .get_deltas = _pkg_get_deltas, .get_files = _pkg_get_files, .get_backup = _pkg_get_backup, + + .changelog_open = _pkg_changelog_open, + .changelog_read = _pkg_changelog_read, + .changelog_close = _pkg_changelog_close, }; /* Public functions for getting package information. These functions -- cgit v1.2.3-55-g3dc8 From d8d89d8d27794d493ed2aa9eba4649e6e3ff4a9d Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Fri, 1 Apr 2011 15:16:26 -0500 Subject: Ensure stdout/stderr are flushed when asking questions Addresses FS#23492, where the question was shown without knowing what one was answering to. Ensure we flush our output streams before printing the question, and flush the stream on which we ask the question before waiting for an answer. Signed-off-by: Dan McGee --- src/pacman/util.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/pacman/util.c b/src/pacman/util.c index 83368085..c7d98540 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -878,6 +878,10 @@ static int question(short preset, char *fmt, va_list args) stream = stderr; } + /* ensure all text makes it to the screen before we prompt the user */ + fflush(stdout); + fflush(stderr); + vfprintf(stream, fmt, args); if(preset) { @@ -891,6 +895,7 @@ static int question(short preset, char *fmt, va_list args) return(preset); } + fflush(stream); if(fgets(response, sizeof(response), stdin)) { strtrim(response); if(strlen(response) == 0) { -- cgit v1.2.3-55-g3dc8 From c37710734694c5a64da924bbfbbcfc07496e241e Mon Sep 17 00:00:00 2001 From: Rémy Oudompheng Date: Sat, 2 Apr 2011 00:35:37 +0200 Subject: Fix compatibility with older versions of libarchive. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit There is no reason to not support versions of libarchive that lack ARCHIVE_COMPRESSION_UU. Distributions should work properly without this. Signed-off-by: Rémy Oudompheng Signed-off-by: Dan McGee --- lib/libalpm/be_sync.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c index ef8517e3..c2c62aa2 100644 --- a/lib/libalpm/be_sync.c +++ b/lib/libalpm/be_sync.c @@ -197,9 +197,11 @@ static size_t estimate_package_count(struct stat *st, struct archive *archive) case ARCHIVE_COMPRESSION_XZ: per_package = 143; break; +#ifdef ARCHIVE_COMPRESSION_UU case ARCHIVE_COMPRESSION_UU: per_package = 3543; break; +#endif default: /* assume it is at least somewhat compressed */ per_package = 200; -- cgit v1.2.3-55-g3dc8 From 0458572a6e9db0030f305c25e951434a099ae754 Mon Sep 17 00:00:00 2001 From: Rémy Oudompheng Date: Sat, 2 Apr 2011 00:36:08 +0200 Subject: util.c: include limits.h for PATH_MAX macro MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Oudompheng Signed-off-by: Dan McGee --- lib/libalpm/util.c | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index 11e69041..430da92a 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include -- cgit v1.2.3-55-g3dc8 From 38e5a4a54f1be3b678e5ab55b97f81be88824119 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sat, 2 Apr 2011 13:48:21 -0500 Subject: test: fix invalid usage of 'type -p' The vercmptest script needs to be invoked as a bash script for this to be valid; the -p operator is interpreted as an argument to look up by sh. This goes way back to commit 3bf9448943dc0b, done to solve http://mailman.archlinux.org/pipermail/pacman-dev/2008-July/007180.html. Saw this problem running in a virtual machine where sh is not bash, but in fact dash: user@debian-powerpc:~/projects/pacman$ ./test/util/vercmptest.sh src/util/vercmp-p: not found src/util/vercmp is src/util/vercmp vercmp binary (src/util/vercmp) could not be located Signed-off-by: Dan McGee --- test/util/vercmptest.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/util/vercmptest.sh b/test/util/vercmptest.sh index a9ed3b2a..6b3869c5 100755 --- a/test/util/vercmptest.sh +++ b/test/util/vercmptest.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # # vercmptest - a test suite for the vercmp/libalpm program # -- cgit v1.2.3-55-g3dc8 From 6a8b1c4f8433e95e713e3c6f152ba717c90d1dc9 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sat, 2 Apr 2011 13:51:25 -0500 Subject: Coding style cleanups Signed-off-by: Dan McGee --- src/pacman/util.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/pacman/util.c b/src/pacman/util.c index c7d98540..3d268031 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -746,8 +746,9 @@ static int multiselect_parse(char *array, int count, char *response) char *ends = NULL; char *starts = strtok_r(str, " ", &saveptr); - if (starts == NULL) + if (starts == NULL) { break; + } strtrim(starts); int len = strlen(starts); if(len == 0) @@ -765,9 +766,9 @@ static int multiselect_parse(char *array, int count, char *response) if(len > 1) { /* check for range */ char *p; - if((p = strchr(starts+1, '-'))) { + if((p = strchr(starts + 1, '-'))) { *p = 0; - ends = p+1; + ends = p + 1; } } @@ -777,9 +778,11 @@ static int multiselect_parse(char *array, int count, char *response) if(!ends) { array[start-1] = include; } else { - if(parseindex(ends, &end, start, count) != 0) + int d; + if(parseindex(ends, &end, start, count) != 0) { return(-1); - for(int d = start; d <= end; d++) { + } + for(d = start; d <= end; d++) { array[d-1] = include; } } -- cgit v1.2.3-55-g3dc8 From fc334b4e77553643bf9cdec47a4469ea7c62566b Mon Sep 17 00:00:00 2001 From: Rémy Oudompheng Date: Tue, 5 Apr 2011 01:38:21 +0200 Subject: db.c: set pm_errno appropriately in alpm_db_set_pkgreason() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Rémy Oudompheng Signed-off-by: Dan McGee --- lib/libalpm/db.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c index d9ed331e..49bbd00f 100644 --- a/lib/libalpm/db.c +++ b/lib/libalpm/db.c @@ -331,7 +331,7 @@ int SYMEXPORT alpm_db_set_pkgreason(pmdb_t *db, const char *name, pmpkgreason_t pkg->reason = reason; /* write DESC */ if(_alpm_local_db_write(db, pkg, INFRQ_DESC)) { - return(-1); + RET_ERR(PM_ERR_DB_WRITE, -1); } return(0); -- cgit v1.2.3-55-g3dc8 From 37df0d4f4fb042f8fbb39525d8d338968dd912bb Mon Sep 17 00:00:00 2001 From: Allan McRae Date: Thu, 31 Mar 2011 11:08:55 +1000 Subject: makepkg: improve parsing for sanity checks Trailing backslahses can lead to additional spaces at the front of extracted entries. See FS#23524. Strip these while parsing the PKGBUILD entries. Signed-off-by: Allan McRae Signed-off-by: Dan McGee --- scripts/makepkg.sh.in | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 193a1853..b55ac427 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -1256,7 +1256,7 @@ check_sanity() { local provides_list=() eval $(awk '/^[[:space:]]*provides=/,/\)/' "$BUILDFILE" | \ - sed -e "s/provides=/provides_list+=/" -e "s/#.*//") + sed -e "s/provides=/provides_list+=/" -e "s/#.*//" -e 's/\\$//') for i in ${provides_list[@]}; do if [[ $i != ${i///} ]]; then error "$(gettext "Provides array cannot contain comparison (< or >) operators.")" @@ -1266,7 +1266,7 @@ check_sanity() { local backup_list=() eval $(awk '/^[[:space:]]*backup=/,/\)/' "$BUILDFILE" | \ - sed -e "s/backup=/backup_list+=/" -e "s/#.*//") + sed -e "s/backup=/backup_list+=/" -e "s/#.*//" -e 's/\\$//') for i in "${backup_list[@]}"; do if [[ ${i:0:1} = "/" ]]; then error "$(gettext "Backup entry should not contain leading slash : %s")" "$i" @@ -1276,7 +1276,7 @@ check_sanity() { local optdepends_list=() eval $(awk '/^[[:space:]]*optdepends=\(/,/\)[[:space:]]*(|#.*)$/' "$BUILDFILE" | \ - sed -e "s/optdepends=/optdepends_list+=/" -e "s/#.*//") + sed -e "s/optdepends=/optdepends_list+=/" -e "s/#.*//" -e 's/\\$//') for i in "${optdepends_list[@]}"; do local pkg=${i%%:*} if [[ ! $pkg =~ ^[[:alnum:]\>\<\=\.\+\_\-]+$ ]]; then @@ -1301,7 +1301,7 @@ check_sanity() { local valid_options=1 local known kopt options_list eval $(awk '/^[[:space:]]*options=/,/\)/' "$BUILDFILE" | \ - sed -e "s/options=/options_list+=/" -e "s/#.*//") + sed -e "s/options=/options_list+=/" -e "s/#.*//" -e 's/\\$//') for i in ${options_list[@]}; do known=0 # check if option matches a known option or its inverse -- cgit v1.2.3-55-g3dc8 From 40fd8123a292ad16610367922dbdff66460bc676 Mon Sep 17 00:00:00 2001 From: Rémy Oudompheng Date: Sat, 2 Apr 2011 12:31:19 +0200 Subject: makepkg: fix a GNU-ism in awk usage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A non-GNU version of awk may not support the (|...) syntax for an optional group and require '()' to match an empty string. The (...)? syntax is more appropriate for this usage. Signed-off-by: Rémy Oudompheng Signed-off-by: Allan McRae 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 b55ac427..1c8c50e8 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -1275,7 +1275,7 @@ check_sanity() { done local optdepends_list=() - eval $(awk '/^[[:space:]]*optdepends=\(/,/\)[[:space:]]*(|#.*)$/' "$BUILDFILE" | \ + eval $(awk '/^[[:space:]]*optdepends=\(/,/\)[[:space:]]*(#.*)?$/' "$BUILDFILE" | \ sed -e "s/optdepends=/optdepends_list+=/" -e "s/#.*//" -e 's/\\$//') for i in "${optdepends_list[@]}"; do local pkg=${i%%:*} -- cgit v1.2.3-55-g3dc8 From ff1974c6e9aa97a6b0cf5e2ce82da70fd70c510c Mon Sep 17 00:00:00 2001 From: Xavier Chantry Date: Sat, 2 Apr 2011 20:24:40 +0200 Subject: libalpm/pkghash.c: unused variable ptr spotted by clang analyzer Signed-off-by: Xavier Chantry --- lib/libalpm/pkghash.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/libalpm/pkghash.c b/lib/libalpm/pkghash.c index db98f94b..6dc43243 100644 --- a/lib/libalpm/pkghash.c +++ b/lib/libalpm/pkghash.c @@ -84,12 +84,11 @@ pmpkghash_t *_alpm_pkghash_create(size_t size) static size_t get_hash_position(unsigned long name_hash, pmpkghash_t *hash) { size_t position; - alpm_list_t *ptr; position = name_hash % hash->buckets; /* collision resolution using open addressing with linear probing */ - while((ptr = hash->hash_table[position]) != NULL) { + while(hash->hash_table[position] != NULL) { position = (position + 1) % hash->buckets; } -- cgit v1.2.3-55-g3dc8 From 272e9b355b17ab663ac4a0d9515d381dcf6f03ec Mon Sep 17 00:00:00 2001 From: Xavier Chantry Date: Sat, 2 Apr 2011 20:26:27 +0200 Subject: libalpm/be_local.c: unused variable ent spotted by clang analyzer Signed-off-by: Xavier Chantry --- lib/libalpm/be_local.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c index c13dffb4..edb62054 100644 --- a/lib/libalpm/be_local.c +++ b/lib/libalpm/be_local.c @@ -405,7 +405,7 @@ static int local_db_populate(pmdb_t *db) * http://kerneltrap.org/mailarchive/linux-btrfs/2010/1/23/6723483/thread */ est_count = 0; - while((ent = readdir(dbdir)) != NULL) { + while(readdir(dbdir) != NULL) { est_count++; } rewinddir(dbdir); -- cgit v1.2.3-55-g3dc8