From b6209b4ba495dd4379806b72735dac78b8843c03 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Thu, 12 Jan 2012 07:47:29 -0600 Subject: Use fileno() in isatty() call This was our only use of the function that had a hardcoded file descriptor. Signed-off-by: Dan McGee --- src/pacman/pacman.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 326664dd..bce73d21 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -801,7 +801,7 @@ int main(int argc, char *argv[]) config = config_new(); /* disable progressbar if the output is redirected */ - if(!isatty(1)) { + if(!isatty(fileno(stdout))) { config->noprogressbar = 1; } -- cgit v1.2.3-24-g4f1b From e8a2c2545608c556cb65d96e7015a1d09d8b3890 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Thu, 12 Jan 2012 17:29:14 -0600 Subject: doc/vercmp: add note about pkgrel handling This comes from the Doxygen function documentation. Also, fix two rather silly misspellings. Signed-off-by: Dan McGee --- doc/vercmp.8.txt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/doc/vercmp.8.txt b/doc/vercmp.8.txt index 4b0490fa..6b94f3e4 100644 --- a/doc/vercmp.8.txt +++ b/doc/vercmp.8.txt @@ -6,7 +6,7 @@ vercmp(8) Name ---- -vercmp - version comparsion utility +vercmp - version comparison utility Synopsis @@ -23,7 +23,7 @@ numbers. It outputs values as follows: * = 0 : if ver1 == ver2 * > 0 : if ver1 > ver2 -Version comparsion operates as follows: +Version comparison operates as follows: Alphanumeric: 1.0a < 1.0b < 1.0beta < 1.0p < 1.0pre < 1.0rc < 1.0 < 1.0.a < 1.0.1 @@ -35,6 +35,11 @@ overrule any version comparison (unless the epoch values are equal). This is specified in an `epoch:version-rel` format. For example, `2:1.0-1` is always greater than `1:3.6-1`. +Keep in mind that the 'pkgrel' is only compared if it is available on both +versions given to this tool. For example, comparing `1.5-1` and `1.5` will +yield 0; comparing `1.5-1` and `1.5-2` will yield < 0 as expected. This is +mainly for supporting versioned dependencies that do not include the 'pkgrel'. + Options ------- -- cgit v1.2.3-24-g4f1b From be229d129eeb43e774217921e1c7e1bb802775fe Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Wed, 18 Jan 2012 12:12:39 -0600 Subject: Don't remove unknown files in cache cleaning code This removes the hack I added to skip '*.sig' files earlier since there are other files that also fall into the same bucket- source packages from `makepkg --source`, delta files, etc. Rather than prompting for each and every one, simply skip them. Doing '-Scc' rather than '-Sc' will delete these files if that is really what you want to do. Signed-off-by: Dan McGee --- doc/pacman.8.txt | 2 +- src/pacman/sync.c | 32 ++++++++++---------------------- 2 files changed, 11 insertions(+), 23 deletions(-) diff --git a/doc/pacman.8.txt b/doc/pacman.8.txt index 59853812..275f8ac0 100644 --- a/doc/pacman.8.txt +++ b/doc/pacman.8.txt @@ -349,7 +349,7 @@ Sync Options[[SO]] databases are saved for every sync DB you download from, and are not deleted even if they are removed from the configuration file linkman:pacman.conf[5]. Use one '\--clean' switch to only remove - packages that are no longer installed; use two to remove all packages + packages that are no longer installed; use two to remove all files from the cache. In both cases, you will have a yes or no option to remove packages and/or unused downloaded databases. + diff --git a/src/pacman/sync.c b/src/pacman/sync.c index 2773708c..2c64f090 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -198,7 +198,6 @@ static int sync_cleancache(int level) /* step through the directory one file at a time */ while((ent = readdir(dir)) != NULL) { char path[PATH_MAX]; - size_t pathlen; int delete = 1; alpm_pkg_t *localpkg = NULL, *pkg = NULL; const char *local_name, *local_version; @@ -209,30 +208,18 @@ static int sync_cleancache(int level) /* build the full filepath */ snprintf(path, PATH_MAX, "%s%s", cachedir, ent->d_name); - /* short circuit for removing all packages from cache */ + /* short circuit for removing all files from cache */ if(level > 1) { unlink(path); continue; } - /* we handle .sig files with packages, not separately */ - pathlen = strlen(path); - if(strcmp(path + pathlen - 4, ".sig") == 0) { - continue; - } - - /* attempt to load the package, prompt removal on failures as we may have - * files here that aren't valid packages. we also don't need a full - * load of the package, just the metadata. */ - if(alpm_pkg_load(config->handle, path, 0, 0, &localpkg) != 0 - || localpkg == NULL) { - if(yesno(_("File %s does not seem to be a valid package, remove it?"), - path)) { - if(localpkg) { - alpm_pkg_free(localpkg); - } - unlink(path); - } + /* attempt to load the file as a package. if we cannot load the file, + * simply skip it and move on. we don't need a full load of the package, + * just the metadata. */ + if(alpm_pkg_load(config->handle, path, 0, 0, &localpkg) != 0) { + pm_printf(ALPM_LOG_DEBUG, "skipping %s, could not load as package\n", + path); continue; } local_name = alpm_pkg_get_name(localpkg); @@ -244,7 +231,7 @@ static int sync_cleancache(int level) if(pkg != NULL && alpm_pkg_vercmp(local_version, alpm_pkg_get_version(pkg)) == 0) { /* package was found in local DB and version matches, keep it */ - pm_printf(ALPM_LOG_DEBUG, "pkg %s-%s found in local db\n", + pm_printf(ALPM_LOG_DEBUG, "package %s-%s found in local db\n", local_name, local_version); delete = 0; } @@ -258,7 +245,7 @@ static int sync_cleancache(int level) if(pkg != NULL && alpm_pkg_vercmp(local_version, alpm_pkg_get_version(pkg)) == 0) { /* package was found in a sync DB and version matches, keep it */ - pm_printf(ALPM_LOG_DEBUG, "pkg %s-%s found in sync db\n", + pm_printf(ALPM_LOG_DEBUG, "package %s-%s found in sync db\n", local_name, local_version); delete = 0; } @@ -268,6 +255,7 @@ static int sync_cleancache(int level) alpm_pkg_free(localpkg); if(delete) { + size_t pathlen = strlen(path); unlink(path); /* unlink a signature file if present too */ if(PATH_MAX - 5 >= pathlen) { -- cgit v1.2.3-24-g4f1b From 7b1a86b8939f59693f8bb0ea0454a702d5e2434e Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Wed, 18 Jan 2012 15:32:34 -0600 Subject: Remove unused strtoupper() function Signed-off-by: Dan McGee --- src/pacman/util.c | 13 ------------- src/pacman/util.h | 1 - 2 files changed, 14 deletions(-) diff --git a/src/pacman/util.c b/src/pacman/util.c index b9ee8c9c..e4e44c63 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -312,19 +312,6 @@ void indentprint(const char *str, size_t indent) free(wcstr); } -/* Convert a string to uppercase - */ -char *strtoupper(char *str) -{ - char *ptr = str; - - while(*ptr) { - (*ptr) = (char)toupper((unsigned char)*ptr); - ptr++; - } - return str; -} - /* Trim whitespace and newlines from a string */ char *strtrim(char *str) diff --git a/src/pacman/util.h b/src/pacman/util.h index 6ec962ff..49cf1dbd 100644 --- a/src/pacman/util.h +++ b/src/pacman/util.h @@ -55,7 +55,6 @@ int rmrf(const char *path); const char *mbasename(const char *path); char *mdirname(const char *path); void indentprint(const char *str, size_t indent); -char *strtoupper(char *str); char *strtrim(char *str); char *strreplace(const char *str, const char *needle, const char *replace); alpm_list_t *strsplit(const char *str, const char splitchar); -- cgit v1.2.3-24-g4f1b From b426488e2b1cf4e464f7f56dbcf2629a3a73a54a Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Wed, 18 Jan 2012 15:32:48 -0600 Subject: Use isdigit() rather than character range comparisons This is safer and guaranteed to work with even exotic character sets. Signed-off-by: Dan McGee --- lib/libalpm/util.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index ad15d937..2d0153e5 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -1085,7 +1085,7 @@ off_t _alpm_strtoofft(const char *line) errno = 0; /* we are trying to parse bare numbers only, no leading anything */ - if(line[0] < '0' || line[0] > '9') { + if(!isdigit((unsigned char)line[0])) { return (off_t)-1; } result = strtoull(line, &end, 10); -- cgit v1.2.3-24-g4f1b From 4e60b9646d69227c6c9f226bf03a12158feaaee7 Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sat, 14 Jan 2012 15:27:48 -0500 Subject: fetch_url: look for files in cache before downloading We lost this logic somewhere between the libfetch and libcurl transition, as it existed in the internal downloader, but was pulled back only into the sync workflow. Add a helper function that will let us check for existance in the filecache prior to calling the downloader. Signed-off-by: Dave Reisner Signed-off-by: Dan McGee --- lib/libalpm/dload.c | 92 ++++++++++++++++++++++++++++++++++------------------- 1 file changed, 60 insertions(+), 32 deletions(-) diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c index 29285903..928324e8 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -562,6 +562,22 @@ int _alpm_download(struct dload_payload *payload, const char *localpath, } } +static char *filecache_find_url(alpm_handle_t *handle, const char *url) +{ + const char *basename = strrchr(url, '/'); + + if(basename == NULL) { + return NULL; + } + + basename++; + if(basename == '\0') { + return NULL; + } + + return _alpm_filecache_find(handle, basename); +} + /** Fetch a remote pkg. */ char SYMEXPORT *alpm_fetch_pkgurl(alpm_handle_t *handle, const char *url) { @@ -569,7 +585,7 @@ char SYMEXPORT *alpm_fetch_pkgurl(alpm_handle_t *handle, const char *url) const char *cachedir; char *final_file = NULL; struct dload_payload payload; - int ret; + int ret = 0; CHECK_HANDLE(handle, return NULL); ASSERT(url, RET_ERR(handle, ALPM_ERR_WRONG_ARGS, NULL)); @@ -578,51 +594,63 @@ char SYMEXPORT *alpm_fetch_pkgurl(alpm_handle_t *handle, const char *url) cachedir = _alpm_filecache_setup(handle); memset(&payload, 0, sizeof(struct dload_payload)); - payload.handle = handle; - STRDUP(payload.fileurl, url, RET_ERR(handle, ALPM_ERR_MEMORY, NULL)); - payload.allow_resume = 1; - - /* download the file */ - ret = _alpm_download(&payload, cachedir, &final_file); - _alpm_dload_payload_reset(&payload); - if(ret == -1) { - _alpm_log(handle, ALPM_LOG_WARNING, _("failed to download %s\n"), url); - free(final_file); - return NULL; + + /* attempt to find the file in our pkgcache */ + filepath = filecache_find_url(handle, url); + if(filepath == NULL) { + STRDUP(payload.fileurl, url, RET_ERR(handle, ALPM_ERR_MEMORY, NULL)); + payload.allow_resume = 1; + payload.handle = handle; + + /* download the file */ + ret = _alpm_download(&payload, cachedir, &final_file); + _alpm_dload_payload_reset(&payload); + if(ret == -1) { + _alpm_log(handle, ALPM_LOG_WARNING, _("failed to download %s\n"), url); + free(final_file); + return NULL; + } + _alpm_log(handle, ALPM_LOG_DEBUG, "successfully downloaded %s\n", url); } - _alpm_log(handle, ALPM_LOG_DEBUG, "successfully downloaded %s\n", url); /* attempt to download the signature */ if(ret == 0 && (handle->siglevel & ALPM_SIG_PACKAGE)) { - char *sig_final_file = NULL; + char *sig_filepath, *sig_final_file = NULL; size_t len; len = strlen(url) + 5; MALLOC(payload.fileurl, len, RET_ERR(handle, ALPM_ERR_MEMORY, NULL)); snprintf(payload.fileurl, len, "%s.sig", url); - payload.handle = handle; - payload.force = 1; - payload.errors_ok = (handle->siglevel & ALPM_SIG_PACKAGE_OPTIONAL); - - /* set hard upper limit of 16KiB */ - payload.max_size = 16 * 1024; - - ret = _alpm_download(&payload, cachedir, &sig_final_file); - if(ret == -1 && !payload.errors_ok) { - _alpm_log(handle, ALPM_LOG_WARNING, - _("failed to download %s\n"), payload.fileurl); - /* Warn now, but don't return NULL. We will fail later during package - * load time. */ - } else if(ret == 0) { - _alpm_log(handle, ALPM_LOG_DEBUG, - "successfully downloaded %s\n", payload.fileurl); + + sig_filepath = filecache_find_url(handle, payload.fileurl); + if(sig_filepath == NULL) { + payload.handle = handle; + payload.force = 1; + payload.errors_ok = (handle->siglevel & ALPM_SIG_PACKAGE_OPTIONAL); + + /* set hard upper limit of 16KiB */ + payload.max_size = 16 * 1024; + + ret = _alpm_download(&payload, cachedir, &sig_final_file); + if(ret == -1 && !payload.errors_ok) { + _alpm_log(handle, ALPM_LOG_WARNING, + _("failed to download %s\n"), payload.fileurl); + /* Warn now, but don't return NULL. We will fail later during package + * load time. */ + } else if(ret == 0) { + _alpm_log(handle, ALPM_LOG_DEBUG, + "successfully downloaded %s\n", payload.fileurl); + } + FREE(sig_final_file); } - FREE(sig_final_file); + free(sig_filepath); _alpm_dload_payload_reset(&payload); } /* we should be able to find the file the second time around */ - filepath = _alpm_filecache_find(handle, final_file); + if(filepath == NULL) { + filepath = _alpm_filecache_find(handle, final_file); + } free(final_file); return filepath; -- cgit v1.2.3-24-g4f1b From d9af1a0cf2383eed009ed2bedfb1b34f1a5c7418 Mon Sep 17 00:00:00 2001 From: Olivier Brunel Date: Thu, 12 Jan 2012 16:08:48 +0100 Subject: Fix broken output when asking question and stdin is piped When asking question and stdin is piped, the response does not get printed out, resulting in a missing \n and broken output (FS#27909); printing the response fixes it. Signed-off-by: Olivier Brunel Signed-off-by: Dan McGee --- src/pacman/util.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/pacman/util.c b/src/pacman/util.c index e4e44c63..d72509a5 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -1365,6 +1365,12 @@ static int question(short preset, char *fmt, va_list args) return preset; } + /* if stdin is piped, response does not get printed out, and as a result + * a \n is missing, resulting in broken output (FS#27909) */ + if(!isatty(fileno(stdin))) { + fprintf(stream, "%s\n", response); + } + if(strcasecmp(response, _("Y")) == 0 || strcasecmp(response, _("YES")) == 0) { return 1; } else if(strcasecmp(response, _("N")) == 0 || strcasecmp(response, _("NO")) == 0) { -- cgit v1.2.3-24-g4f1b From 430b0df7794815049f37f38df39c71e1a9e9c157 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Thu, 12 Jan 2012 09:32:19 -0600 Subject: repo-add: clean up help messages Use consistent blank lines across all commands, get rid of the translated double newlines which only serve to confuse translators, and fix -h/--help for that extra special third command this script offers. Signed-off-by: Dan McGee --- scripts/repo-add.sh.in | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in index 4708086c..6a10a684 100644 --- a/scripts/repo-add.sh.in +++ b/scripts/repo-add.sh.in @@ -48,30 +48,38 @@ usage() { printf "%s (pacman) %s\n\n" "$cmd" "$myver" if [[ $cmd == "repo-add" ]] ; then printf "$(gettext "Usage: repo-add [options] ...\n")" + printf "\n" printf "$(gettext "\ repo-add will update a package database by reading a package file.\n\ -Multiple packages to add can be specified on the command line.\n\n")" +Multiple packages to add can be specified on the command line.\n")" + printf "\n" printf "$(gettext "Options:\n")" printf "$(gettext " -d, --delta generate and add delta for package update\n")" printf "$(gettext " -f, --files update database's file list\n")" elif [[ $cmd == "repo-remove" ]] ; then - printf "$(gettext "Usage: repo-remove [options] ...\n\n")" + printf "$(gettext "Usage: repo-remove [options] ...\n")" + printf "\n" printf "$(gettext "\ repo-remove will update a package database by removing the package name\n\ specified on the command line from the given repo database. Multiple\n\ -packages to remove can be specified on the command line.\n\n")" +packages to remove can be specified on the command line.\n")" + printf "\n" printf "$(gettext "Options:\n")" + else + printf "$(gettext "Please move along, there is nothing to see here.\n")" + return fi printf "$(gettext " -q, --quiet minimize output\n")" printf "$(gettext " -s, --sign sign database with GnuPG after update\n")" printf "$(gettext " -k, --key use the specified key to sign the database\n")" printf "$(gettext " -v, --verify verify database's signature before update\n")" printf "$(gettext "\n\ -See %s(8) for more details and descriptions of the available options.\n\n")" $cmd +See %s(8) for more details and descriptions of the available options.\n")" $cmd + printf "\n" if [[ $cmd == "repo-add" ]] ; then - echo "$(gettext "Example: repo-add /path/to/repo.db.tar.gz pacman-3.0.0-1-i686.pkg.tar.gz")" + printf "$(gettext "Example: repo-add /path/to/repo.db.tar.gz pacman-3.0.0-1-i686.pkg.tar.gz\n")" elif [[ $cmd == "repo-remove" ]] ; then - echo "$(gettext "Example: repo-remove /path/to/repo.db.tar.gz kernel26")" + printf "$(gettext "Example: repo-remove /path/to/repo.db.tar.gz kernel26\n")" fi } -- cgit v1.2.3-24-g4f1b From 24ca6ce1f969a6f5d3ef9277f6d20efcd76330ec Mon Sep 17 00:00:00 2001 From: canyonknight Date: Mon, 16 Jan 2012 19:09:56 -0500 Subject: Turn gpg commands into functions in pacman-key Adds functions for every gpg command. By pulling out the gpg commands from the "program start" section, additional commands can be run before or after a specific gpg command without adding additional clutter to the function call section. Adds an explicit exit status of 0 to prevent arithmetic expansions from returning non-zero, thereby falsely causing pacman-key to have a non-zero exit status. This change creates the framework for additional error messages and better exit statuses being added to every pacman-key gpg call. Signed-off-by: canyonknight Signed-off-by: Allan McRae Signed-off-by: Dan McGee --- scripts/pacman-key.sh.in | 74 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 58 insertions(+), 16 deletions(-) diff --git a/scripts/pacman-key.sh.in b/scripts/pacman-key.sh.in index f358c487..02df8c50 100644 --- a/scripts/pacman-key.sh.in +++ b/scripts/pacman-key.sh.in @@ -338,6 +338,14 @@ populate_keyring() { fi } +add_keys() { + "${GPG_PACMAN[@]}" --quiet --batch --import "${KEYFILES[@]}" +} + +delete_keys() { + "${GPG_PACMAN[@]}" --quiet --batch --delete-key --yes "${KEYIDS[@]}" +} + edit_keys() { local errors=0; for key in "${KEYIDS[@]}"; do @@ -354,6 +362,14 @@ edit_keys() { done } +export_keys() { + "${GPG_PACMAN[@]}" --armor --export "${KEYIDS[@]}" +} + +finger_keys() { + "${GPG_PACMAN[@]}" --batch --fingerprint "${KEYIDS[@]}" +} + import_trustdb() { local importdir @@ -375,6 +391,35 @@ import() { done } +list_keys() { + "${GPG_PACMAN[@]}" --batch --list-keys "${KEYIDS[@]}" +} + +list_sigs() { + "${GPG_PACMAN[@]}" --batch --list-sigs "${KEYIDS[@]}" +} + +lsign_keys() { + printf 'y\ny\n' | LANG=C "${GPG_PACMAN[@]}" --command-fd 0 --quiet --batch --lsign-key "${KEYIDS[@]}" 2>/dev/null +} + +receive_keys() { + "${GPG_PACMAN[@]}" --recv-keys "${KEYIDS[@]}" +} + +refresh_keys() { + "${GPG_PACMAN[@]}" --refresh-keys "${KEYIDS[@]}" +} + +verify_sig() { + "${GPG_PACMAN[@]}" --verify $SIGNATURE +} + +updatedb() { + msg "$(gettext "Updating trust database...")" + "${GPG_PACMAN[@]}" --batch --check-trustdb +} + # PROGRAM START if ! type gettext &>/dev/null; then gettext() { @@ -476,27 +521,24 @@ esac (( ! INIT )) && check_keyring -(( ADD )) && "${GPG_PACMAN[@]}" --quiet --batch --import "${KEYFILES[@]}" -(( DELETE )) && "${GPG_PACMAN[@]}" --quiet --batch --delete-key --yes "${KEYIDS[@]}" +(( ADD )) && add_keys +(( DELETE )) && delete_keys (( EDITKEY )) && edit_keys -(( EXPORT )) && "${GPG_PACMAN[@]}" --armor --export "${KEYIDS[@]}" -(( FINGER )) && "${GPG_PACMAN[@]}" --batch --fingerprint "${KEYIDS[@]}" +(( EXPORT )) && export_keys +(( FINGER )) && finger_keys (( IMPORT )) && import (( IMPORT_TRUSTDB)) && import_trustdb (( INIT )) && initialize -(( LISTKEYS )) && "${GPG_PACMAN[@]}" --batch --list-keys "${KEYIDS[@]}" -(( LISTSIGS )) && "${GPG_PACMAN[@]}" --batch --list-sigs "${KEYIDS[@]}" -if (( LSIGNKEY )); then - printf 'y\ny\n' | LANG=C "${GPG_PACMAN[@]}" --command-fd 0 --quiet --batch --lsign-key "${KEYIDS[@]}" 2>/dev/null -fi +(( LISTKEYS )) && list_keys +(( LISTSIGS )) && list_sigs +(( LSIGNKEY )) && lsign_keys (( POPULATE )) && populate_keyring -(( RECEIVE )) && "${GPG_PACMAN[@]}" --recv-keys "${KEYIDS[@]}" -(( REFRESH )) && "${GPG_PACMAN[@]}" --refresh-keys "${KEYIDS[@]}" -(( VERIFY )) && "${GPG_PACMAN[@]}" --verify "$SIGNATURE" +(( RECEIVE )) && receive_keys +(( REFRESH )) && refresh_keys +(( VERIFY )) && verify_sig -if (( UPDATEDB )); then - msg "$(gettext "Updating trust database...")" - "${GPG_PACMAN[@]}" --batch --check-trustdb -fi +(( UPDATEDB )) && updatedb + +exit 0 # vim: set ts=2 sw=2 noet: -- cgit v1.2.3-24-g4f1b From c231c9af9712e95e58f660d46bd8feaf6fd891e2 Mon Sep 17 00:00:00 2001 From: canyonknight Date: Mon, 16 Jan 2012 19:12:41 -0500 Subject: Improve exit statuses and error messages in pacman-key Return codes from gpg commands are currently lost. This adds the functionality of taking non-zero exit statuses from gpg. This includes error reporting for all gpg commands that are run individually, run in a loop, and run through a pipe. Includes the check_keyids_exist function which verifies a key exists locally prior to attempted local manipulation of the key. If a gpg command has a non-zero status, pacman-key will now exit with a non-zero status. It will print a gettext error message of gpg's failure. Signed-off-by: canyonknight Signed-off-by: Allan McRae Signed-off-by: Dan McGee --- scripts/pacman-key.sh.in | 118 ++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 95 insertions(+), 23 deletions(-) diff --git a/scripts/pacman-key.sh.in b/scripts/pacman-key.sh.in index 02df8c50..b7c77d82 100644 --- a/scripts/pacman-key.sh.in +++ b/scripts/pacman-key.sh.in @@ -144,6 +144,20 @@ add_gpg_conf_option() { fi } +check_keyids_exist() { + local ret=0 + for key in "${KEYIDS[@]}"; do + # Verify if the key exists in pacman's keyring + if ! "${GPG_PACMAN[@]}" --list-keys "$key" &>/dev/null ; then + error "$(gettext "The key identified by %s could not be found locally.")" "$key" + ret=1 + fi + done + if (( ret )); then + exit 1 + fi +} + initialize() { local conffile keyserv # Check for simple existence rather than for a directory as someone @@ -339,85 +353,143 @@ populate_keyring() { } add_keys() { - "${GPG_PACMAN[@]}" --quiet --batch --import "${KEYFILES[@]}" + if ! "${GPG_PACMAN[@]}" --quiet --batch --import "${KEYFILES[@]}" ; then + error "$(gettext "A specified keyfile could not be added to the gpg keychain.")" + exit 1 + fi } delete_keys() { - "${GPG_PACMAN[@]}" --quiet --batch --delete-key --yes "${KEYIDS[@]}" + check_keyids_exist + if ! "${GPG_PACMAN[@]}" --quiet --batch --delete-key --yes "${KEYIDS[@]}" ; then + error "$(gettext "A specified key could not be removed from the gpg keychain.")" + exit 1 + fi } edit_keys() { - local errors=0; + check_keyids_exist + local ret=0 for key in "${KEYIDS[@]}"; do - # Verify if the key exists in pacman's keyring - if ! "${GPG_PACMAN[@]}" --list-keys "$key" &>/dev/null; then - error "$(gettext "The key identified by %s does not exist.")" "$key" - errors=1; + if ! "${GPG_PACMAN[@]}" --edit-key "$key" ; then + error "$(gettext "The key identified by %s could not be edited.")" "$key" + ret=1 fi done - (( errors )) && exit 1; - - for key in "${KEYIDS[@]}"; do - "${GPG_PACMAN[@]}" --edit-key "$key" - done + if (( ret )); then + exit 1 + fi } export_keys() { - "${GPG_PACMAN[@]}" --armor --export "${KEYIDS[@]}" + check_keyids_exist + if ! "${GPG_PACMAN[@]}" --armor --export "${KEYIDS[@]}" ; then + error "$(gettext "A specified key could not be exported from the gpg keychain.")" + exit 1 + fi } finger_keys() { - "${GPG_PACMAN[@]}" --batch --fingerprint "${KEYIDS[@]}" + check_keyids_exist + if ! "${GPG_PACMAN[@]}" --batch --fingerprint "${KEYIDS[@]}" ; then + error "$(gettext "The fingerprint of a specified key could not be determined.")" + exit 1 + fi } import_trustdb() { local importdir - + local ret=0 for importdir in "${IMPORT_DIRS[@]}"; do if [[ -f "${importdir}/trustdb.gpg" ]]; then gpg --homedir "${importdir}" --export-ownertrust | \ "${GPG_PACMAN[@]}" --import-ownertrust - + if (( PIPESTATUS )); then + error "$(gettext "%s could not be imported.")" "${importdir}/trustdb.gpg" + ret=1 + fi + else + error "$(gettext "File %s does not exist and could not be imported.")" "${importdir}/trustdb.gpg" + ret=1 fi done + if (( ret )); then + exit 1 + fi } import() { local importdir - + local ret=0 for importdir in "${IMPORT_DIRS[@]}"; do if [[ -f "${importdir}/pubring.gpg" ]]; then - "${GPG_PACMAN[@]}" --quiet --batch --import "${importdir}/pubring.gpg" + if ! "${GPG_PACMAN[@]}" --quiet --batch --import "${importdir}/pubring.gpg" ; then + error "$(gettext "%s could not be imported.")" "${importdir}/pubring.gpg" + ret=1 + fi + else + error "$(gettext "File %s does not exist and could not be imported.")" "${importdir}/pubring.gpg" + ret=1 fi done + if (( ret )); then + exit 1 + fi } list_keys() { - "${GPG_PACMAN[@]}" --batch --list-keys "${KEYIDS[@]}" + check_keyids_exist + if ! "${GPG_PACMAN[@]}" --batch --list-keys "${KEYIDS[@]}" ; then + error "$(gettext "A specified key could not be listed.")" + exit 1 + fi } list_sigs() { - "${GPG_PACMAN[@]}" --batch --list-sigs "${KEYIDS[@]}" + check_keyids_exist + if ! "${GPG_PACMAN[@]}" --batch --list-sigs "${KEYIDS[@]}" ; then + error "$(gettext "A specified signature could not be listed.")" + exit 1 + fi } lsign_keys() { + check_keyids_exist printf 'y\ny\n' | LANG=C "${GPG_PACMAN[@]}" --command-fd 0 --quiet --batch --lsign-key "${KEYIDS[@]}" 2>/dev/null + if (( PIPESTATUS[1] )); then + error "$(gettext "A specified key could not be locally signed.")" + exit 1 + fi } receive_keys() { - "${GPG_PACMAN[@]}" --recv-keys "${KEYIDS[@]}" + if ! "${GPG_PACMAN[@]}" --recv-keys "${KEYIDS[@]}" ; then + error "$(gettext "Remote key not fetched correctly from keyserver.")" + exit 1 + fi } refresh_keys() { - "${GPG_PACMAN[@]}" --refresh-keys "${KEYIDS[@]}" + check_keyids_exist + if ! "${GPG_PACMAN[@]}" --refresh-keys "${KEYIDS[@]}" ; then + error "$(gettext "A specified local key could not be updated from a keyserver.")" + exit 1 + fi } verify_sig() { - "${GPG_PACMAN[@]}" --verify $SIGNATURE + if ! "${GPG_PACMAN[@]}" --verify $SIGNATURE ; then + error "$(gettext "The signature identified by %s could not be verified.")" "$SIGNATURE" + exit 1 + fi } updatedb() { msg "$(gettext "Updating trust database...")" - "${GPG_PACMAN[@]}" --batch --check-trustdb + if ! "${GPG_PACMAN[@]}" --batch --check-trustdb ; then + error "$(gettext "Trust database could not be updated.")" + exit 1 + fi } # PROGRAM START -- cgit v1.2.3-24-g4f1b From c77cec2ffc850fa28c5720b8902acc5421069ae4 Mon Sep 17 00:00:00 2001 From: Allan McRae Date: Thu, 19 Jan 2012 11:29:36 +1000 Subject: Fix missing [removal] output Currently, a transaction is considered to be purely package removal until the first package install is found. This resulted in the removed packages at the start of a combined upgrade/removal transaction not getting the "[removal]" output. Fixes FS#27981. Signed-off-by: Allan McRae Signed-off-by: Dan McGee --- src/pacman/util.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/pacman/util.c b/src/pacman/util.c index d72509a5..76054132 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -835,8 +835,12 @@ static void _display_targets(alpm_list_t *targets, int verbose) /* add up size of all removed packages */ rsize += alpm_pkg_get_isize(target->remove); } + } + + /* form data for both verbose and non-verbose display */ + for(i = targets; i; i = alpm_list_next(i)) { + pm_target_t *target = i->data; - /* form data for both verbose and non-verbose display */ rows = alpm_list_add(rows, create_verbose_row(target, show_dl_size)); if(target->install) { pm_asprintf(&str, "%s-%s", alpm_pkg_get_name(target->install), -- cgit v1.2.3-24-g4f1b From 1b50223f8240456b8c989b5c1e016f4a245b527c Mon Sep 17 00:00:00 2001 From: Olivier Brunel Date: Mon, 9 Jan 2012 21:37:31 +0100 Subject: util.c, rmrf(): only create string when needed The entry's name is only used when not "." or ".." so only print the string then. Signed-off-by: Olivier Brunel Signed-off-by: Dan McGee --- lib/libalpm/util.c | 6 +++--- src/pacman/util.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index 2d0153e5..6834751f 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -381,7 +381,6 @@ int _alpm_rmrf(const char *path) int errflag = 0; struct dirent *dp; DIR *dirp; - char name[PATH_MAX]; struct stat st; if(_alpm_lstat(path, &st) == 0) { @@ -401,9 +400,10 @@ int _alpm_rmrf(const char *path) return 1; } for(dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) { - if(dp->d_ino) { - sprintf(name, "%s/%s", path, dp->d_name); + if(dp->d_name) { if(strcmp(dp->d_name, "..") != 0 && strcmp(dp->d_name, ".") != 0) { + char name[PATH_MAX]; + sprintf(name, "%s/%s", path, dp->d_name); errflag += _alpm_rmrf(name); } } diff --git a/src/pacman/util.c b/src/pacman/util.c index 76054132..a8f19682 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -192,10 +192,10 @@ int rmrf(const char *path) return 1; } for(dp = readdir(dirp); dp != NULL; dp = readdir(dirp)) { - if(dp->d_ino) { - char name[PATH_MAX]; - sprintf(name, "%s/%s", path, dp->d_name); + if(dp->d_name) { if(strcmp(dp->d_name, "..") != 0 && strcmp(dp->d_name, ".") != 0) { + char name[PATH_MAX]; + snprintf(name, PATH_MAX, "%s/%s", path, dp->d_name); errflag += rmrf(name); } } -- cgit v1.2.3-24-g4f1b From 562109c0e8717eaac3b9078271c4ca4f82abfecd Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Wed, 18 Jan 2012 22:25:27 -0600 Subject: Update copyright on changed files since beginning of year Signed-off-by: Dan McGee --- lib/libalpm/dload.c | 2 +- lib/libalpm/remove.c | 2 +- lib/libalpm/signing.c | 2 +- lib/libalpm/util.c | 2 +- scripts/makepkg.sh.in | 4 ++-- scripts/pacman-key.sh.in | 4 ++-- scripts/repo-add.sh.in | 4 ++-- src/pacman/pacman.c | 2 +- src/pacman/sync.c | 2 +- src/pacman/util.c | 2 +- src/pacman/util.h | 2 +- 11 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c index 928324e8..6fe4a323 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -1,7 +1,7 @@ /* * download.c * - * Copyright (c) 2006-2011 Pacman Development Team + * Copyright (c) 2006-2012 Pacman Development Team * Copyright (c) 2002-2006 by Judd Vinet * * This program is free software; you can redistribute it and/or modify diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c index 41cee514..cc9e289d 100644 --- a/lib/libalpm/remove.c +++ b/lib/libalpm/remove.c @@ -1,7 +1,7 @@ /* * remove.c * - * Copyright (c) 2006-2011 Pacman Development Team + * Copyright (c) 2006-2012 Pacman Development Team * Copyright (c) 2002-2006 by Judd Vinet * Copyright (c) 2005 by Aurelien Foret * Copyright (c) 2005 by Christian Hamar diff --git a/lib/libalpm/signing.c b/lib/libalpm/signing.c index 1a53deaa..3ec957de 100644 --- a/lib/libalpm/signing.c +++ b/lib/libalpm/signing.c @@ -1,7 +1,7 @@ /* * signing.c * - * Copyright (c) 2008-2011 Pacman Development Team + * Copyright (c) 2008-2012 Pacman Development Team * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index 6834751f..0e5e8a00 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -1,7 +1,7 @@ /* * util.c * - * Copyright (c) 2006-2011 Pacman Development Team + * Copyright (c) 2006-2012 Pacman Development Team * Copyright (c) 2002-2006 by Judd Vinet * Copyright (c) 2005 by Aurelien Foret * Copyright (c) 2005 by Christian Hamar diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 797b8d78..169162ce 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -3,7 +3,7 @@ # makepkg - make packages compatible for use with pacman # @configure_input@ # -# Copyright (c) 2006-2011 Pacman Development Team +# Copyright (c) 2006-2012 Pacman Development Team # Copyright (c) 2002-2006 by Judd Vinet # Copyright (c) 2005 by Aurelien Foret # Copyright (c) 2006 by Miklos Vajna @@ -1866,7 +1866,7 @@ usage() { version() { printf "makepkg (pacman) %s\n" "$myver" printf "$(gettext "\ -Copyright (c) 2006-2011 Pacman Development Team .\n\ +Copyright (c) 2006-2012 Pacman Development Team .\n\ Copyright (C) 2002-2006 Judd Vinet .\n\n\ This is free software; see the source for copying conditions.\n\ There is NO WARRANTY, to the extent permitted by law.\n")" diff --git a/scripts/pacman-key.sh.in b/scripts/pacman-key.sh.in index b7c77d82..2159fdf1 100644 --- a/scripts/pacman-key.sh.in +++ b/scripts/pacman-key.sh.in @@ -4,7 +4,7 @@ # Based on apt-key, from Debian # @configure_input@ # -# Copyright (c) 2010-2011 Pacman Development Team +# Copyright (c) 2010-2012 Pacman Development Team # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -88,7 +88,7 @@ usage() { version() { printf "pacman-key (pacman) %s\n" "${myver}" printf "$(gettext "\ -Copyright (c) 2010-2011 Pacman Development Team .\n\ +Copyright (c) 2010-2012 Pacman Development Team .\n\ This is free software; see the source for copying conditions.\n\ There is NO WARRANTY, to the extent permitted by law.\n")" } diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in index 6a10a684..8c1d53da 100644 --- a/scripts/repo-add.sh.in +++ b/scripts/repo-add.sh.in @@ -4,7 +4,7 @@ # repo-remove - remove a package entry from a given repo database file # @configure_input@ # -# Copyright (c) 2006-2011 Pacman Development Team +# Copyright (c) 2006-2012 Pacman Development Team # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -87,7 +87,7 @@ version() { cmd=${0##*/} printf "%s (pacman) %s\n\n" "$cmd" "$myver" printf "$(gettext "\ -Copyright (c) 2006-2011 Pacman Development Team \n\n\ +Copyright (c) 2006-2012 Pacman Development Team \n\n\ This is free software; see the source for copying conditions.\n\ There is NO WARRANTY, to the extent permitted by law.\n")" } diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index bce73d21..4c0d69ed 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -223,7 +223,7 @@ static void version(void) { printf("\n"); printf(" .--. Pacman v%s - libalpm v%s\n", PACKAGE_VERSION, alpm_version()); - printf("/ _.-' .-. .-. .-. Copyright (C) 2006-2011 Pacman Development Team\n"); + printf("/ _.-' .-. .-. .-. Copyright (C) 2006-2012 Pacman Development Team\n"); printf("\\ '-. '-' '-' '-' Copyright (C) 2002-2006 Judd Vinet\n"); printf(" '--'\n"); printf(_(" This program may be freely redistributed under\n" diff --git a/src/pacman/sync.c b/src/pacman/sync.c index 2c64f090..4f10e6b9 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -1,7 +1,7 @@ /* * sync.c * - * Copyright (c) 2006-2011 Pacman Development Team + * Copyright (c) 2006-2012 Pacman Development Team * Copyright (c) 2002-2006 by Judd Vinet * * This program is free software; you can redistribute it and/or modify diff --git a/src/pacman/util.c b/src/pacman/util.c index a8f19682..facdc1c9 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -1,7 +1,7 @@ /* * util.c * - * Copyright (c) 2006-2011 Pacman Development Team + * Copyright (c) 2006-2012 Pacman Development Team * Copyright (c) 2002-2006 by Judd Vinet * * This program is free software; you can redistribute it and/or modify diff --git a/src/pacman/util.h b/src/pacman/util.h index 49cf1dbd..1b5a3daf 100644 --- a/src/pacman/util.h +++ b/src/pacman/util.h @@ -1,7 +1,7 @@ /* * util.h * - * Copyright (c) 2006-2011 Pacman Development Team + * Copyright (c) 2006-2012 Pacman Development Team * Copyright (c) 2002-2006 by Judd Vinet * * This program is free software; you can redistribute it and/or modify -- cgit v1.2.3-24-g4f1b From 1eb40c83287b07ac7428ad2d58504f386fad98f1 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Thu, 19 Jan 2012 16:21:06 -0600 Subject: Add diskspace checking support for Solaris/Illumos Was able to get my hands on one of these boxes today, so add yet another new way of doing this. I'm glad these calls are so standardized. This was compile tested on Linux and Illumos and seems to still be working in both places. Signed-off-by: Dan McGee --- configure.ac | 3 ++- lib/libalpm/diskspace.c | 54 ++++++++++++++++++++++++++++++++++++++++++++----- 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/configure.ac b/configure.ac index 0de908a3..a8b142ea 100644 --- a/configure.ac +++ b/configure.ac @@ -173,7 +173,8 @@ AM_CONDITIONAL([HAVE_LIBGPGME], [test "x$with_gpgme" = "xyes"]) # Checks for header files. AC_CHECK_HEADERS([fcntl.h float.h glob.h libintl.h limits.h locale.h \ - mntent.h stddef.h string.h sys/ioctl.h sys/mount.h \ + mntent.h stddef.h string.h sys/ioctl.h \ + sys/mnttab.h sys/mount.h \ sys/param.h sys/statvfs.h sys/time.h sys/types.h \ sys/ucred.h syslog.h termios.h wchar.h]) diff --git a/lib/libalpm/diskspace.c b/lib/libalpm/diskspace.c index fe2036d5..4127153d 100644 --- a/lib/libalpm/diskspace.c +++ b/lib/libalpm/diskspace.c @@ -1,7 +1,7 @@ /* * diskspace.c * - * Copyright (c) 2010-2011 Pacman Development Team + * Copyright (c) 2010-2012 Pacman Development Team * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,10 +19,15 @@ #include "config.h" +#include #include + #if defined(HAVE_MNTENT_H) #include #endif +#if defined(HAVE_MNTTAB_H) +#include +#endif #if defined(HAVE_SYS_STATVFS_H) #include #endif @@ -60,10 +65,10 @@ static alpm_list_t *mount_point_list(alpm_handle_t *handle) alpm_list_t *mount_points = NULL, *ptr; alpm_mountpoint_t *mp; -#if defined HAVE_GETMNTENT +#if defined(HAVE_GETMNTENT) && defined(HAVE_MNTENT_H) + /* Linux */ struct mntent *mnt; FILE *fp; - struct statvfs fsp; fp = setmntent(MOUNTED, "r"); @@ -72,8 +77,10 @@ static alpm_list_t *mount_point_list(alpm_handle_t *handle) } while((mnt = getmntent(fp))) { + struct statvfs fsp; if(!mnt) { - _alpm_log(handle, ALPM_LOG_WARNING, _("could not get filesystem information\n")); + _alpm_log(handle, ALPM_LOG_WARNING, + _("could not get filesystem information\n")); continue; } if(statvfs(mnt->mnt_dir, &fsp) != 0) { @@ -93,7 +100,44 @@ static alpm_list_t *mount_point_list(alpm_handle_t *handle) } endmntent(fp); -#elif defined HAVE_GETMNTINFO +#elif defined(HAVE_GETMNTENT) && defined(HAVE_MNTTAB_H) + /* Solaris, Illumos */ + struct mnttab mnt; + FILE *fp; + int ret; + + fp = fopen("/etc/mnttab", "r"); + + if(fp == NULL) { + return NULL; + } + + while((ret = getmntent(fp, &mnt)) == 0) { + struct statvfs fsp; + if(statvfs(mnt->mnt_mountp, &fsp) != 0) { + _alpm_log(handle, ALPM_LOG_WARNING, + _("could not get filesystem information for %s: %s\n"), + mnt->mnt_mountp, strerror(errno)); + continue; + } + + CALLOC(mp, 1, sizeof(alpm_mountpoint_t), RET_ERR(handle, ALPM_ERR_MEMORY, NULL)); + mp->mount_dir = strdup(mnt->mnt_mountp); + mp->mount_dir_len = strlen(mp->mount_dir); + memcpy(&(mp->fsp), &fsp, sizeof(struct statvfs)); + mp->read_only = fsp.f_flag & ST_RDONLY; + + mount_points = alpm_list_add(mount_points, mp); + } + /* -1 == EOF */ + if(ret != -1) { + _alpm_log(handle, ALPM_LOG_WARNING, + _("could not get filesystem information\n")); + } + + fclose(fp); +#elif defined(HAVE_GETMNTINFO) + /* FreeBSD (statfs), NetBSD (statvfs), OpenBSD (statfs), OS X (statfs) */ int entries; FSSTATSTYPE *fsp; -- cgit v1.2.3-24-g4f1b From de56874cc9cdbfa96dd6360818ee6f21da3e1c86 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Thu, 19 Jan 2012 16:23:57 -0600 Subject: contrib/bash_completion: don't print stderr messages If you are a crazy developer like me and have bogus options in your pacman.conf file, the tab completion gets messed up by the output on stderr. Suppress it. Fix the same basic issue in zsh_completion, thanks to the work by Florian Pritz . Signed-off-by: Dan McGee --- contrib/bash_completion.in | 4 ++-- contrib/zsh_completion.in | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/contrib/bash_completion.in b/contrib/bash_completion.in index d9e0c785..8983c92b 100644 --- a/contrib/bash_completion.in +++ b/contrib/bash_completion.in @@ -59,9 +59,9 @@ _makepkg() { _pacman_pkg() { _arch_compgen "$( if [[ $2 ]]; then - \pacman -$1 | \cut -d' ' -f1 | \sort -u + \pacman -$1 2>/dev/null | \cut -d' ' -f1 | \sort -u else - \pacman -$1 + \pacman -$1 2>/dev/null fi )" } diff --git a/contrib/zsh_completion.in b/contrib/zsh_completion.in index 59551c58..2cfc946c 100644 --- a/contrib/zsh_completion.in +++ b/contrib/zsh_completion.in @@ -276,7 +276,7 @@ _pacman_completions_repositories() { # $cmd must be declared by calling function _pacman_get_command() { # this is mostly nicked from _perforce - cmd=( "pacman" ) + cmd=( "pacman" "2>/dev/null") integer i for (( i = 2; i < CURRENT - 1; i++ )); do if [[ ${words[i]} = "--config" || ${words[i]} = "--root" ]]; then -- cgit v1.2.3-24-g4f1b From df47136bcfd3fdec150fc8613f3fe243432d875f Mon Sep 17 00:00:00 2001 From: Allan McRae Date: Fri, 20 Jan 2012 23:20:52 +1000 Subject: makepkg: fix error on unnecessary -r The grep statement used to check for a difference between the installed package list before and after resolving dependencies returns 1 if there is no difference. This sets of the error trap when "-r" is used "unnecessarily". Signed-off-by: Allan McRae Signed-off-by: Dan McGee --- scripts/makepkg.sh.in | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 169162ce..81e77e47 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -507,14 +507,15 @@ remove_deps() { # check for packages removed during dependency install (e.g. due to conflicts) # removing all installed packages is risky in this case if [[ -n $(grep -xvFf <(printf '%s\n' "${current_packagelist[@]}") \ - <(printf '%s\n' "${original_packagelist[@]}") ) ]]; then + <(printf '%s\n' "${original_packagelist[@]}") || true) ]]; then warning "$(gettext "Failed to remove installed dependencies.")" return 0 fi local deplist - if ! deplist=($(grep -xvFf <(printf "%s\n" "${original_pkglist[@]}") \ - <(printf "%s\n" "${current_pkglist[@]}"))); then + deplist=($(grep -xvFf <(printf "%s\n" "${original_pkglist[@]}") \ + <(printf "%s\n" "${current_pkglist[@]}") || true)) + if [[ -n deplist ]]; then return fi -- cgit v1.2.3-24-g4f1b From edd4276bbf3d21a7353e3d67ce6639246ef8032d Mon Sep 17 00:00:00 2001 From: Allan McRae Date: Fri, 20 Jan 2012 23:25:57 +1000 Subject: makepkg: restrict usage of flags passed to pacman With pacman-4.0, using --noconfirm or --noprogressbar with -Q or -T results in pacman reporting an "invalid option" error. Restrict the passing of these options to pacman. Fixes FS#28012. Signed-off-by: Allan McRae Signed-off-by: Dan McGee --- scripts/makepkg.sh.in | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 81e77e47..89045ac9 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -412,7 +412,11 @@ download_file() { run_pacman() { local cmd - printf -v cmd "%q " "$PACMAN" $PACMAN_OPTS "$@" + if [[ ! $1 = -@(T|Qq) ]]; then + printf -v cmd "%q " "$PACMAN" $PACMAN_OPTS "$@" + else + printf -v cmd "%q " "$PACMAN" "$@" + fi if (( ! ASROOT )) && [[ ! $1 = -@(T|Qq) ]]; then if type -p sudo >/dev/null; then cmd="sudo $cmd" -- cgit v1.2.3-24-g4f1b From 44f146f232be5203fb01ad35fdf73122838df97c Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sat, 21 Jan 2012 21:31:39 -0500 Subject: lib/dload: enforce usage of TCP keepalives This is particularly important in the case of FTP control connections, which may be closed by rogue NAT/firewall devices detecting idle connections on larger transfers which may take 5-10+ minutes. Signed-off-by: Dave Reisner Signed-off-by: Dan McGee --- configure.ac | 3 ++- lib/libalpm/dload.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index a8b142ea..0bf11e99 100644 --- a/configure.ac +++ b/configure.ac @@ -173,7 +173,8 @@ AM_CONDITIONAL([HAVE_LIBGPGME], [test "x$with_gpgme" = "xyes"]) # Checks for header files. AC_CHECK_HEADERS([fcntl.h float.h glob.h libintl.h limits.h locale.h \ - mntent.h stddef.h string.h sys/ioctl.h \ + mntent.h netinet/in.h netinet/tcp.h \ + stddef.h string.h sys/ioctl.h \ sys/mnttab.h sys/mount.h \ sys/param.h sys/statvfs.h sys/time.h sys/types.h \ sys/ucred.h syslog.h termios.h wchar.h]) diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c index 6fe4a323..f5af7c64 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -25,11 +25,19 @@ #include #include #include +#include /* setsockopt, SO_KEEPALIVE */ #include #include #include #include +#ifdef HAVE_NETINET_IN_H +#include /* IPPROTO_TCP */ +#endif +#ifdef HAVE_NETINET_TCP_H +#include /* TCP_KEEPINTVL, TCP_KEEPIDLE */ +#endif + #ifdef HAVE_LIBCURL #include #endif @@ -217,6 +225,47 @@ static size_t parse_headers(void *ptr, size_t size, size_t nmemb, void *user) return realsize; } +static int dload_sockopt_cb(void *userdata, curl_socket_t curlfd, + curlsocktype purpose) +{ + alpm_handle_t *handle = userdata; + int optval = 1; + + /* this whole method is to prevent FTP control connections from going sour + * during a long data transfer; crappy firewalls love to drop otherwise idle + * connections if there is no traffic. */ + if(purpose != CURLSOCKTYPE_IPCXN) { + return 0; + } + + /* don't abort operation if any setsockopt fails, just log to debug */ + if(setsockopt(curlfd, SOL_SOCKET, SO_KEEPALIVE, (void *)&optval, + sizeof(optval)) < 0) { + _alpm_log(handle, ALPM_LOG_DEBUG, + "Failed to set SO_KEEPALIVE on fd %d\n", curlfd); + } + else { +#ifdef TCP_KEEPIDLE + optval = 60; + if(setsockopt(curlfd, IPPROTO_TCP, TCP_KEEPIDLE, (void *)&optval, + sizeof(optval)) < 0) { + _alpm_log(handle, ALPM_LOG_DEBUG, + "Failed to set TCP_KEEPIDLE on fd %d\n", curlfd); + } +#endif +#ifdef TCP_KEEPINTVL + optval = 60; + if(setsockopt(curlfd, IPPROTO_TCP, TCP_KEEPINTVL, (void *)&optval, + sizeof(optval)) < 0) { + _alpm_log(handle, ALPM_LOG_DEBUG, + "Failed to set TCP_KEEPINTVL on fd %d\n", curlfd); + } +#endif + } + + return 0; +} + static void curl_set_handle_opts(struct dload_payload *payload, CURL *curl, char *error_buffer) { @@ -241,6 +290,8 @@ static void curl_set_handle_opts(struct dload_payload *payload, curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, parse_headers); curl_easy_setopt(curl, CURLOPT_WRITEHEADER, (void *)payload); curl_easy_setopt(curl, CURLOPT_NETRC, CURL_NETRC_OPTIONAL); + curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, dload_sockopt_cb); + curl_easy_setopt(curl, CURLOPT_SOCKOPTDATA, (void *)handle); _alpm_log(handle, ALPM_LOG_DEBUG, "url: %s\n", payload->fileurl); @@ -392,6 +443,8 @@ static int curl_download_internal(struct dload_payload *payload, /* perform transfer */ payload->curlerr = curl_easy_perform(curl); + _alpm_log(handle, ALPM_LOG_DEBUG, "curl returned error %d from transfer\n", + payload->curlerr); /* disconnect relationships from the curl handle for things that might go out * of scope, but could still be touched on connection teardown. This really -- cgit v1.2.3-24-g4f1b From a03c35125ec729b914600b7c24084f83a05a5ede Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Mon, 23 Jan 2012 12:15:53 -0600 Subject: Fix sys/mnttab.h header include Signed-off-by: Dan McGee --- lib/libalpm/diskspace.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/libalpm/diskspace.c b/lib/libalpm/diskspace.c index 4127153d..d0f52a63 100644 --- a/lib/libalpm/diskspace.c +++ b/lib/libalpm/diskspace.c @@ -25,8 +25,8 @@ #if defined(HAVE_MNTENT_H) #include #endif -#if defined(HAVE_MNTTAB_H) -#include +#if defined(HAVE_SYS_MNTTAB_H) +#include #endif #if defined(HAVE_SYS_STATVFS_H) #include -- cgit v1.2.3-24-g4f1b From 825b4ff35aa676b139dc24bc651724b092f2fded Mon Sep 17 00:00:00 2001 From: Dave Reisner Date: Sun, 22 Jan 2012 18:46:23 -0500 Subject: lib/dload: give uniform naming to curl CB functions Signed-off-by: Dave Reisner Signed-off-by: Dan McGee --- lib/libalpm/dload.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c index f5af7c64..414d5d76 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -92,7 +92,7 @@ static void inthandler(int UNUSED signum) dload_interrupted = ABORT_SIGINT; } -static int curl_progress(void *file, double dltotal, double dlnow, +static int dload_progress_cb(void *file, double dltotal, double dlnow, double UNUSED ultotal, double UNUSED ulnow) { struct dload_payload *payload = (struct dload_payload *)file; @@ -194,7 +194,7 @@ static mode_t _getumask(void) return mask; } -static size_t parse_headers(void *ptr, size_t size, size_t nmemb, void *user) +static size_t dload_parseheader_cb(void *ptr, size_t size, size_t nmemb, void *user) { size_t realsize = size * nmemb; const char *fptr, *endptr = NULL; @@ -283,11 +283,11 @@ static void curl_set_handle_opts(struct dload_payload *payload, curl_easy_setopt(curl, CURLOPT_FILETIME, 1L); curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0L); curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L); - curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, curl_progress); + curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, dload_progress_cb); curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, (void *)payload); curl_easy_setopt(curl, CURLOPT_LOW_SPEED_LIMIT, 1024L); curl_easy_setopt(curl, CURLOPT_LOW_SPEED_TIME, 10L); - curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, parse_headers); + curl_easy_setopt(curl, CURLOPT_HEADERFUNCTION, dload_parseheader_cb); curl_easy_setopt(curl, CURLOPT_WRITEHEADER, (void *)payload); curl_easy_setopt(curl, CURLOPT_NETRC, CURL_NETRC_OPTIONAL); curl_easy_setopt(curl, CURLOPT_SOCKOPTFUNCTION, dload_sockopt_cb); -- cgit v1.2.3-24-g4f1b