summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xcontrib/paclist.in85
-rw-r--r--lib/libalpm/handle.c2
-rw-r--r--scripts/pacman-key.sh.in2
-rw-r--r--scripts/repo-add.sh.in6
-rw-r--r--src/pacman/conf.c4
-rw-r--r--src/pacman/query.c17
-rw-r--r--src/pacman/sync.c78
-rw-r--r--src/pacman/util.c11
-rw-r--r--src/util/vercmp.c2
9 files changed, 74 insertions, 133 deletions
diff --git a/contrib/paclist.in b/contrib/paclist.in
index 0379a4c5..84144f78 100755
--- a/contrib/paclist.in
+++ b/contrib/paclist.in
@@ -1,7 +1,8 @@
-#!/usr/bin/perl
+#!/bin/bash
# paclist - List all packages installed from a given repo
#
# Copyright (C) 2008 Dan McGee <dpmcgee@gmail.com>
+# Copyright (C) 2011 Dave Reisner <dreisner@archlinux.org>
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
@@ -16,73 +17,27 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-use strict;
-use warnings;
+export TEXTDOMAIN='pacman'
+export TEXTDOMAINDIR='/usr/share/locale'
-my $progname = "paclist";
-my $version = "1.0";
-
-if ($#ARGV != 0 || $ARGV[0] eq "--help" || $ARGV[0] eq "-h") {
- print "$progname - List all packages installed from a given repo\n";
- print "Usage: $progname <repo>\n";
- print "Example: $progname testing\n";
- if ($#ARGV != 0) {
- exit 1;
+# determine whether we have gettext; make it a no-op if we do not
+if ! type gettext &>/dev/null; then
+ gettext() {
+ echo "$@"
}
- exit 0;
-}
-
-if ( $ARGV[0] eq "--version" || $ARGV[0] eq "-v") {
- print "$progname version $version\n";
- print "Copyright (C) 2008 Dan McGee\n";
- exit 0;
-}
-
-# This hash table will be used to store pairs of ('name version', count) from
-# the return of both pacman -Sl <repo> and pacman -Q output. We then check to
-# see if a value was added twice (count = 2)- if so, we will print that package
-# as it is both in the repo we queried and installed on our local system.
-my %packages = ();
-my $output;
+fi
-$output = `pacman -Sl $ARGV[0]`;
-if ($? != 0) {
- exit 1;
-}
-my @sync = split(/\n/, $output);
-# sample output from pacman -Sl:
-# testing foobar 1.0-1
-foreach $_ (@sync) {
- my @info = split(/ /);
- # we only want to store 'foobar 1.0-1' in our hash table
- my $pkg = $info[1] . " " . $info[2];
- $packages{$pkg}++;
-}
+if [[ -z $1 ]]; then
+ printf '%s - List all packages installed from a given repo\n' "${0##*/}"
+ printf 'Usage: %s <repo>\n' "${0##*/}"
+ printf 'Example: %s testing\n' "${0##*/}"
+ exit 1
+fi
-$output = `pacman -Q`;
-if ($? != 0) {
- exit 1;
-}
-# sample output from pacman -Q:
-# foobar 1.0-1
-my @local = split(/\n/, $output);
-foreach $_ (@local) {
- # store 'foobar 1.0-1' in our hash table
- $packages{$_}++;
-}
-
-# run comparison check- if value was added twice, it was in the intersection
-my @intersection;
-foreach $_ (keys %packages) {
- if ($packages{$_} == 2) {
- push @{ \@intersection }, $_;
- }
-}
+printf -v installed '[%s]' "$(gettext installed)"
+pacman -Sl $1 | awk -v i="$installed" '$NF == i { print $2,$3 }'
-# print our intersection, and bask in the glory and speed of perl
-@intersection = sort @intersection;
-foreach $_ (@intersection) {
- print $_ . "\n";
-}
+# exit with pacman's return value, not awk's
+exit ${PIPESTATUS[0]}
-#vim: set noet:
+# vim: set ts=2 sw=2 noet:
diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c
index ddd76a25..9bffd4fd 100644
--- a/lib/libalpm/handle.c
+++ b/lib/libalpm/handle.c
@@ -299,7 +299,7 @@ static char *canonicalize_path(const char *path) {
len += 1;
}
CALLOC(new_path, len + 1, sizeof(char), return NULL);
- strncpy(new_path, path, len);
+ strcpy(new_path, path);
new_path[len - 1] = '/';
return new_path;
}
diff --git a/scripts/pacman-key.sh.in b/scripts/pacman-key.sh.in
index 877cca29..833943cb 100644
--- a/scripts/pacman-key.sh.in
+++ b/scripts/pacman-key.sh.in
@@ -33,7 +33,7 @@ usage() {
echo
printf "$(gettext "Usage: %s [options] <command> [arguments]")\n" $(basename $0)
echo
- echo "$(gettext "Manage pacman's list of trusted keys")"
+ printf "$(gettext "Manage pacman\'s list of trusted keys")\n"
echo
echo "$(gettext "Options must be placed before commands. The available options are:")"
printf "$(gettext " --config <file> Use an alternate config file (instead of '%s')")\n" "$CONFIG"
diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in
index 415ad41f..474e21d9 100644
--- a/scripts/repo-add.sh.in
+++ b/scripts/repo-add.sh.in
@@ -642,7 +642,11 @@ if (( success )); then
create_signature "$tmpdir/$filename"
[[ -f $REPO_DB_FILE ]] && mv -f "$REPO_DB_FILE" "${REPO_DB_FILE}.old"
- [[ -f $REPO_DB_FILE.sig ]] && rm -f "$REPO_DB_FILE.sig"
+ if [[ -f $REPO_DB_FILE.sig ]]; then
+ mv -f "$REPO_DB_FILE.sig" "$REPO_DB_FILE.old.sig"
+ else
+ rm -f "$REPO_DB_FILE.old.sig"
+ fi
[[ -f $tmpdir/$filename ]] && mv "$tmpdir/$filename" "$REPO_DB_FILE"
[[ -f $tmpdir/$filename.sig ]] && mv "$tmpdir/$filename.sig" "$REPO_DB_FILE.sig"
dblink="${REPO_DB_FILE%.tar*}"
diff --git a/src/pacman/conf.c b/src/pacman/conf.c
index 3af3fa5b..fac6da34 100644
--- a/src/pacman/conf.c
+++ b/src/pacman/conf.c
@@ -750,7 +750,9 @@ static int _parseconfig(const char *file, struct section_t *section,
}
cleanup:
- fclose(fp);
+ if (fp) {
+ fclose(fp);
+ }
pm_printf(ALPM_LOG_DEBUG, "config: finished parsing %s\n", file);
return ret;
}
diff --git a/src/pacman/query.c b/src/pacman/query.c
index 90329b33..251c4dd6 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -110,8 +110,7 @@ static int query_fileowner(alpm_list_t *targets)
int ret = 0;
char path[PATH_MAX];
const char *root;
- char *append;
- size_t max_length;
+ size_t rootlen;
alpm_list_t *t;
alpm_db_t *db_local;
@@ -125,9 +124,13 @@ static int query_fileowner(alpm_list_t *targets)
* once, then we can just overwrite whatever file was there on the previous
* iteration. */
root = alpm_option_get_root(config->handle);
- strncpy(path, root, PATH_MAX - 1);
- append = path + strlen(path);
- max_length = PATH_MAX - (append - path) - 1;
+ rootlen = strlen(root);
+ if(rootlen + 1 > PATH_MAX) {
+ /* we are in trouble here */
+ pm_fprintf(stderr, ALPM_LOG_ERROR, _("path too long: %s%s\n"), root, "");
+ return 1;
+ }
+ strcpy(path, root);
db_local = alpm_option_get_localdb(config->handle);
@@ -208,11 +211,11 @@ static int query_fileowner(alpm_list_t *targets)
continue;
}
- if(strlen(pkgfile) > max_length) {
+ if(rootlen + 1 + strlen(pkgfile) > PATH_MAX) {
pm_fprintf(stderr, ALPM_LOG_ERROR, _("path too long: %s%s\n"), root, pkgfile);
}
/* concatenate our file and the root path */
- strcpy(append, pkgfile);
+ strcpy(path + rootlen, pkgfile);
pdname = mdirname(path);
ppath = resolve_path(pdname);
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index 26c9ccca..5e1643e4 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -443,32 +443,27 @@ static int sync_info(alpm_list_t *syncs, alpm_list_t *targets)
if(targets) {
for(i = targets; i; i = alpm_list_next(i)) {
- int foundpkg = 0;
+ const char *target = alpm_list_getdata(i);
+ char *name = strdup(target);
+ char *repo, *pkgstr;
+ int foundpkg = 0, founddb = 0;
- char target[512]; /* TODO is this enough space? */
- char *repo = NULL, *pkgstr = NULL;
-
- strncpy(target, i->data, 512);
- pkgstr = strchr(target, '/');
+ pkgstr = strchr(name, '/');
if(pkgstr) {
- alpm_db_t *db = NULL;
- repo = target;
+ repo = name;
*pkgstr = '\0';
++pkgstr;
+ } else {
+ repo = NULL;
+ pkgstr = name;
+ }
- for(j = syncs; j; j = alpm_list_next(j)) {
- db = alpm_list_getdata(j);
- if(strcmp(repo, alpm_db_get_name(db)) == 0) {
- break;
- }
- db = NULL;
- }
-
- if(!db) {
- pm_fprintf(stderr, ALPM_LOG_ERROR,
- _("repository '%s' does not exist\n"), repo);
- return 1;
+ for(j = syncs; j; j = alpm_list_next(j)) {
+ alpm_db_t *db = alpm_list_getdata(j);
+ if(repo && strcmp(repo, alpm_db_get_name(db)) != 0) {
+ continue;
}
+ founddb = 1;
for(k = alpm_db_get_pkgcache(db); k; k = alpm_list_next(k)) {
alpm_pkg_t *pkg = alpm_list_getdata(k);
@@ -479,34 +474,19 @@ static int sync_info(alpm_list_t *syncs, alpm_list_t *targets)
break;
}
}
+ }
- if(!foundpkg) {
- pm_fprintf(stderr, ALPM_LOG_ERROR,
- _("package '%s' was not found in repository '%s'\n"), pkgstr, repo);
- ret++;
- }
- } else {
- pkgstr = target;
-
- for(j = syncs; j; j = alpm_list_next(j)) {
- alpm_db_t *db = alpm_list_getdata(j);
-
- for(k = alpm_db_get_pkgcache(db); k; k = alpm_list_next(k)) {
- alpm_pkg_t *pkg = alpm_list_getdata(k);
-
- if(strcmp(alpm_pkg_get_name(pkg), pkgstr) == 0) {
- dump_pkg_full(pkg, PKG_FROM_SYNCDB, config->op_s_info > 1);
- foundpkg = 1;
- break;
- }
- }
- }
- if(!foundpkg) {
- pm_fprintf(stderr, ALPM_LOG_ERROR,
- _("package '%s' was not found\n"), pkgstr);
- ret++;
- }
+ if(!founddb) {
+ pm_fprintf(stderr, ALPM_LOG_ERROR,
+ _("repository '%s' does not exist\n"), repo);
+ ret++;
+ }
+ if(!foundpkg) {
+ pm_fprintf(stderr, ALPM_LOG_ERROR,
+ _("package '%s' was not found\n"), target);
+ ret++;
}
+ free(name);
}
} else {
for(i = syncs; i; i = alpm_list_next(i)) {
@@ -630,7 +610,7 @@ static int process_pkg(alpm_pkg_t *pkg)
return 0;
}
-static int process_group(alpm_list_t *dbs, char *group)
+static int process_group(alpm_list_t *dbs, const char *group)
{
int ret = 0;
alpm_list_t *i;
@@ -676,7 +656,7 @@ cleanup:
return ret;
}
-static int process_targname(alpm_list_t *dblist, char *targname)
+static int process_targname(alpm_list_t *dblist, const char *targname)
{
alpm_pkg_t *pkg = alpm_find_dbs_satisfier(config->handle, dblist, targname);
@@ -695,7 +675,7 @@ static int process_targname(alpm_list_t *dblist, char *targname)
return process_group(dblist, targname);
}
-static int process_target(char *target)
+static int process_target(const char *target)
{
/* process targets */
char *targstring = strdup(target);
diff --git a/src/pacman/util.c b/src/pacman/util.c
index deb3e056..7065abdc 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -389,22 +389,21 @@ char *strreplace(const char *str, const char *needle, const char *replace)
* x "size difference between replace and needle" */
newsz = strlen(str) + 1 +
alpm_list_count(list) * (replacesz - needlesz);
- newstr = malloc(newsz);
+ newstr = calloc(newsz, sizeof(char));
if(!newstr) {
return NULL;
}
- *newstr = '\0';
p = str;
newp = newstr;
for(i = list; i; i = alpm_list_next(i)) {
q = alpm_list_getdata(i);
- if(q > p){
+ if(q > p) {
/* add chars between this occurence and last occurence, if any */
- strncpy(newp, p, (size_t)(q - p));
+ memcpy(newp, p, (size_t)(q - p));
newp += q - p;
}
- strncpy(newp, replace, replacesz);
+ memcpy(newp, replace, replacesz);
newp += replacesz;
p = q + needlesz;
}
@@ -413,9 +412,7 @@ char *strreplace(const char *str, const char *needle, const char *replace)
if(*p) {
/* add the rest of 'p' */
strcpy(newp, p);
- newp += strlen(p);
}
- *newp = '\0';
return newstr;
}
diff --git a/src/util/vercmp.c b/src/util/vercmp.c
index 88cf49a6..f4356fb4 100644
--- a/src/util/vercmp.c
+++ b/src/util/vercmp.c
@@ -20,7 +20,7 @@
#include <stdlib.h>
#include <stdio.h> /* printf */
-#include <string.h> /* strncpy */
+#include <string.h>
#define BASENAME "vercmp"