summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.am4
-rw-r--r--NEWS3
-rw-r--r--README15
-rw-r--r--contrib/README2
-rw-r--r--contrib/checkupdates.sh.in10
-rw-r--r--contrib/pacdiff.sh.in4
-rw-r--r--doc/pacman.8.txt34
-rw-r--r--lib/libalpm/add.c413
-rw-r--r--lib/libalpm/alpm.h24
-rw-r--r--lib/libalpm/backup.c7
-rw-r--r--lib/libalpm/be_local.c19
-rw-r--r--lib/libalpm/be_package.c5
-rw-r--r--lib/libalpm/be_sync.c4
-rw-r--r--lib/libalpm/conflict.c21
-rw-r--r--lib/libalpm/db.c11
-rw-r--r--lib/libalpm/delta.c24
-rw-r--r--lib/libalpm/deps.c36
-rw-r--r--lib/libalpm/diskspace.c6
-rw-r--r--lib/libalpm/dload.c2
-rw-r--r--lib/libalpm/package.c11
-rw-r--r--lib/libalpm/package.h2
-rw-r--r--lib/libalpm/sync.c6
-rw-r--r--lib/libalpm/trans.c2
-rw-r--r--lib/libalpm/util.c4
-rwxr-xr-xscripts/makepkg-template.pl.in4
-rw-r--r--scripts/makepkg.sh.in11
-rw-r--r--scripts/pkgdelta.sh.in2
-rw-r--r--src/pacman/callback.c20
-rw-r--r--src/pacman/conf.c307
-rw-r--r--src/pacman/conf.h16
-rw-r--r--src/pacman/database.c218
-rw-r--r--src/pacman/ini.c147
-rw-r--r--src/pacman/pacman.c23
-rw-r--r--src/pacman/util.c3
-rw-r--r--src/util/.gitignore2
-rw-r--r--src/util/Makefile.am5
-rw-r--r--src/util/pacsort.c1
-rw-r--r--src/util/testdb.c297
-rw-r--r--test/pacman/README1
-rw-r--r--test/pacman/pmrule.py3
-rw-r--r--test/pacman/tests/upgrade015.py1
-rw-r--r--test/pacman/tests/upgrade016.py5
-rw-r--r--test/pacman/tests/upgrade027.py1
-rw-r--r--test/pacman/tests/upgrade028.py1
-rw-r--r--test/pacman/tests/upgrade029.py1
-rw-r--r--test/scripts/Makefile.am1
-rwxr-xr-xtest/scripts/human_to_size_test.sh73
-rw-r--r--test/scripts/makepkg-template-tests/invalid-key/PKGBUILD1
-rw-r--r--test/scripts/makepkg-template-tests/invalid-key/testcase-config11
-rw-r--r--test/scripts/makepkg-template-tests/invalid-template-line-missing-name/PKGBUILD1
-rw-r--r--test/scripts/makepkg-template-tests/invalid-template-line-missing-name/testcase-config11
-rw-r--r--test/scripts/makepkg-template-tests/invalid-template-line-unknown-marker/PKGBUILD9
-rw-r--r--test/scripts/makepkg-template-tests/invalid-template-line-unknown-marker/testcase-config11
-rw-r--r--test/scripts/makepkg-template-tests/keep-old-version/PKGBUILD15
-rw-r--r--test/scripts/makepkg-template-tests/keep-old-version/templates/perl-bla-1.2.template1
-rw-r--r--test/scripts/makepkg-template-tests/keep-old-version/templates/perl-module-1.0.template6
-rw-r--r--test/scripts/makepkg-template-tests/keep-old-version/templates/perl-module-1.1.template7
-rw-r--r--test/scripts/makepkg-template-tests/keep-old-version/testcase-config29
-rw-r--r--test/scripts/makepkg-template-tests/missing-template-file/PKGBUILD7
-rw-r--r--test/scripts/makepkg-template-tests/missing-template-file/testcase-config14
-rw-r--r--test/scripts/makepkg-template-tests/missing-template-symlink/PKGBUILD7
-rw-r--r--test/scripts/makepkg-template-tests/missing-template-symlink/templates/perl-module-1.0.template1
-rw-r--r--test/scripts/makepkg-template-tests/missing-template-symlink/testcase-config9
-rw-r--r--test/scripts/makepkg-template-tests/name-charset-invalid/PKGBUILD8
-rw-r--r--test/scripts/makepkg-template-tests/name-charset-invalid/testcase-config10
-rw-r--r--test/scripts/makepkg-template-tests/name-charset-valid/PKGBUILD8
-rw-r--r--test/scripts/makepkg-template-tests/name-charset-valid/templates/foo@-_.+a-1.template1
-rw-r--r--test/scripts/makepkg-template-tests/name-charset-valid/testcase-config19
-rw-r--r--test/scripts/makepkg-template-tests/template-without-version/PKGBUILD8
-rw-r--r--test/scripts/makepkg-template-tests/template-without-version/templates/template-without_version.template0
-rw-r--r--test/scripts/makepkg-template-tests/template-without-version/testcase-config9
-rw-r--r--test/scripts/makepkg-template-tests/testcase-config-template9
-rw-r--r--test/scripts/makepkg-template-tests/update-version-with-newest-option/PKGBUILD7
-rw-r--r--test/scripts/makepkg-template-tests/update-version-with-newest-option/templates/perl-bla-1.2.template1
-rw-r--r--test/scripts/makepkg-template-tests/update-version-with-newest-option/templates/perl-module-1.0.template6
-rw-r--r--test/scripts/makepkg-template-tests/update-version-with-newest-option/templates/perl-module-1.1.template7
-rw-r--r--test/scripts/makepkg-template-tests/update-version-with-newest-option/testcase-config29
-rwxr-xr-xtest/scripts/makepkg-template_test.sh67
-rwxr-xr-xtest/scripts/parseopts_test.sh102
-rw-r--r--test/tap.sh163
-rwxr-xr-xtest/util/pacsorttest.sh90
-rwxr-xr-xtest/util/vercmptest.sh151
82 files changed, 1451 insertions, 1196 deletions
diff --git a/Makefile.am b/Makefile.am
index e9b3dfa1..d2a11ebd 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -13,7 +13,7 @@ DISTCHECK_CONFIGURE_FLAGS = --enable-doc --disable-git-version
# Some files automatically included, so they aren't specified below:
# AUTHORS, COPYING, NEWS, README
-EXTRA_DIST = HACKING
+EXTRA_DIST = HACKING test/tap.sh
# Sample makepkg prototype files
pkgdatadir = ${datadir}/${PACKAGE}
@@ -28,6 +28,7 @@ $(top_srcdir)/test/pacman/tests/TESTS: $(wildcard test/pacman/tests/*.py*)
TESTS = test/scripts/parseopts_test.sh \
test/scripts/human_to_size_test.sh \
+ test/scripts/makepkg-template_test.sh \
test/scripts/pacman-db-upgrade-v9.py \
test/util/pacsorttest.sh \
test/util/vercmptest.sh
@@ -37,6 +38,7 @@ TEST_SUITE_LOG = test/test-suite.log
TEST_EXTENSIONS = .py
AM_TESTS_ENVIRONMENT = \
PMTEST_UTIL_DIR=$(top_builddir)/src/util/; export PMTEST_UTIL_DIR; \
+ PMTEST_SCRIPT_DIR=$(top_builddir)/scripts/; export PMTEST_SCRIPT_DIR; \
PMTEST_SCRIPTLIB_DIR=$(top_srcdir)/scripts/library/; export PMTEST_SCRIPTLIB_DIR;
LOG_DRIVER = env AM_TAP_AWK='$(AWK)' $(SHELL) \
$(top_srcdir)/build-aux/tap-driver.sh
diff --git a/NEWS b/NEWS
index f4e6bf30..483badc1 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,8 @@
VERSION DESCRIPTION
-----------------------------------------------------------------------------
+5.0.0 - pacman can check the validity of the local and sync databases
+ (-Dk and -Dkk respectively). This replaces the 'testdb'
+ software
4.2.0 - symlinks to directories on the filesystem are no longer
treated as directories
- pacman-db-upgrade - fix local database for files installed
diff --git a/README b/README
index eddd3416..8c17d335 100644
--- a/README
+++ b/README
@@ -560,3 +560,18 @@ API CHANGES BETWEEN 4.1 AND 4.2
- ALPM_EVENT_RETRIEVE_DONE, ALPM_EVENT_RETRIEVE_FAILED, ALPM_EVENT_PKGDOWNLOAD_START,
ALPM_EVENT_PKGDOWNLOAD_DONE, ALPM_EVENT_PKGDOWNLOAD_FAILED, ALPM_EVENT_OPTDEP_REMOVAL,
ALPM_EVENT_PACNEW_CREATED, ALPM_EVENT_PACSVAE_CREATED, ALPM_EVENT_PACORIG_CREATED
+
+
+API CHANGES BETWEEN 4.2 AND 5.0
+===============================
+
+[REMOVED]
+- alpm_siglevel_t - removed members ALPM_SIG_PACKAGE_SET, ALPM_SIG_PACKAGE_TRUST_SET
+
+- ALPM_EVENT_PACORIG_CREATED
+- alpm_event_pacorig_created_t
+- alpm_event_t.pacorig_created
+
+[ADDED]
+- pkgbase accessor
+ - alpm_pkg_get_base()
diff --git a/contrib/README b/contrib/README
index bcb4b853..befd3c1d 100644
--- a/contrib/README
+++ b/contrib/README
@@ -16,7 +16,7 @@ sync databases (for safety on rolling release distributions).
paccache - a flexible package cache cleaning utility that allows greater
control over which packages are removed.
-pacdiff - a simple pacnew/pacorig/pacsave updater for /etc/.
+pacdiff - a simple pacnew/pacsave updater for /etc/.
paclist - list all packages installed from a given repository. Useful for
seeing which packages you may have installed from the testing repository,
diff --git a/contrib/checkupdates.sh.in b/contrib/checkupdates.sh.in
index f4f36c09..e8a81986 100644
--- a/contrib/checkupdates.sh.in
+++ b/contrib/checkupdates.sh.in
@@ -21,6 +21,9 @@
declare -r myname='checkupdates'
declare -r myver='@PACKAGE_VERSION@'
+m4_include(../scripts/library/output_format.sh)
+m4_include(../scripts/library/term_colors.sh)
+
if (( $# > 0 )); then
echo "${myname} (pacman) v${myver}"
echo
@@ -32,6 +35,11 @@ if (( $# > 0 )); then
exit 0
fi
+if ! type -P fakeroot >/dev/null; then
+ error 'Cannot find the fakeroot binary.'
+ exit 1
+fi
+
if [[ -z $CHECKUPDATES_DB ]]; then
CHECKUPDATES_DB="${TMPDIR:-/tmp}/checkup-db-${USER}/"
fi
@@ -44,7 +52,7 @@ eval $(awk -F' *= *' '$1 ~ /DBPath/ { print $1 "=" $2 }' @sysconfdir@/pacman.con
mkdir -p "$CHECKUPDATES_DB"
ln -s "${DBPath}/local" "$CHECKUPDATES_DB" &> /dev/null
fakeroot pacman -Sy --dbpath "$CHECKUPDATES_DB" --logfile /dev/null &> /dev/null
-pacman -Qqu --dbpath "$CHECKUPDATES_DB" 2> /dev/null | grep -v '\[.*\]'
+pacman -Qu --dbpath "$CHECKUPDATES_DB" 2> /dev/null | grep -v '\[.*\]'
exit 0
diff --git a/contrib/pacdiff.sh.in b/contrib/pacdiff.sh.in
index ecb6ae29..3f0a3c69 100644
--- a/contrib/pacdiff.sh.in
+++ b/contrib/pacdiff.sh.in
@@ -1,5 +1,5 @@
#!/bin/bash
-# pacdiff : a simple pacnew/pacorig/pacsave updater
+# pacdiff : a simple pacnew/pacsave updater
#
# Copyright (c) 2007 Aaron Griffin <aaronmgriffin@gmail.com>
# Copyright (c) 2013-2014 Pacman Development Team <pacman-dev@archlinux.org>
@@ -35,7 +35,7 @@ usage() {
cat <<EOF
${myname} (pacman) v${myver}
-A simple program to merge or remove pacnew/pacorig/pacsave files.
+A simple program to merge or remove pacnew/pacsave files.
Usage: $myname [-l | -f | -p] [--nocolor]
diff --git a/doc/pacman.8.txt b/doc/pacman.8.txt
index 74436155..5c57450b 100644
--- a/doc/pacman.8.txt
+++ b/doc/pacman.8.txt
@@ -35,10 +35,10 @@ as an argument, targets will be read from stdin.
Operations
----------
*-D, \--database*::
- Modify the package database. This operation allows you to modify certain
- attributes of the installed packages in pacman's database. At the
- moment, you can only change the install reason using '\--asdeps' and
- '\--asexplicit' options.
+ Operate on the package database. This operation allows you to modify
+ certain attributes of the installed packages in pacman's database. It
+ also allows you to check the databases for internal consistency.
+ See <<DO,Database Options>> below.
*-Q, \--query*::
Query the package database. This operation allows you to view installed
@@ -431,6 +431,27 @@ system upgrade and install/upgrade the "foo" package in the same operation.
to-date.
+Database Options[[QO]]
+----------------------
+*\--asdeps* <package>::
+ Mark a package as non-explicitly installed; in other words, set their install
+ reason to be installed as a dependency.
+
+*\--asexplicit<package>*::
+ Mark a package as explicitly installed; in other words, set their install
+ reason to be explicitly installed. This is useful it you want to keep a
+ package installed even when it was initially installed as a dependency
+ of another package.
+
+*-k \--check*::
+ Check the local package database is internally consistent. This will
+ check all required files are present and that installed packages have
+ the required dependencies, do not conflict and that multiple packages
+ do not own the same file. Specifying this option twice will perform
+ a check on the sync databases to ensure all specified dependencies
+ are available.
+
+
Handling Config Files[[HCF]]
----------------------------
Pacman uses the same logic as 'rpm' to determine action against files that are
@@ -463,8 +484,9 @@ original=X, current=Y, new=Z::
original=NULL, current=Y, new=Z::
The package was not previously installed, and the file already exists on the
- file system. Save the current file with a '.pacorig' extension, install the
- new file, and warn the user.
+ file system. Install the new file with a '.pacnew' extension and warn the
+ user. The user must then manually merge any necessary changes into the
+ original file.
Examples
diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
index 725f2b5c..b1245693 100644
--- a/lib/libalpm/add.c
+++ b/lib/libalpm/add.c
@@ -107,7 +107,7 @@ int SYMEXPORT alpm_add_pkg(alpm_handle_t *handle, alpm_pkg_t *pkg)
}
static int perform_extraction(alpm_handle_t *handle, struct archive *archive,
- struct archive_entry *entry, const char *filename, const char *origname)
+ struct archive_entry *entry, const char *filename)
{
int ret;
const int archive_flags = ARCHIVE_EXTRACT_OWNER |
@@ -120,13 +120,13 @@ static int perform_extraction(alpm_handle_t *handle, struct archive *archive,
if(ret == ARCHIVE_WARN && archive_errno(archive) != ENOSPC) {
/* operation succeeded but a "non-critical" error was encountered */
_alpm_log(handle, ALPM_LOG_WARNING, _("warning given when extracting %s (%s)\n"),
- origname, archive_error_string(archive));
+ filename, archive_error_string(archive));
} else if(ret != ARCHIVE_OK) {
_alpm_log(handle, ALPM_LOG_ERROR, _("could not extract %s (%s)\n"),
- origname, archive_error_string(archive));
+ filename, archive_error_string(archive));
alpm_logaction(handle, ALPM_CALLER_PREFIX,
"error: could not extract %s (%s)\n",
- origname, archive_error_string(archive));
+ filename, archive_error_string(archive));
return 1;
}
return 0;
@@ -144,49 +144,59 @@ static int try_rename(alpm_handle_t *handle, const char *src, const char *dest)
return 0;
}
+static int extract_db_file(alpm_handle_t *handle, struct archive *archive,
+ struct archive_entry *entry, alpm_pkg_t *newpkg, const char *entryname)
+{
+ char filename[PATH_MAX]; /* the actual file we're extracting */
+ const char *dbfile;
+ if(strcmp(entryname, ".INSTALL") == 0) {
+ dbfile = "install";
+ } else if(strcmp(entryname, ".CHANGELOG") == 0) {
+ dbfile = "changelog";
+ } else if(strcmp(entryname, ".MTREE") == 0) {
+ dbfile = "mtree";
+ } else if(*entryname == '.') {
+ /* reserve all files starting with '.' for future possibilities */
+ _alpm_log(handle, ALPM_LOG_DEBUG, "skipping extraction of '%s'\n", entryname);
+ archive_read_data_skip(archive);
+ return 0;
+ }
+ archive_entry_set_perm(entry, 0644);
+ snprintf(filename, PATH_MAX, "%s%s-%s/%s",
+ _alpm_db_path(handle->db_local), newpkg->name, newpkg->version, dbfile);
+ return perform_extraction(handle, archive, entry, filename);
+}
+
static int extract_single_file(alpm_handle_t *handle, struct archive *archive,
struct archive_entry *entry, alpm_pkg_t *newpkg, alpm_pkg_t *oldpkg)
{
- const char *entryname;
- mode_t entrymode;
+ const char *entryname = archive_entry_pathname(entry);
+ mode_t entrymode = archive_entry_mode(entry);
+ alpm_backup_t *backup = _alpm_needbackup(entryname, newpkg);
char filename[PATH_MAX]; /* the actual file we're extracting */
int needbackup = 0, notouch = 0;
const char *hash_orig = NULL;
- char *entryname_orig = NULL;
int errors = 0;
+ struct stat lsbuf;
+ size_t filename_len;
- entryname = archive_entry_pathname(entry);
- entrymode = archive_entry_mode(entry);
+ if(*entryname == '.') {
+ return extract_db_file(handle, archive, entry, newpkg, entryname);
+ }
- if(strcmp(entryname, ".INSTALL") == 0) {
- /* the install script goes inside the db */
- snprintf(filename, PATH_MAX, "%s%s-%s/install",
- _alpm_db_path(handle->db_local), newpkg->name, newpkg->version);
- archive_entry_set_perm(entry, 0644);
- } else if(strcmp(entryname, ".CHANGELOG") == 0) {
- /* the changelog goes inside the db */
- snprintf(filename, PATH_MAX, "%s%s-%s/changelog",
- _alpm_db_path(handle->db_local), newpkg->name, newpkg->version);
- archive_entry_set_perm(entry, 0644);
- } else if(strcmp(entryname, ".MTREE") == 0) {
- /* the mtree file goes inside the db */
- snprintf(filename, PATH_MAX, "%s%s-%s/mtree",
- _alpm_db_path(handle->db_local), newpkg->name, newpkg->version);
- archive_entry_set_perm(entry, 0644);
- } else if(*entryname == '.') {
- /* for now, ignore all files starting with '.' that haven't
- * already been handled (for future possibilities) */
- _alpm_log(handle, ALPM_LOG_DEBUG, "skipping extraction of '%s'\n", entryname);
- archive_read_data_skip(archive);
+ if (!alpm_filelist_contains(&newpkg->files, entryname)) {
+ _alpm_log(handle, ALPM_LOG_WARNING,
+ _("file not found in file list for package %s. skipping extraction of %s\n"),
+ newpkg->name, entryname);
return 0;
- } else {
- if (!alpm_filelist_contains(&newpkg->files, entryname)) {
- _alpm_log(handle, ALPM_LOG_WARNING, _("file not found in file list for package %s. skipping extraction of %s\n"),
- newpkg->name, entryname);
- return 0;
- }
- /* build the new entryname relative to handle->root */
- snprintf(filename, PATH_MAX, "%s%s", handle->root, entryname);
+ }
+
+ /* build the new entryname relative to handle->root */
+ filename_len = snprintf(filename, PATH_MAX, "%s%s", handle->root, entryname);
+ if(filename_len >= PATH_MAX) {
+ _alpm_log(handle, ALPM_LOG_ERROR,
+ _("unable to extract %s%s: path too long"), handle->root, entryname);
+ return 1;
}
/* if a file is in NoExtract then we never extract it */
@@ -214,115 +224,116 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive,
* 6- skip extraction, dir already exists.
*/
- struct stat lsbuf;
if(llstat(filename, &lsbuf) != 0) {
/* cases 1,2: file doesn't exist, skip all backup checks */
- } else {
- if(S_ISDIR(lsbuf.st_mode)) {
- if(S_ISDIR(entrymode)) {
- uid_t entryuid = archive_entry_uid(entry);
- gid_t entrygid = archive_entry_gid(entry);
-
- /* case 6: existing dir, ignore it */
- if(lsbuf.st_mode != entrymode) {
- /* if filesystem perms are different than pkg perms, warn user */
- mode_t mask = 07777;
- _alpm_log(handle, ALPM_LOG_WARNING, _("directory permissions differ on %s\n"
- "filesystem: %o package: %o\n"), filename, lsbuf.st_mode & mask,
- entrymode & mask);
- alpm_logaction(handle, ALPM_CALLER_PREFIX,
- "warning: directory permissions differ on %s\n"
- "filesystem: %o package: %o\n", filename, lsbuf.st_mode & mask,
- entrymode & mask);
- }
+ } else if(S_ISDIR(lsbuf.st_mode) && S_ISDIR(entrymode)) {
+ uid_t entryuid = archive_entry_uid(entry);
+ gid_t entrygid = archive_entry_gid(entry);
+
+ /* case 6: existing dir, ignore it */
+ if(lsbuf.st_mode != entrymode) {
+ /* if filesystem perms are different than pkg perms, warn user */
+ mode_t mask = 07777;
+ _alpm_log(handle, ALPM_LOG_WARNING, _("directory permissions differ on %s\n"
+ "filesystem: %o package: %o\n"), filename, lsbuf.st_mode & mask,
+ entrymode & mask);
+ alpm_logaction(handle, ALPM_CALLER_PREFIX,
+ "warning: directory permissions differ on %s\n"
+ "filesystem: %o package: %o\n", filename, lsbuf.st_mode & mask,
+ entrymode & mask);
+ }
- if((entryuid != lsbuf.st_uid) || (entrygid != lsbuf.st_gid)) {
- _alpm_log(handle, ALPM_LOG_WARNING, _("directory ownership differs on %s\n"
- "filesystem: %u:%u package: %u:%u\n"), filename,
- lsbuf.st_uid, lsbuf.st_gid, entryuid, entrygid);
- alpm_logaction(handle, ALPM_CALLER_PREFIX,
- "warning: directory ownership differs on %s\n"
- "filesystem: %u:%u package: %u:%u\n", filename,
- lsbuf.st_uid, lsbuf.st_gid, entryuid, entrygid);
- }
+ if((entryuid != lsbuf.st_uid) || (entrygid != lsbuf.st_gid)) {
+ _alpm_log(handle, ALPM_LOG_WARNING, _("directory ownership differs on %s\n"
+ "filesystem: %u:%u package: %u:%u\n"), filename,
+ lsbuf.st_uid, lsbuf.st_gid, entryuid, entrygid);
+ alpm_logaction(handle, ALPM_CALLER_PREFIX,
+ "warning: directory ownership differs on %s\n"
+ "filesystem: %u:%u package: %u:%u\n", filename,
+ lsbuf.st_uid, lsbuf.st_gid, entryuid, entrygid);
+ }
- _alpm_log(handle, ALPM_LOG_DEBUG, "extract: skipping dir extraction of %s\n",
- filename);
- archive_read_data_skip(archive);
- return 0;
- } else {
- /* case 5: trying to overwrite dir with file, don't allow it */
- _alpm_log(handle, ALPM_LOG_ERROR, _("extract: not overwriting dir with file %s\n"),
- filename);
- archive_read_data_skip(archive);
- return 1;
- }
- } else if(S_ISDIR(entrymode)) {
- /* case 4: trying to overwrite file with dir */
- _alpm_log(handle, ALPM_LOG_DEBUG, "extract: overwriting file with dir %s\n",
- filename);
+ _alpm_log(handle, ALPM_LOG_DEBUG, "extract: skipping dir extraction of %s\n",
+ filename);
+ archive_read_data_skip(archive);
+ return 0;
+ } else if(S_ISDIR(lsbuf.st_mode)) {
+ /* case 5: trying to overwrite dir with file, don't allow it */
+ _alpm_log(handle, ALPM_LOG_ERROR, _("extract: not overwriting dir with file %s\n"),
+ filename);
+ archive_read_data_skip(archive);
+ return 1;
+ } else if(S_ISDIR(entrymode)) {
+ /* case 4: trying to overwrite file with dir */
+ _alpm_log(handle, ALPM_LOG_DEBUG, "extract: overwriting file with dir %s\n",
+ filename);
+ } else {
+ /* case 3: trying to overwrite file with file */
+ /* if file is in NoUpgrade, don't touch it */
+ if(_alpm_fnmatch_patterns(handle->noupgrade, entryname) == 0) {
+ notouch = 1;
} else {
- /* case 3: */
- /* if file is in NoUpgrade, don't touch it */
- if(_alpm_fnmatch_patterns(handle->noupgrade, entryname) == 0) {
- notouch = 1;
- } else {
- alpm_backup_t *backup;
- /* go to the backup array and see if our conflict is there */
- /* check newpkg first, so that adding backup files is retroactive */
- backup = _alpm_needbackup(entryname, newpkg);
- if(backup) {
- needbackup = 1;
- }
-
- /* check oldpkg for a backup entry, store the hash if available */
- if(oldpkg) {
- backup = _alpm_needbackup(entryname, oldpkg);
- if(backup) {
- hash_orig = backup->hash;
- needbackup = 1;
- }
- }
+ alpm_backup_t *oldbackup;
+ if(oldpkg && (oldbackup = _alpm_needbackup(entryname, oldpkg))) {
+ hash_orig = oldbackup->hash;
+ needbackup = 1;
+ } else if(backup) {
+ /* allow adding backup files retroactively */
+ needbackup = 1;
}
}
}
- /* we need access to the original entryname later after calls to
- * archive_entry_set_pathname(), so we need to dupe it and free() later */
- STRDUP(entryname_orig, entryname, RET_ERR(handle, ALPM_ERR_MEMORY, -1));
+ if(notouch || needbackup) {
+ if(filename_len + strlen(".pacnew") >= PATH_MAX) {
+ _alpm_log(handle, ALPM_LOG_ERROR,
+ _("unable to extract %s.pacnew: path too long"), filename);
+ return 1;
+ }
+ strcpy(filename + filename_len, ".pacnew");
+ }
- if(needbackup) {
- char *checkfile;
- char *hash_local = NULL, *hash_pkg = NULL;
- size_t len;
+ if(handle->trans->flags & ALPM_TRANS_FLAG_FORCE) {
+ /* if FORCE was used, unlink() each file (whether it's there
+ * or not) before extracting. This prevents the old "Text file busy"
+ * error that crops up if forcing a glibc or pacman upgrade. */
+ unlink(filename);
+ }
+
+ _alpm_log(handle, ALPM_LOG_DEBUG, "extracting %s\n", filename);
+ if(perform_extraction(handle, archive, entry, filename)) {
+ errors++;
+ return errors;
+ }
- len = strlen(filename) + 10;
- MALLOC(checkfile, len,
- errors++; handle->pm_errno = ALPM_ERR_MEMORY; goto needbackup_cleanup);
- snprintf(checkfile, len, "%s.paccheck", filename);
+ if(backup) {
+ FREE(backup->hash);
+ backup->hash = alpm_compute_md5sum(filename);
+ }
- if(perform_extraction(handle, archive, entry, checkfile, entryname_orig)) {
- errors++;
- goto needbackup_cleanup;
- }
+ if(notouch) {
+ alpm_event_pacnew_created_t event = {
+ .type = ALPM_EVENT_PACNEW_CREATED,
+ .from_noupgrade = 1,
+ .oldpkg = oldpkg,
+ .newpkg = newpkg,
+ .file = filename
+ };
+ /* "remove" the .pacnew suffix */
+ filename[filename_len] = '\0';
+ EVENT(handle, &event);
+ alpm_logaction(handle, ALPM_CALLER_PREFIX,
+ "warning: %s installed as %s.pacnew\n", filename, filename);
+ } else if(needbackup) {
+ char *hash_local = NULL, *hash_pkg = NULL;
+ char origfile[PATH_MAX] = "";
- hash_local = alpm_compute_md5sum(filename);
- hash_pkg = alpm_compute_md5sum(checkfile);
+ strncat(origfile, filename, filename_len);
- /* update the md5 hash in newpkg's backup (it will be the new original) */
- alpm_list_t *i;
- for(i = alpm_pkg_get_backup(newpkg); i; i = i->next) {
- alpm_backup_t *backup = i->data;
- char *newhash;
- if(!backup->name || strcmp(backup->name, entryname_orig) != 0) {
- continue;
- }
- STRDUP(newhash, hash_pkg, errors++; handle->pm_errno = ALPM_ERR_MEMORY; goto needbackup_cleanup);
- FREE(backup->hash);
- backup->hash = newhash;
- }
+ hash_local = alpm_compute_md5sum(origfile);
+ hash_pkg = backup ? backup->hash : alpm_compute_md5sum(filename);
- _alpm_log(handle, ALPM_LOG_DEBUG, "checking hashes for %s\n", entryname_orig);
+ _alpm_log(handle, ALPM_LOG_DEBUG, "checking hashes for %s\n", origfile);
_alpm_log(handle, ALPM_LOG_DEBUG, "current: %s\n", hash_local);
_alpm_log(handle, ALPM_LOG_DEBUG, "new: %s\n", hash_pkg);
_alpm_log(handle, ALPM_LOG_DEBUG, "original: %s\n", hash_orig);
@@ -331,8 +342,8 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive,
/* local and new files are the same, updating anyway to get
* correct timestamps */
_alpm_log(handle, ALPM_LOG_DEBUG, "action: installing new file: %s\n",
- entryname_orig);
- if(try_rename(handle, checkfile, filename)) {
+ origfile);
+ if(try_rename(handle, filename, origfile)) {
errors++;
}
} else if(hash_orig && hash_pkg && strcmp(hash_orig, hash_pkg) == 0) {
@@ -340,146 +351,38 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive,
* including any user changes */
_alpm_log(handle, ALPM_LOG_DEBUG,
"action: leaving existing file in place\n");
- unlink(checkfile);
+ unlink(filename);
} else if(hash_orig && hash_local && strcmp(hash_orig, hash_local) == 0) {
/* installed file has NOT been changed by user,
* update to the new version */
_alpm_log(handle, ALPM_LOG_DEBUG, "action: installing new file: %s\n",
- entryname_orig);
- if(try_rename(handle, checkfile, filename)) {
+ origfile);
+ if(try_rename(handle, filename, origfile)) {
errors++;
}
} else {
- /* none of the three files matched another, unpack the new file alongside
- * the local file */
-
- if(oldpkg) {
- char *newpath;
- size_t newlen = strlen(filename) + strlen(".pacnew") + 1;
-
- _alpm_log(handle, ALPM_LOG_DEBUG,
- "action: keeping current file and installing"
- " new one with .pacnew ending\n");
-
- MALLOC(newpath, newlen,
- errors++; handle->pm_errno = ALPM_ERR_MEMORY; goto needbackup_cleanup);
- snprintf(newpath, newlen, "%s.pacnew", filename);
-
- if(try_rename(handle, checkfile, newpath)) {
- errors++;
- } else {
- alpm_event_pacnew_created_t event = {
- .type = ALPM_EVENT_PACNEW_CREATED,
- .from_noupgrade = 0,
- .oldpkg = oldpkg,
- .newpkg = newpkg,
- .file = filename
- };
- EVENT(handle, &event);
- alpm_logaction(handle, ALPM_CALLER_PREFIX,
- "warning: %s installed as %s\n", filename, newpath);
- }
-
- free(newpath);
- } else {
- char *newpath;
- size_t newlen = strlen(filename) + strlen(".pacorig") + 1;
-
- _alpm_log(handle, ALPM_LOG_DEBUG,
- "action: saving existing file with a .pacorig ending"
- " and installing a new one\n");
-
- MALLOC(newpath, newlen,
- errors++; handle->pm_errno = ALPM_ERR_MEMORY; goto needbackup_cleanup);
- snprintf(newpath, newlen, "%s.pacorig", filename);
-
- /* move the existing file to the "pacorig" */
- if(try_rename(handle, filename, newpath)) {
- errors++; /* failed rename filename -> filename.pacorig */
- errors++; /* failed rename checkfile -> filename */
- } else {
- /* rename the file we extracted to the real name */
- if(try_rename(handle, checkfile, filename)) {
- errors++;
- } else {
- alpm_event_pacorig_created_t event = {
- .type = ALPM_EVENT_PACORIG_CREATED,
- .newpkg = newpkg,
- .file = filename
- };
- EVENT(handle, &event);
- alpm_logaction(handle, ALPM_CALLER_PREFIX,
- "warning: %s saved as %s\n", filename, newpath);
- }
- }
-
- free(newpath);
- }
- }
-
-needbackup_cleanup:
- free(checkfile);
- free(hash_local);
- free(hash_pkg);
- } else {
- size_t len;
- /* we didn't need a backup */
- if(notouch) {
- /* change the path to a .pacnew extension */
- _alpm_log(handle, ALPM_LOG_DEBUG, "%s is in NoUpgrade -- skipping\n", filename);
- /* remember len so we can get the old filename back for the event */
- len = strlen(filename);
- strncat(filename, ".pacnew", PATH_MAX - len);
- } else {
- _alpm_log(handle, ALPM_LOG_DEBUG, "extracting %s\n", filename);
- }
-
- if(handle->trans->flags & ALPM_TRANS_FLAG_FORCE) {
- /* if FORCE was used, unlink() each file (whether it's there
- * or not) before extracting. This prevents the old "Text file busy"
- * error that crops up if forcing a glibc or pacman upgrade. */
- unlink(filename);
- }
-
- if(perform_extraction(handle, archive, entry, filename, entryname_orig)) {
- /* error */
- free(entryname_orig);
- errors++;
- return errors;
- }
-
- if(notouch) {
+ /* none of the three files matched another, leave the unpacked
+ * file alongside the local file */
alpm_event_pacnew_created_t event = {
.type = ALPM_EVENT_PACNEW_CREATED,
- .from_noupgrade = 1,
+ .from_noupgrade = 0,
.oldpkg = oldpkg,
.newpkg = newpkg,
- .file = filename
+ .file = origfile
};
- /* "remove" the .pacnew suffix */
- filename[len] = '\0';
+ _alpm_log(handle, ALPM_LOG_DEBUG,
+ "action: keeping current file and installing"
+ " new one with .pacnew ending\n");
EVENT(handle, &event);
alpm_logaction(handle, ALPM_CALLER_PREFIX,
- "warning: %s installed as %s.pacnew\n", filename, filename);
- /* restore */
- filename[len] = '.';
+ "warning: %s installed as %s\n", origfile, filename);
}
- /* calculate an hash if this is in newpkg's backup */
- alpm_list_t *i;
- for(i = alpm_pkg_get_backup(newpkg); i; i = i->next) {
- alpm_backup_t *backup = i->data;
- char *newhash;
- if(!backup->name || strcmp(backup->name, entryname_orig) != 0) {
- continue;
- }
- _alpm_log(handle, ALPM_LOG_DEBUG, "appending backup entry for %s\n", entryname_orig);
- newhash = alpm_compute_md5sum(filename);
- FREE(backup->hash);
- backup->hash = newhash;
+ free(hash_local);
+ if(!backup) {
+ free(hash_pkg);
}
}
- free(entryname_orig);
return errors;
}
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index e6ef3ae3..23ec2427 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -202,9 +202,6 @@ typedef enum _alpm_siglevel_t {
ALPM_SIG_DATABASE_MARGINAL_OK = (1 << 12),
ALPM_SIG_DATABASE_UNKNOWN_OK = (1 << 13),
- ALPM_SIG_PACKAGE_SET = (1 << 27),
- ALPM_SIG_PACKAGE_TRUST_SET = (1 << 28),
-
ALPM_SIG_USE_DEFAULT = (1 << 31)
} alpm_siglevel_t;
@@ -445,10 +442,7 @@ typedef enum _alpm_event_type_t {
ALPM_EVENT_PACNEW_CREATED,
/** A .pacsave file was created; See alpm_event_pacsave_created_t for
* arguments */
- ALPM_EVENT_PACSAVE_CREATED,
- /** A .pacorig file was created; See alpm_event_pacorig_created_t for
- * arguments */
- ALPM_EVENT_PACORIG_CREATED
+ ALPM_EVENT_PACSAVE_CREATED
} alpm_event_type_t;
typedef struct _alpm_event_any_t {
@@ -539,15 +533,6 @@ typedef struct _alpm_event_pacsave_created_t {
const char *file;
} alpm_event_pacsave_created_t;
-typedef struct _alpm_event_pacorig_created_t {
- /** Type of event. */
- alpm_event_type_t type;
- /** New package. */
- alpm_pkg_t *newpkg;
- /** Filename of the file without the .pacorig suffix. */
- const char *file;
-} alpm_event_pacorig_created_t;
-
/** Events.
* This is an union passed to the callback, that allows the frontend to know
* which type of event was triggered (via type). It is then possible to
@@ -564,7 +549,6 @@ typedef union _alpm_event_t {
alpm_event_pkgdownload_t pkgdownload;
alpm_event_pacnew_created_t pacnew_created;
alpm_event_pacsave_created_t pacsave_created;
- alpm_event_pacorig_created_t pacorig_created;
} alpm_event_t;
/** Event callback. */
@@ -1101,6 +1085,12 @@ int alpm_pkg_should_ignore(alpm_handle_t *handle, alpm_pkg_t *pkg);
*/
const char *alpm_pkg_get_filename(alpm_pkg_t *pkg);
+/** Returns the package base name.
+ * @param pkg a pointer to package
+ * @return a reference to an internal string
+ */
+const char *alpm_pkg_get_base(alpm_pkg_t *pkg);
+
/** Returns the package name.
* @param pkg a pointer to package
* @return a reference to an internal string
diff --git a/lib/libalpm/backup.c b/lib/libalpm/backup.c
index aeb41316..1fc5eb79 100644
--- a/lib/libalpm/backup.c
+++ b/lib/libalpm/backup.c
@@ -47,11 +47,10 @@ int _alpm_split_backup(const char *string, alpm_backup_t **backup)
*ptr = '\0';
ptr++;
/* now str points to the filename and ptr points to the hash */
- STRDUP((*backup)->name, str, return -1);
- STRDUP((*backup)->hash, ptr, return -1);
+ STRDUP((*backup)->name, str, FREE(str); return -1);
+ STRDUP((*backup)->hash, ptr, FREE(str); return -1);
FREE(str);
- return 0;
-}
+ return 0;}
/* Look for a filename in a alpm_pkg_t.backup list. If we find it,
* then we return the full backup entry.
diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
index 7d141c6d..300660b6 100644
--- a/lib/libalpm/be_local.c
+++ b/lib/libalpm/be_local.c
@@ -63,6 +63,12 @@ static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq);
* initialized.
*/
+static const char *_cache_get_base(alpm_pkg_t *pkg)
+{
+ LAZY_LOAD(INFRQ_DESC, NULL);
+ return pkg->base;
+}
+
static const char *_cache_get_desc(alpm_pkg_t *pkg)
{
LAZY_LOAD(INFRQ_DESC, NULL);
@@ -297,6 +303,7 @@ static int _cache_force_load(alpm_pkg_t *pkg)
* logic.
*/
static struct pkg_operations local_pkg_ops = {
+ .get_base = _cache_get_base,
.get_desc = _cache_get_desc,
.get_url = _cache_get_url,
.get_builddate = _cache_get_builddate,
@@ -701,6 +708,8 @@ static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq)
_alpm_log(db->handle, ALPM_LOG_ERROR, _("%s database is inconsistent: version "
"mismatch on package %s\n"), db->treename, info->name);
}
+ } else if(strcmp(line, "%BASE%") == 0) {
+ READ_AND_STORE(info->base);
} else if(strcmp(line, "%DESC%") == 0) {
READ_AND_STORE(info->desc);
} else if(strcmp(line, "%GROUPS%") == 0) {
@@ -801,6 +810,7 @@ static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq)
alpm_backup_t *backup;
CALLOC(backup, 1, sizeof(alpm_backup_t), goto error);
if(_alpm_split_backup(line, &backup)) {
+ FREE(backup);
goto error;
}
info->backup = alpm_list_add(info->backup, backup);
@@ -904,6 +914,10 @@ int _alpm_local_db_write(alpm_db_t *db, alpm_pkg_t *info, alpm_dbinfrq_t inforeq
free(path);
fprintf(fp, "%%NAME%%\n%s\n\n"
"%%VERSION%%\n%s\n\n", info->name, info->version);
+ if(info->base) {
+ fprintf(fp, "%%BASE%%\n"
+ "%s\n\n", info->base);
+ }
if(info->desc) {
fprintf(fp, "%%DESC%%\n"
"%s\n\n", info->desc);
@@ -1022,11 +1036,6 @@ int _alpm_local_db_write(alpm_db_t *db, alpm_pkg_t *info, alpm_dbinfrq_t inforeq
cleanup:
umask(oldmask);
-
- if(fp) {
- fclose(fp);
- }
-
return retval;
}
diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c
index 5617f4fa..06b24a8f 100644
--- a/lib/libalpm/be_package.c
+++ b/lib/libalpm/be_package.c
@@ -193,7 +193,7 @@ static int parse_descfile(alpm_handle_t *handle, struct archive *a, alpm_pkg_t *
STRDUP(newpkg->name, ptr, return -1);
newpkg->name_hash = _alpm_hash_sdbm(newpkg->name);
} else if(strcmp(key, "pkgbase") == 0) {
- /* not used atm */
+ STRDUP(newpkg->base, ptr, return -1);
} else if(strcmp(key, "pkgver") == 0) {
STRDUP(newpkg->version, ptr, return -1);
} else if(strcmp(key, "basever") == 0) {
@@ -437,6 +437,7 @@ static int add_entry_to_files_list(alpm_pkg_t *pkg, size_t *files_size,
static int build_filelist_from_mtree(alpm_handle_t *handle, alpm_pkg_t *pkg, struct archive *archive)
{
int ret = 0;
+ size_t i;
size_t mtree_maxsize = 0;
size_t mtree_cursize = 0;
size_t files_size = 0; /* we clean up the existing array so this is fine */
@@ -448,7 +449,7 @@ static int build_filelist_from_mtree(alpm_handle_t *handle, alpm_pkg_t *pkg, str
"found mtree for package %s, getting file list\n", pkg->filename);
/* throw away any files we might have already found */
- for (size_t i = 0; i < pkg->files.count; i++) {
+ for(i = 0; i < pkg->files.count; i++) {
free(pkg->files.files[i].name);
}
free(pkg->files.files);
diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c
index 52459483..0c4519aa 100644
--- a/lib/libalpm/be_sync.c
+++ b/lib/libalpm/be_sync.c
@@ -614,6 +614,8 @@ static int sync_db_read(alpm_db_t *db, struct archive *archive,
if(_alpm_validate_filename(db, pkg->name, pkg->filename) < 0) {
return -1;
}
+ } else if(strcmp(line, "%BASE%") == 0) {
+ READ_AND_STORE(pkg->base);
} else if(strcmp(line, "%DESC%") == 0) {
READ_AND_STORE(pkg->desc);
} else if(strcmp(line, "%GROUPS%") == 0) {
@@ -707,7 +709,7 @@ alpm_db_t *_alpm_db_register_sync(alpm_handle_t *handle, const char *treename,
_alpm_log(handle, ALPM_LOG_DEBUG, "registering sync database '%s'\n", treename);
#ifndef HAVE_LIBGPGME
- if((level &= ~ALPM_SIG_PACKAGE_SET) != 0 && level != ALPM_SIG_USE_DEFAULT) {
+ if(level != ALPM_SIG_USE_DEFAULT) {
RET_ERR(handle, ALPM_ERR_WRONG_ARGS, NULL);
}
#endif
diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c
index db07102c..c886f785 100644
--- a/lib/libalpm/conflict.c
+++ b/lib/libalpm/conflict.c
@@ -48,15 +48,19 @@ static alpm_conflict_t *conflict_new(alpm_pkg_t *pkg1, alpm_pkg_t *pkg2,
{
alpm_conflict_t *conflict;
- MALLOC(conflict, sizeof(alpm_conflict_t), return NULL);
+ CALLOC(conflict, 1, sizeof(alpm_conflict_t), return NULL);
conflict->package1_hash = pkg1->name_hash;
conflict->package2_hash = pkg2->name_hash;
- STRDUP(conflict->package1, pkg1->name, return NULL);
- STRDUP(conflict->package2, pkg2->name, return NULL);
+ STRDUP(conflict->package1, pkg1->name, goto error);
+ STRDUP(conflict->package2, pkg2->name, goto error);
conflict->reason = reason;
return conflict;
+
+error:
+ alpm_conflict_free(conflict);
+ return NULL;
}
/**
@@ -79,11 +83,15 @@ alpm_conflict_t *_alpm_conflict_dup(const alpm_conflict_t *conflict)
newconflict->package1_hash = conflict->package1_hash;
newconflict->package2_hash = conflict->package2_hash;
- STRDUP(newconflict->package1, conflict->package1, return NULL);
- STRDUP(newconflict->package2, conflict->package2, return NULL);
+ STRDUP(newconflict->package1, conflict->package1, goto error);
+ STRDUP(newconflict->package2, conflict->package2, goto error);
newconflict->reason = conflict->reason;
return newconflict;
+
+error:
+ alpm_conflict_free(newconflict);
+ return NULL;
}
/**
@@ -265,7 +273,7 @@ static alpm_list_t *add_fileconflict(alpm_handle_t *handle,
alpm_pkg_t *pkg1, alpm_pkg_t *pkg2)
{
alpm_fileconflict_t *conflict;
- MALLOC(conflict, sizeof(alpm_fileconflict_t), goto error);
+ CALLOC(conflict, 1, sizeof(alpm_fileconflict_t), goto error);
STRDUP(conflict->target, pkg1->name, goto error);
STRDUP(conflict->file, filestr, goto error);
@@ -284,6 +292,7 @@ static alpm_list_t *add_fileconflict(alpm_handle_t *handle,
return conflicts;
error:
+ alpm_fileconflict_free(conflict);
RET_ERR(handle, ALPM_ERR_MEMORY, conflicts);
}
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c
index 466c96f1..ebcd1f89 100644
--- a/lib/libalpm/db.c
+++ b/lib/libalpm/db.c
@@ -331,7 +331,7 @@ alpm_db_t *_alpm_db_new(const char *treename, int is_local)
alpm_db_t *db;
CALLOC(db, 1, sizeof(alpm_db_t), return NULL);
- STRDUP(db->treename, treename, return NULL);
+ STRDUP(db->treename, treename, FREE(db); return NULL);
if(is_local) {
db->status |= DB_STATUS_LOCAL;
} else {
@@ -542,7 +542,10 @@ alpm_pkghash_t *_alpm_db_get_pkgcache_hash(alpm_db_t *db)
}
if(!(db->status & DB_STATUS_PKGCACHE)) {
- load_pkgcache(db);
+ if(load_pkgcache(db)) {
+ /* handle->error set in local/sync-db-populate */
+ return NULL;
+ }
}
return db->pkgcache;
@@ -562,13 +565,15 @@ alpm_list_t *_alpm_db_get_pkgcache(alpm_db_t *db)
/* "duplicate" pkg then add it to pkgcache */
int _alpm_db_add_pkgincache(alpm_db_t *db, alpm_pkg_t *pkg)
{
- alpm_pkg_t *newpkg;
+ alpm_pkg_t *newpkg = NULL;
if(db == NULL || pkg == NULL || !(db->status & DB_STATUS_PKGCACHE)) {
return -1;
}
if(_alpm_pkg_dup(pkg, &newpkg)) {
+ /* we return memory on "non-fatal" error in _alpm_pkg_dup */
+ _alpm_pkg_free(newpkg);
return -1;
}
diff --git a/lib/libalpm/delta.c b/lib/libalpm/delta.c
index baa02b75..db6bb8e7 100644
--- a/lib/libalpm/delta.c
+++ b/lib/libalpm/delta.c
@@ -306,10 +306,10 @@ alpm_delta_t *_alpm_delta_parse(alpm_handle_t *handle, const char *line)
/* start at index 1 -- match 0 is the entire match */
len = pmatch[1].rm_eo - pmatch[1].rm_so;
- STRNDUP(delta->delta, &line[pmatch[1].rm_so], len, return NULL);
+ STRNDUP(delta->delta, &line[pmatch[1].rm_so], len, goto error);
len = pmatch[2].rm_eo - pmatch[2].rm_so;
- STRNDUP(delta->delta_md5, &line[pmatch[2].rm_so], len, return NULL);
+ STRNDUP(delta->delta_md5, &line[pmatch[2].rm_so], len, goto error);
len = pmatch[3].rm_eo - pmatch[3].rm_so;
if(len < sizeof(filesize)) {
@@ -319,12 +319,16 @@ alpm_delta_t *_alpm_delta_parse(alpm_handle_t *handle, const char *line)
}
len = pmatch[4].rm_eo - pmatch[4].rm_so;
- STRNDUP(delta->from, &line[pmatch[4].rm_so], len, return NULL);
+ STRNDUP(delta->from, &line[pmatch[4].rm_so], len, goto error);
len = pmatch[5].rm_eo - pmatch[5].rm_so;
- STRNDUP(delta->to, &line[pmatch[5].rm_so], len, return NULL);
+ STRNDUP(delta->to, &line[pmatch[5].rm_so], len, goto error);
return delta;
+
+error:
+ _alpm_delta_free(delta);
+ return NULL;
}
#undef NUM_MATCHES
@@ -342,14 +346,18 @@ alpm_delta_t *_alpm_delta_dup(const alpm_delta_t *delta)
{
alpm_delta_t *newdelta;
CALLOC(newdelta, 1, sizeof(alpm_delta_t), return NULL);
- STRDUP(newdelta->delta, delta->delta, return NULL);
- STRDUP(newdelta->delta_md5, delta->delta_md5, return NULL);
- STRDUP(newdelta->from, delta->from, return NULL);
- STRDUP(newdelta->to, delta->to, return NULL);
+ STRDUP(newdelta->delta, delta->delta, goto error);
+ STRDUP(newdelta->delta_md5, delta->delta_md5, goto error);
+ STRDUP(newdelta->from, delta->from, goto error);
+ STRDUP(newdelta->to, delta->to, goto error);
newdelta->delta_size = delta->delta_size;
newdelta->download_size = delta->download_size;
return newdelta;
+
+error:
+ _alpm_delta_free(newdelta);
+ return NULL;
}
/* vim: set noet: */
diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c
index f2ee8f41..c340f112 100644
--- a/lib/libalpm/deps.c
+++ b/lib/libalpm/deps.c
@@ -48,13 +48,17 @@ static alpm_depmissing_t *depmiss_new(const char *target, alpm_depend_t *dep,
{
alpm_depmissing_t *miss;
- MALLOC(miss, sizeof(alpm_depmissing_t), return NULL);
+ CALLOC(miss, 1, sizeof(alpm_depmissing_t), return NULL);
- STRDUP(miss->target, target, return NULL);
+ STRDUP(miss->target, target, goto error);
miss->depend = _alpm_dep_dup(dep);
- STRDUP(miss->causingpkg, causingpkg, return NULL);
+ STRDUP(miss->causingpkg, causingpkg, goto error);
return miss;
+
+error:
+ alpm_depmissing_free(miss);
+ return NULL;
}
void SYMEXPORT alpm_depmissing_free(alpm_depmissing_t *miss)
@@ -465,11 +469,11 @@ alpm_depend_t SYMEXPORT *alpm_dep_from_string(const char *depstring)
return NULL;
}
- MALLOC(depend, sizeof(alpm_depend_t), return NULL);
+ CALLOC(depend, 1, sizeof(alpm_depend_t), return NULL);
/* Note the extra space in ": " to avoid matching the epoch */
if((desc = strstr(depstring, ": ")) != NULL) {
- STRDUP(depend->desc, desc + 2, return NULL);
+ STRDUP(depend->desc, desc + 2, goto error);
deplen = desc - depstring;
} else {
/* no description- point desc at NULL at end of string for later use */
@@ -509,13 +513,17 @@ alpm_depend_t SYMEXPORT *alpm_dep_from_string(const char *depstring)
}
/* copy the right parts to the right places */
- STRNDUP(depend->name, depstring, ptr - depstring, return NULL);
+ STRNDUP(depend->name, depstring, ptr - depstring, goto error);
depend->name_hash = _alpm_hash_sdbm(depend->name);
if(version) {
- STRNDUP(depend->version, version, desc - version, return NULL);
+ STRNDUP(depend->version, version, desc - version, goto error);
}
return depend;
+
+error:
+ alpm_dep_free(depend);
+ return NULL;
}
alpm_depend_t *_alpm_dep_dup(const alpm_depend_t *dep)
@@ -523,13 +531,17 @@ alpm_depend_t *_alpm_dep_dup(const alpm_depend_t *dep)
alpm_depend_t *newdep;
CALLOC(newdep, 1, sizeof(alpm_depend_t), return NULL);
- STRDUP(newdep->name, dep->name, return NULL);
- STRDUP(newdep->version, dep->version, return NULL);
- STRDUP(newdep->desc, dep->desc, return NULL);
+ STRDUP(newdep->name, dep->name, goto error);
+ STRDUP(newdep->version, dep->version, goto error);
+ STRDUP(newdep->desc, dep->desc, goto error);
newdep->name_hash = dep->name_hash;
newdep->mod = dep->mod;
return newdep;
+
+error:
+ alpm_dep_free(newdep);
+ return NULL;
}
/* These parameters are messy. We check if this package, given a list of
@@ -597,11 +609,13 @@ int _alpm_recursedeps(alpm_db_t *db, alpm_list_t **targs, int include_explicit)
alpm_pkg_t *deppkg = j->data;
if(_alpm_pkg_depends_on(pkg, deppkg)
&& can_remove_package(db, deppkg, *targs, include_explicit)) {
- alpm_pkg_t *copy;
+ alpm_pkg_t *copy = NULL;
_alpm_log(db->handle, ALPM_LOG_DEBUG, "adding '%s' to the targets\n",
deppkg->name);
/* add it to the target list */
if(_alpm_pkg_dup(deppkg, &copy)) {
+ /* we return memory on "non-fatal" error in _alpm_pkg_dup */
+ _alpm_pkg_free(copy);
return -1;
}
*targs = alpm_list_add(*targs, copy);
diff --git a/lib/libalpm/diskspace.c b/lib/libalpm/diskspace.c
index af87f755..c94cab31 100644
--- a/lib/libalpm/diskspace.c
+++ b/lib/libalpm/diskspace.c
@@ -112,7 +112,7 @@ static alpm_list_t *mount_point_list(alpm_handle_t *handle)
while((mnt = getmntent(fp))) {
CALLOC(mp, 1, sizeof(alpm_mountpoint_t), RET_ERR(handle, ALPM_ERR_MEMORY, NULL));
- STRDUP(mp->mount_dir, mnt->mnt_dir, RET_ERR(handle, ALPM_ERR_MEMORY, NULL));
+ STRDUP(mp->mount_dir, mnt->mnt_dir, free(mp); RET_ERR(handle, ALPM_ERR_MEMORY, NULL));
mp->mount_dir_len = strlen(mp->mount_dir);
mount_points = alpm_list_add(mount_points, mp);
@@ -135,7 +135,7 @@ static alpm_list_t *mount_point_list(alpm_handle_t *handle)
while((ret = getmntent(fp, &mnt)) == 0) {
CALLOC(mp, 1, sizeof(alpm_mountpoint_t), RET_ERR(handle, ALPM_ERR_MEMORY, NULL));
- STRDUP(mp->mount_dir, mnt->mnt_mountp, RET_ERR(handle, ALPM_ERR_MEMORY, NULL));
+ STRDUP(mp->mount_dir, mnt->mnt_mountp, free(mp); RET_ERR(handle, ALPM_ERR_MEMORY, NULL));
mp->mount_dir_len = strlen(mp->mount_dir);
mount_points = alpm_list_add(mount_points, mp);
@@ -162,7 +162,7 @@ static alpm_list_t *mount_point_list(alpm_handle_t *handle)
for(; entries-- > 0; fsp++) {
CALLOC(mp, 1, sizeof(alpm_mountpoint_t), RET_ERR(handle, ALPM_ERR_MEMORY, NULL));
- STRDUP(mp->mount_dir, fsp->f_mntonname, RET_ERR(handle, ALPM_ERR_MEMORY, NULL));
+ STRDUP(mp->mount_dir, fsp->f_mntonname, free(mp); RET_ERR(handle, ALPM_ERR_MEMORY, NULL));
mp->mount_dir_len = strlen(mp->mount_dir);
memcpy(&(mp->fsp), fsp, sizeof(FSSTATSTYPE));
#if defined(HAVE_GETMNTINFO_STATVFS) && defined(HAVE_STRUCT_STATVFS_F_FLAG)
diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c
index e3409f99..c5186bef 100644
--- a/lib/libalpm/dload.c
+++ b/lib/libalpm/dload.c
@@ -379,7 +379,7 @@ static FILE *create_tempfile(struct dload_payload *payload, const char *localpat
payload->tempfile_name = randpath;
free(payload->remote_name);
STRDUP(payload->remote_name, strrchr(randpath, '/') + 1,
- RET_ERR(payload->handle, ALPM_ERR_MEMORY, NULL));
+ fclose(fp); RET_ERR(payload->handle, ALPM_ERR_MEMORY, NULL));
return fp;
}
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index d9ed3d31..b186a4cb 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -83,6 +83,7 @@ int SYMEXPORT alpm_pkg_checkmd5sum(alpm_pkg_t *pkg)
* backend logic that needs lazy access, such as the local database through
* a lazy-load cache. However, the defaults will work just fine for fully-
* populated package structures. */
+static const char *_pkg_get_base(alpm_pkg_t *pkg) { return pkg->base; }
static const char *_pkg_get_desc(alpm_pkg_t *pkg) { return pkg->desc; }
static const char *_pkg_get_url(alpm_pkg_t *pkg) { return pkg->url; }
static alpm_time_t _pkg_get_builddate(alpm_pkg_t *pkg) { return pkg->builddate; }
@@ -144,6 +145,7 @@ static int _pkg_force_load(alpm_pkg_t UNUSED *pkg) { return 0; }
* struct itself with no abstraction layer or any type of lazy loading.
*/
struct pkg_operations default_pkg_ops = {
+ .get_base = _pkg_get_base,
.get_desc = _pkg_get_desc,
.get_url = _pkg_get_url,
.get_builddate = _pkg_get_builddate,
@@ -186,6 +188,13 @@ const char SYMEXPORT *alpm_pkg_get_filename(alpm_pkg_t *pkg)
return pkg->filename;
}
+const char SYMEXPORT *alpm_pkg_get_base(alpm_pkg_t *pkg)
+{
+ ASSERT(pkg != NULL, return NULL);
+ pkg->handle->pm_errno = 0;
+ return pkg->ops->get_base(pkg);
+}
+
const char SYMEXPORT *alpm_pkg_get_name(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return NULL);
@@ -566,6 +575,7 @@ int _alpm_pkg_dup(alpm_pkg_t *pkg, alpm_pkg_t **new_ptr)
newpkg->name_hash = pkg->name_hash;
STRDUP(newpkg->filename, pkg->filename, goto cleanup);
+ STRDUP(newpkg->base, pkg->base, goto cleanup);
STRDUP(newpkg->name, pkg->name, goto cleanup);
STRDUP(newpkg->version, pkg->version, goto cleanup);
STRDUP(newpkg->desc, pkg->desc, goto cleanup);
@@ -641,6 +651,7 @@ void _alpm_pkg_free(alpm_pkg_t *pkg)
}
FREE(pkg->filename);
+ FREE(pkg->base);
FREE(pkg->name);
FREE(pkg->version);
FREE(pkg->desc);
diff --git a/lib/libalpm/package.h b/lib/libalpm/package.h
index 357c20ef..5ab9b207 100644
--- a/lib/libalpm/package.h
+++ b/lib/libalpm/package.h
@@ -43,6 +43,7 @@
* defined default_pkg_ops struct to work just fine for their needs.
*/
struct pkg_operations {
+ const char *(*get_base) (alpm_pkg_t *);
const char *(*get_desc) (alpm_pkg_t *);
const char *(*get_url) (alpm_pkg_t *);
alpm_time_t (*get_builddate) (alpm_pkg_t *);
@@ -85,6 +86,7 @@ extern struct pkg_operations default_pkg_ops;
struct __alpm_pkg_t {
unsigned long name_hash;
char *filename;
+ char *base;
char *name;
char *version;
char *desc;
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index c513b6b5..e19655d9 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -736,11 +736,11 @@ static int apply_deltas(alpm_handle_t *handle)
} else {
/* len = cachedir len + from len + '/' + null */
len = strlen(cachedir) + strlen(d->from) + 2;
- MALLOC(from, len, RET_ERR(handle, ALPM_ERR_MEMORY, 1));
+ MALLOC(from, len, free(delta); RET_ERR(handle, ALPM_ERR_MEMORY, 1));
snprintf(from, len, "%s/%s", cachedir, d->from);
}
len = strlen(cachedir) + strlen(d->to) + 2;
- MALLOC(to, len, free(from); RET_ERR(handle, ALPM_ERR_MEMORY, 1));
+ MALLOC(to, len, free(delta); free(from); RET_ERR(handle, ALPM_ERR_MEMORY, 1));
snprintf(to, len, "%s/%s", cachedir, d->to);
/* build the patch command */
@@ -862,7 +862,7 @@ static struct dload_payload *build_payload(alpm_handle_t *handle,
struct dload_payload *payload;
CALLOC(payload, 1, sizeof(*payload), RET_ERR(handle, ALPM_ERR_MEMORY, NULL));
- STRDUP(payload->remote_name, filename, RET_ERR(handle, ALPM_ERR_MEMORY, NULL));
+ STRDUP(payload->remote_name, filename, FREE(payload); RET_ERR(handle, ALPM_ERR_MEMORY, NULL));
payload->max_size = size;
payload->servers = servers;
return payload;
diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c
index e1caa5e3..48745d3b 100644
--- a/lib/libalpm/trans.c
+++ b/lib/libalpm/trans.c
@@ -347,7 +347,7 @@ int _alpm_runscriptlet(alpm_handle_t *handle, const char *filepath,
/* either extract or copy the scriptlet */
len += strlen("/.INSTALL");
- MALLOC(scriptfn, len, RET_ERR(handle, ALPM_ERR_MEMORY, -1));
+ MALLOC(scriptfn, len, free(tmpdir); RET_ERR(handle, ALPM_ERR_MEMORY, -1));
snprintf(scriptfn, len, "%s/.INSTALL", tmpdir);
if(is_archive) {
if(_alpm_unpack_single(handle, filepath, tmpdir, ".INSTALL")) {
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index 1e367369..ffd3c73d 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -542,7 +542,9 @@ int _alpm_run_chroot(alpm_handle_t *handle, const char *cmd, char *const argv[])
while(dup2(pipefd[1], 2) == -1 && errno == EINTR);
close(pipefd[0]);
close(pipefd[1]);
- close(cwdfd);
+ if(cwdfd >= 0) {
+ close(cwdfd);
+ }
/* use fprintf instead of _alpm_log to send output through the parent */
if(chroot(handle->root) != 0) {
diff --git a/scripts/makepkg-template.pl.in b/scripts/makepkg-template.pl.in
index d9da1674..4bfd4d6a 100755
--- a/scripts/makepkg-template.pl.in
+++ b/scripts/makepkg-template.pl.in
@@ -109,7 +109,7 @@ sub load_template {
my ($version) = (abs_path($path) =~ /-([0-9.]+)[.]template$/);
if (!$version) {
- die sprintf(gettext("Couldn't detect version for template '%s'"), $values->{name});
+ die sprintf(gettext("Couldn't detect version for template '%s'\n"), $values->{name});
}
my $parsed = process_file($path);
@@ -128,7 +128,7 @@ sub process_file {
my $nesting_level = 0;
my $linenumber = 0;
- open (my $fh, "<", $filename) or die sprintf(gettext("failed to open '%s': %s"), $filename, $!);
+ open (my $fh, "<", $filename) or die sprintf(gettext("failed to open '%s': %s\n"), $filename, $!);
my @lines = <$fh>;
close $fh;
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 4461d12f..716ed808 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -1284,22 +1284,23 @@ verify_integrity_one() {
}
verify_integrity_sums() {
- local integ=$1 arch=$2 integrity_sums=() sources=()
+ local integ=$1 arch=$2 integrity_sums=() sources=() srcname
if [[ $arch ]]; then
array_build integrity_sums "${integ}sums_$arch"
- array_build sources "source_$arch"
+ srcname=source_$arch
else
array_build integrity_sums "${integ}sums"
- array_build sources source
+ srcname=source
fi
+ array_build sources "$srcname"
if (( ${#integrity_sums[@]} == 0 && ${#sources[@]} == 0 )); then
return 1
fi
if (( ${#integrity_sums[@]} == ${#sources[@]} )); then
- msg "$(gettext "Validating source files with %s...")" "${integ}sums"
+ msg "$(gettext "Validating %s files with %s...")" "$srcname" "${integ}sums"
local idx errors=0
for (( idx = 0; idx < ${#sources[*]}; idx++ )); do
verify_integrity_one "${sources[idx]}" "$integ" "${integrity_sums[idx]}" || errors=1
@@ -1352,7 +1353,7 @@ check_checksums() {
done
if (( ${#correlation[*]} )); then
- error "$(gettext "Integrity checks are missing.")"
+ error "$(gettext "Integrity checks are missing for: %s")" "${!correlation[*]}"
exit 1 # TODO: error code
fi
}
diff --git a/scripts/pkgdelta.sh.in b/scripts/pkgdelta.sh.in
index be49326e..fe63974d 100644
--- a/scripts/pkgdelta.sh.in
+++ b/scripts/pkgdelta.sh.in
@@ -140,7 +140,7 @@ create_xdelta()
deltafile=$(dirname "$newfile")/$pkgname-${oldver}_to_${newver}-$arch.delta
local ret=0
- xdelta3 -q -f -s "$oldfile" "$newfile" "$deltafile" || ret=$?
+ xdelta3 -q -f -9 -S lzma -s "$oldfile" "$newfile" "$deltafile" || ret=$?
if (( ret )); then
error "$(gettext "Delta could not be created.")"
return 1
diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index 4993382d..0d87fd35 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -269,9 +269,11 @@ void cb_event(alpm_event_t *event)
case ALPM_EVENT_OPTDEP_REMOVAL:
{
alpm_event_optdep_removal_t *e = &event->optdep_removal;
+ char *dep_string = alpm_dep_compute_string(e->optdep);
colon_printf(_("%s optionally requires %s\n"),
alpm_pkg_get_name(e->pkg),
- alpm_dep_compute_string(e->optdep));
+ dep_string);
+ free(dep_string);
}
break;
case ALPM_EVENT_DATABASE_MISSING:
@@ -313,22 +315,6 @@ void cb_event(alpm_event_t *event)
}
}
break;
- case ALPM_EVENT_PACORIG_CREATED:
- {
- alpm_event_pacorig_created_t *e = &event->pacorig_created;
- if(on_progress) {
- char *string = NULL;
- pm_sprintf(&string, ALPM_LOG_WARNING, _("%s saved as %s.pacorig\n"),
- e->file, e->file);
- if(string != NULL) {
- output = alpm_list_add(output, string);
- }
- } else {
- pm_printf(ALPM_LOG_WARNING, _("%s saved as %s.pacorig\n"),
- e->file, e->file);
- }
- }
- break;
/* all the simple done events, with fallthrough for each */
case ALPM_EVENT_FILECONFLICTS_DONE:
case ALPM_EVENT_CHECKDEPS_DONE:
diff --git a/src/pacman/conf.c b/src/pacman/conf.c
index 873ca0ee..b31b2536 100644
--- a/src/pacman/conf.c
+++ b/src/pacman/conf.c
@@ -22,6 +22,7 @@
#include <limits.h>
#include <locale.h> /* setlocale */
#include <fcntl.h> /* open */
+#include <glob.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h> /* strdup */
@@ -131,6 +132,9 @@ int config_free(config_t *oldconfig)
alpm_list_free(oldconfig->explicit_adds);
alpm_list_free(oldconfig->explicit_removes);
+ alpm_list_free_inner(config->repos, (alpm_list_fn_free) config_repo_free);
+ alpm_list_free(config->repos);
+
FREELIST(oldconfig->holdpkg);
FREELIST(oldconfig->ignorepkg);
FREELIST(oldconfig->ignoregrp);
@@ -151,6 +155,16 @@ int config_free(config_t *oldconfig)
return 0;
}
+void config_repo_free(config_repo_t *repo)
+{
+ if(repo == NULL) {
+ return;
+ }
+ free(repo->name);
+ FREELIST(repo->servers);
+ free(repo);
+}
+
/** Helper function for download_with_xfercommand() */
static char *get_filename(const char *url)
{
@@ -309,12 +323,15 @@ int config_set_arch(const char *arch)
* @return 0 on success, 1 on any parsing error
*/
static int process_siglevel(alpm_list_t *values, alpm_siglevel_t *storage,
- const char *file, int linenum)
+ alpm_siglevel_t *storage_mask, const char *file, int linenum)
{
- alpm_siglevel_t level = *storage;
+ alpm_siglevel_t level = *storage, mask = *storage_mask;
alpm_list_t *i;
int ret = 0;
+#define SLSET(sl) do { level |= (sl); mask |= (sl); } while(0)
+#define SLUNSET(sl) do { level &= ~(sl); mask |= (sl); } while(0)
+
/* Collapse the option names into a single bitmasked value */
for(i = values; i; i = alpm_list_next(i)) {
const char *original = i->data, *value;
@@ -337,51 +354,40 @@ static int process_siglevel(alpm_list_t *values, alpm_siglevel_t *storage,
/* now parse out and store actual flag if it is valid */
if(strcmp(value, "Never") == 0) {
if(package) {
- level &= ~ALPM_SIG_PACKAGE;
- level |= ALPM_SIG_PACKAGE_SET;
+ SLUNSET(ALPM_SIG_PACKAGE);
}
if(database) {
- level &= ~ALPM_SIG_DATABASE;
+ SLUNSET(ALPM_SIG_DATABASE);
}
} else if(strcmp(value, "Optional") == 0) {
if(package) {
- level |= ALPM_SIG_PACKAGE;
- level |= ALPM_SIG_PACKAGE_OPTIONAL;
- level |= ALPM_SIG_PACKAGE_SET;
+ SLSET(ALPM_SIG_PACKAGE | ALPM_SIG_PACKAGE_OPTIONAL);
}
if(database) {
- level |= ALPM_SIG_DATABASE;
- level |= ALPM_SIG_DATABASE_OPTIONAL;
+ SLSET(ALPM_SIG_DATABASE | ALPM_SIG_DATABASE_OPTIONAL);
}
} else if(strcmp(value, "Required") == 0) {
if(package) {
- level |= ALPM_SIG_PACKAGE;
- level &= ~ALPM_SIG_PACKAGE_OPTIONAL;
- level |= ALPM_SIG_PACKAGE_SET;
+ SLSET(ALPM_SIG_PACKAGE);
+ SLUNSET(ALPM_SIG_PACKAGE_OPTIONAL);
}
if(database) {
- level |= ALPM_SIG_DATABASE;
- level &= ~ALPM_SIG_DATABASE_OPTIONAL;
+ SLSET(ALPM_SIG_DATABASE);
+ SLUNSET(ALPM_SIG_DATABASE_OPTIONAL);
}
} else if(strcmp(value, "TrustedOnly") == 0) {
if(package) {
- level &= ~ALPM_SIG_PACKAGE_MARGINAL_OK;
- level &= ~ALPM_SIG_PACKAGE_UNKNOWN_OK;
- level |= ALPM_SIG_PACKAGE_TRUST_SET;
+ SLUNSET(ALPM_SIG_PACKAGE_MARGINAL_OK | ALPM_SIG_PACKAGE_UNKNOWN_OK);
}
if(database) {
- level &= ~ALPM_SIG_DATABASE_MARGINAL_OK;
- level &= ~ALPM_SIG_DATABASE_UNKNOWN_OK;
+ SLUNSET(ALPM_SIG_DATABASE_MARGINAL_OK | ALPM_SIG_DATABASE_UNKNOWN_OK);
}
} else if(strcmp(value, "TrustAll") == 0) {
if(package) {
- level |= ALPM_SIG_PACKAGE_MARGINAL_OK;
- level |= ALPM_SIG_PACKAGE_UNKNOWN_OK;
- level |= ALPM_SIG_PACKAGE_TRUST_SET;
+ SLSET(ALPM_SIG_PACKAGE_MARGINAL_OK | ALPM_SIG_PACKAGE_UNKNOWN_OK);
}
if(database) {
- level |= ALPM_SIG_DATABASE_MARGINAL_OK;
- level |= ALPM_SIG_DATABASE_UNKNOWN_OK;
+ SLSET(ALPM_SIG_DATABASE_MARGINAL_OK | ALPM_SIG_DATABASE_UNKNOWN_OK);
}
} else {
pm_printf(ALPM_LOG_ERROR,
@@ -392,6 +398,9 @@ static int process_siglevel(alpm_list_t *values, alpm_siglevel_t *storage,
level &= ~ALPM_SIG_USE_DEFAULT;
}
+#undef SLSET
+#undef SLUNSET
+
/* ensure we have sig checking ability and are actually turning it on */
if(!(alpm_capabilities() & ALPM_CAPABILITY_SIGNATURES) &&
level & (ALPM_SIG_PACKAGE | ALPM_SIG_DATABASE)) {
@@ -403,6 +412,7 @@ static int process_siglevel(alpm_list_t *values, alpm_siglevel_t *storage,
if(!ret) {
*storage = level;
+ *storage_mask = mask;
}
return ret;
}
@@ -410,23 +420,13 @@ static int process_siglevel(alpm_list_t *values, alpm_siglevel_t *storage,
/**
* Merge the package entires of two signature verification levels.
* @param base initial siglevel
- * @param over overridden siglevel, derived value is stored here
+ * @param over overridden siglevel
+ * @return merged siglevel
*/
-static void merge_siglevel(alpm_siglevel_t *base, alpm_siglevel_t *over)
+static alpm_siglevel_t merge_siglevel(alpm_siglevel_t base,
+ alpm_siglevel_t over, alpm_siglevel_t mask)
{
- alpm_siglevel_t level = *over;
- if(!(level & ALPM_SIG_USE_DEFAULT)) {
- if(!(level & ALPM_SIG_PACKAGE_SET)) {
- level |= *base & ALPM_SIG_PACKAGE;
- level |= *base & ALPM_SIG_PACKAGE_OPTIONAL;
- }
- if(!(level & ALPM_SIG_PACKAGE_TRUST_SET)) {
- level |= *base & ALPM_SIG_PACKAGE_MARGINAL_OK;
- level |= *base & ALPM_SIG_PACKAGE_UNKNOWN_OK;
- }
- }
-
- *over = level;
+ return mask ? (over & mask) | (base & ~mask) : over;
}
static int process_cleanmethods(alpm_list_t *values,
@@ -575,7 +575,8 @@ static int _parse_options(const char *key, char *value,
} else if(strcmp(key, "SigLevel") == 0) {
alpm_list_t *values = NULL;
setrepeatingoption(value, "SigLevel", &values);
- if(process_siglevel(values, &config->siglevel, file, linenum)) {
+ if(process_siglevel(values, &config->siglevel,
+ &config->siglevel_mask, file, linenum)) {
FREELIST(values);
return 1;
}
@@ -583,7 +584,8 @@ static int _parse_options(const char *key, char *value,
} else if(strcmp(key, "LocalFileSigLevel") == 0) {
alpm_list_t *values = NULL;
setrepeatingoption(value, "LocalFileSigLevel", &values);
- if(process_siglevel(values, &config->localfilesiglevel, file, linenum)) {
+ if(process_siglevel(values, &config->localfilesiglevel,
+ &config->localfilesiglevel_mask, file, linenum)) {
FREELIST(values);
return 1;
}
@@ -591,7 +593,8 @@ static int _parse_options(const char *key, char *value,
} else if(strcmp(key, "RemoteFileSigLevel") == 0) {
alpm_list_t *values = NULL;
setrepeatingoption(value, "RemoteFileSigLevel", &values);
- if(process_siglevel(values, &config->remotefilesiglevel, file, linenum)) {
+ if(process_siglevel(values, &config->remotefilesiglevel,
+ &config->remotefilesiglevel_mask, file, linenum)) {
FREELIST(values);
return 1;
}
@@ -640,6 +643,40 @@ static int _add_mirror(alpm_db_t *db, char *value)
return 0;
}
+static int register_repo(config_repo_t *repo)
+{
+ alpm_list_t *i;
+ alpm_db_t *db;
+
+ repo->siglevel = merge_siglevel(config->siglevel,
+ repo->siglevel, repo->siglevel_mask);
+
+ db = alpm_register_syncdb(config->handle, repo->name, repo->siglevel);
+ if(db == NULL) {
+ pm_printf(ALPM_LOG_ERROR, _("could not register '%s' database (%s)\n"),
+ repo->name, alpm_strerror(alpm_errno(config->handle)));
+ return 1;
+ }
+
+ pm_printf(ALPM_LOG_DEBUG,
+ "setting usage of %d for %s repository\n",
+ repo->usage == 0 ? ALPM_DB_USAGE_ALL : repo->usage,
+ repo->name);
+ alpm_db_set_usage(db, repo->usage == 0 ? ALPM_DB_USAGE_ALL : repo->usage);
+
+ for(i = repo->servers; i; i = alpm_list_next(i)) {
+ char *value = i->data;
+ if(_add_mirror(db, value) != 0) {
+ pm_printf(ALPM_LOG_ERROR,
+ _("could not add mirror '%s' to database '%s' (%s)\n"),
+ value, repo->name, alpm_strerror(alpm_errno(config->handle)));
+ return 1;
+ }
+ }
+
+ return 0;
+}
+
/** Sets up libalpm global stuff in one go. Called after the command line
* and initial config file parsing. Once this is complete, we can see if any
* paths were defined. If a rootdir was defined and nothing else, we want all
@@ -680,7 +717,7 @@ static int setup_libalpm(void)
pm_printf(ALPM_LOG_ERROR, _("failed to initialize alpm library\n(%s: %s)\n"),
alpm_strerror(err), config->dbpath);
if(err == ALPM_ERR_DB_VERSION) {
- pm_printf(ALPM_LOG_ERROR, _(" try running pacman-db-upgrade\n"));
+ fprintf(stderr, _("try running pacman-db-upgrade\n"));
}
return -1;
}
@@ -719,11 +756,18 @@ static int setup_libalpm(void)
alpm_option_set_default_siglevel(handle, config->siglevel);
- merge_siglevel(&config->siglevel, &config->localfilesiglevel);
- merge_siglevel(&config->siglevel, &config->remotefilesiglevel);
+ config->localfilesiglevel = merge_siglevel(config->siglevel,
+ config->localfilesiglevel, config->localfilesiglevel_mask);
+ config->remotefilesiglevel = merge_siglevel(config->siglevel,
+ config->remotefilesiglevel, config->remotefilesiglevel_mask);
+
alpm_option_set_local_file_siglevel(handle, config->localfilesiglevel);
alpm_option_set_remote_file_siglevel(handle, config->remotefilesiglevel);
+ for(i = config->repos; i; i = alpm_list_next(i)) {
+ register_repo(i->data);
+ }
+
if(config->xfercommand) {
alpm_option_set_fetchcb(handle, download_with_xfercommand);
} else if(!(alpm_capabilities() & ALPM_CAPABILITY_DOWNLOADER)) {
@@ -754,7 +798,7 @@ static int setup_libalpm(void)
ret = alpm_option_add_assumeinstalled(handle, dep);
if(ret) {
- pm_printf(ALPM_LOG_ERROR, _("Failed to pass assume installed entry to libalpm"));
+ pm_printf(ALPM_LOG_ERROR, _("Failed to pass %s entry to libalpm"), "assume-installed");
alpm_dep_free(dep);
return ret;
}
@@ -768,14 +812,9 @@ static int setup_libalpm(void)
* calling library methods.
*/
struct section_t {
- /* useful for all sections */
const char *name;
- int is_options;
- int parse_options;
- /* db section option gathering */
- alpm_list_t *servers;
- alpm_siglevel_t siglevel;
- alpm_db_usage_t usage;
+ config_repo_t *repo;
+ int depth;
};
static int process_usage(alpm_list_t *values, alpm_db_usage_t *usage,
@@ -816,6 +855,7 @@ static int _parse_repo(const char *key, char *value, const char *file,
int line, struct section_t *section)
{
int ret = 0;
+ config_repo_t *repo = section->repo;
if(strcmp(key, "Server") == 0) {
if(!value) {
@@ -823,7 +863,7 @@ static int _parse_repo(const char *key, char *value, const char *file,
file, line, key);
ret = 1;
} else {
- section->servers = alpm_list_add(section->servers, strdup(value));
+ repo->servers = alpm_list_add(repo->servers, strdup(value));
}
} else if(strcmp(key, "SigLevel") == 0) {
if(!value) {
@@ -833,10 +873,8 @@ static int _parse_repo(const char *key, char *value, const char *file,
alpm_list_t *values = NULL;
setrepeatingoption(value, "SigLevel", &values);
if(values) {
- if(section->siglevel == ALPM_SIG_USE_DEFAULT) {
- section->siglevel = config->siglevel;
- }
- ret = process_siglevel(values, &section->siglevel, file, line);
+ ret = process_siglevel(values, &repo->siglevel,
+ &repo->siglevel_mask, file, line);
FREELIST(values);
}
}
@@ -844,7 +882,7 @@ static int _parse_repo(const char *key, char *value, const char *file,
alpm_list_t *values = NULL;
setrepeatingoption(value, "Usage", &values);
if(values) {
- if(process_usage(values, &section->usage, file, line)) {
+ if(process_usage(values, &repo->usage, file, line)) {
FREELIST(values);
return 1;
}
@@ -853,67 +891,72 @@ static int _parse_repo(const char *key, char *value, const char *file,
} else {
pm_printf(ALPM_LOG_WARNING,
_("config file %s, line %d: directive '%s' in section '%s' not recognized.\n"),
- file, line, key, section->name);
+ file, line, key, repo->name);
}
return ret;
}
-/**
- * Wrap up a section once we have reached the end of it. This should be called
- * when a subsequent section is encountered, or when we have reached the end of
- * the root config file. Once called, all existing saved config pieces on the
- * section struct are freed.
- * @param section the current parsed and saved section data
- * @param parse_options whether we are parsing options or repo data
- * @return 0 on success, 1 on failure
- */
-static int finish_section(struct section_t *section)
-{
- int ret = 0;
- alpm_list_t *i;
- alpm_db_t *db;
+static int _parse_directive(const char *file, int linenum, const char *name,
+ char *key, char *value, void *data);
- pm_printf(ALPM_LOG_DEBUG, "config: finish section '%s'\n", section->name);
+static int process_include(const char *value, void *data,
+ const char *file, int linenum)
+{
+ glob_t globbuf;
+ int globret, ret = 0;
+ size_t gindex;
+ struct section_t *section = data;
+ static const int config_max_recursion = 10;
- /* parsing options (or nothing)- nothing to do except free the pieces */
- if(!section->name || section->parse_options || section->is_options) {
- goto cleanup;
+ if(value == NULL) {
+ pm_printf(ALPM_LOG_ERROR, _("config file %s, line %d: directive '%s' needs a value\n"),
+ file, linenum, "Include");
+ return 1;
}
- /* if we are not looking at options sections only, register a db */
- db = alpm_register_syncdb(config->handle, section->name, section->siglevel);
- if(db == NULL) {
- pm_printf(ALPM_LOG_ERROR, _("could not register '%s' database (%s)\n"),
- section->name, alpm_strerror(alpm_errno(config->handle)));
- ret = 1;
- goto cleanup;
+ if(section->depth >= config_max_recursion) {
+ pm_printf(ALPM_LOG_ERROR,
+ _("config parsing exceeded max recursion depth of %d.\n"),
+ config_max_recursion);
+ return 1;
}
- pm_printf(ALPM_LOG_DEBUG,
- "setting usage of %d for %s repoistory\n",
- section->usage == 0 ? ALPM_DB_USAGE_ALL : section->usage,
- section->name);
- alpm_db_set_usage(db, section->usage == 0 ? ALPM_DB_USAGE_ALL : section->usage);
-
- for(i = section->servers; i; i = alpm_list_next(i)) {
- char *value = i->data;
- if(_add_mirror(db, value) != 0) {
- pm_printf(ALPM_LOG_ERROR,
- _("could not add mirror '%s' to database '%s' (%s)\n"),
- value, section->name, alpm_strerror(alpm_errno(config->handle)));
- ret = 1;
- goto cleanup;
- }
- free(value);
+ section->depth++;
+
+ /* Ignore include failures... assume non-critical */
+ globret = glob(value, GLOB_NOCHECK, NULL, &globbuf);
+ switch(globret) {
+ case GLOB_NOSPACE:
+ pm_printf(ALPM_LOG_DEBUG,
+ "config file %s, line %d: include globbing out of space\n",
+ file, linenum);
+ break;
+ case GLOB_ABORTED:
+ pm_printf(ALPM_LOG_DEBUG,
+ "config file %s, line %d: include globbing read error for %s\n",
+ file, linenum, value);
+ break;
+ case GLOB_NOMATCH:
+ pm_printf(ALPM_LOG_DEBUG,
+ "config file %s, line %d: no include found for %s\n",
+ file, linenum, value);
+ break;
+ default:
+ for(gindex = 0; gindex < globbuf.gl_pathc; gindex++) {
+ pm_printf(ALPM_LOG_DEBUG, "config file %s, line %d: including %s\n",
+ file, linenum, globbuf.gl_pathv[gindex]);
+ ret = parse_ini(globbuf.gl_pathv[gindex], _parse_directive, data);
+ if(ret) {
+ goto cleanup;
+ }
+ }
+ break;
}
cleanup:
- alpm_list_free(section->servers);
- section->servers = NULL;
- section->siglevel = ALPM_SIG_USE_DEFAULT;
- section->name = NULL;
- section->usage = 0;
+ section->depth--;
+ globfree(&globbuf);
return ret;
}
@@ -921,16 +964,27 @@ static int _parse_directive(const char *file, int linenum, const char *name,
char *key, char *value, void *data)
{
struct section_t *section = data;
- if(!key && !value) {
- int ret = finish_section(section);
- pm_printf(ALPM_LOG_DEBUG, "config: new section '%s'\n", name);
+ if(!name && !key && !value) {
+ pm_printf(ALPM_LOG_ERROR, _("config file %s could not be read: %s\n"),
+ file, strerror(errno));
+ return 1;
+ } else if(!key && !value) {
section->name = name;
- if(name && strcmp(name, "options") == 0) {
- section->is_options = 1;
+ pm_printf(ALPM_LOG_DEBUG, "config: new section '%s'\n", name);
+ if(strcmp(name, "options") == 0) {
+ section->repo = NULL;
} else {
- section->is_options = 0;
+ section->repo = calloc(sizeof(config_repo_t), 1);
+ section->repo->name = strdup(name);
+ section->repo->siglevel = ALPM_SIG_USE_DEFAULT;
+ section->repo->usage = 0;
+ config->repos = alpm_list_add(config->repos, section->repo);
}
- return ret;
+ return 0;
+ }
+
+ if(strcmp(key, "Include") == 0) {
+ return process_include(value, data, file, linenum);
}
if(section->name == NULL) {
@@ -939,15 +993,13 @@ static int _parse_directive(const char *file, int linenum, const char *name,
return 1;
}
- if(section->parse_options && section->is_options) {
+ if(!section->repo) {
/* we are either in options ... */
return _parse_options(key, value, file, linenum);
- } else if(!section->parse_options && !section->is_options) {
+ } else {
/* ... or in a repo section */
return _parse_repo(key, value, file, linenum, section);
}
-
- return 0;
}
/** Parse a configuration file.
@@ -959,25 +1011,18 @@ int parseconfig(const char *file)
int ret;
struct section_t section;
memset(&section, 0, sizeof(struct section_t));
- section.siglevel = ALPM_SIG_USE_DEFAULT;
- section.usage = 0;
- /* the config parse is a two-pass affair. We first parse the entire thing for
- * the [options] section so we can get all default and path options set.
- * Next, we go back and parse everything but [options]. */
-
- /* call the real parseconfig function with a null section & db argument */
- pm_printf(ALPM_LOG_DEBUG, "parseconfig: options pass\n");
- section.parse_options = 1;
+ pm_printf(ALPM_LOG_DEBUG, "config: attempting to read file %s\n", file);
if((ret = parse_ini(file, _parse_directive, &section))) {
return ret;
}
+ pm_printf(ALPM_LOG_DEBUG, "config: finished parsing %s\n", file);
if((ret = setup_libalpm())) {
return ret;
}
- /* second pass, repo section parsing */
- pm_printf(ALPM_LOG_DEBUG, "parseconfig: repo pass\n");
- section.parse_options = 0;
- return parse_ini(file, _parse_directive, &section);
+ alpm_list_free_inner(config->repos, (alpm_list_fn_free) config_repo_free);
+ alpm_list_free(config->repos);
+ config->repos = NULL;
+ return ret;
}
/* vim: set noet: */
diff --git a/src/pacman/conf.h b/src/pacman/conf.h
index 3141e2c3..51224524 100644
--- a/src/pacman/conf.h
+++ b/src/pacman/conf.h
@@ -34,6 +34,14 @@ typedef struct __colstr_t {
const char *nocolor;
} colstr_t;
+typedef struct __config_repo_t {
+ char *name;
+ alpm_list_t *servers;
+ alpm_db_usage_t usage;
+ alpm_siglevel_t siglevel;
+ alpm_siglevel_t siglevel_mask;
+} config_repo_t;
+
typedef struct __config_t {
unsigned short op;
unsigned short quiet;
@@ -88,6 +96,10 @@ typedef struct __config_t {
alpm_siglevel_t localfilesiglevel;
alpm_siglevel_t remotefilesiglevel;
+ alpm_siglevel_t siglevel_mask;
+ alpm_siglevel_t localfilesiglevel_mask;
+ alpm_siglevel_t remotefilesiglevel_mask;
+
/* conf file options */
/* I Love Candy! */
unsigned short chomp;
@@ -114,6 +126,8 @@ typedef struct __config_t {
/* Color strings for output */
colstr_t colstr;
+
+ alpm_list_t *repos;
} config_t;
/* Operations */
@@ -208,6 +222,8 @@ void enable_colors(int colors);
config_t *config_new(void);
int config_free(config_t *oldconfig);
+void config_repo_free(config_repo_t *repo);
+
int config_set_arch(const char *arch);
int parseconfig(const char *file);
#endif /* _PM_CONF_H */
diff --git a/src/pacman/database.c b/src/pacman/database.c
index e858e0c8..7c396bc7 100644
--- a/src/pacman/database.c
+++ b/src/pacman/database.c
@@ -18,6 +18,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <dirent.h>
+#include <errno.h>
+#include <limits.h>
#include <stdio.h>
#include <alpm.h>
@@ -35,11 +38,12 @@
*
* @return 0 on success, 1 on failure
*/
-int pacman_database(alpm_list_t *targets)
+static int change_install_reason(alpm_list_t *targets)
{
alpm_list_t *i;
alpm_db_t *db_local;
- int retval = 0;
+ int ret = 0;
+
alpm_pkgreason_t reason;
if(targets == NULL) {
@@ -68,7 +72,7 @@ int pacman_database(alpm_list_t *targets)
if(!pkg || alpm_pkg_set_reason(pkg, reason)) {
pm_printf(ALPM_LOG_ERROR, _("could not set install reason for package %s (%s)\n"),
pkgname, alpm_strerror(alpm_errno(config->handle)));
- retval = 1;
+ ret = 1;
} else {
if(reason == ALPM_PKG_REASON_DEPEND) {
printf(_("%s: install reason has been set to 'installed as dependency'\n"), pkgname);
@@ -82,7 +86,213 @@ int pacman_database(alpm_list_t *targets)
if(trans_release() == -1) {
return 1;
}
- return retval;
+ return ret;
+}
+
+static int check_db_missing_deps(alpm_list_t *pkglist)
+{
+ alpm_list_t *data, *i;
+ int ret = 0;
+ /* check dependencies */
+ data = alpm_checkdeps(config->handle, NULL, NULL, pkglist, 0);
+ for(i = data; i; i = alpm_list_next(i)) {
+ alpm_depmissing_t *miss = i->data;
+ char *depstring = alpm_dep_compute_string(miss->depend);
+ pm_printf(ALPM_LOG_ERROR, "missing '%s' dependency for '%s'\n",
+ depstring, miss->target);
+ free(depstring);
+ ret++;
+ }
+ FREELIST(data);
+ return ret;
+}
+
+static int check_db_local_files(void)
+{
+ struct dirent *ent;
+ const char *dbpath;
+ char path[PATH_MAX];
+ int ret = 0;
+ DIR *dbdir;
+
+ dbpath = alpm_option_get_dbpath(config->handle);
+ snprintf(path, PATH_MAX, "%slocal", dbpath);
+ if(!(dbdir = opendir(path))) {
+ pm_printf(ALPM_LOG_ERROR, "could not open local database directory %s: %s\n",
+ path, strerror(errno));
+ return 1;
+ }
+
+ while((ent = readdir(dbdir)) != NULL) {
+ if(strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0
+ || strcmp(ent->d_name, "ALPM_DB_VERSION") == 0) {
+ continue;
+ }
+ /* check for expected db files in local database */
+ snprintf(path, PATH_MAX, "%slocal/%s/desc", dbpath, ent->d_name);
+ if(access(path, F_OK)) {
+ pm_printf(ALPM_LOG_ERROR, "'%s': description file is missing\n", ent->d_name);
+ ret++;
+ }
+ snprintf(path, PATH_MAX, "%slocal/%s/files", dbpath, ent->d_name);
+ if(access(path, F_OK)) {
+ pm_printf(ALPM_LOG_ERROR, "'%s': file list is missing\n", ent->d_name);
+ ret++;
+ }
+ }
+ closedir(dbdir);
+
+ return ret;
+}
+
+static int check_db_local_package_conflicts(alpm_list_t *pkglist)
+{
+ alpm_list_t *data, *i;
+ int ret = 0;
+ /* check conflicts */
+ data = alpm_checkconflicts(config->handle, pkglist);
+ for(i = data; i; i = i->next) {
+ alpm_conflict_t *conflict = i->data;
+ pm_printf(ALPM_LOG_ERROR, "'%s' conflicts with '%s'\n",
+ conflict->package1, conflict->package2);
+ ret++;
+ }
+ FREELIST(data);
+ return ret;
+}
+
+struct fileitem {
+ alpm_file_t *file;
+ alpm_pkg_t *pkg;
+};
+
+static int fileitem_cmp(const void *p1, const void *p2)
+{
+ const struct fileitem * fi1 = p1;
+ const struct fileitem * fi2 = p2;
+ return strcmp(fi1->file->name, fi2->file->name);
+}
+
+static int check_db_local_filelist_conflicts(alpm_list_t *pkglist)
+{
+ alpm_list_t *i;
+ int ret = 0;
+ size_t list_size = 4096;
+ size_t offset = 0, j;
+ struct fileitem *all_files;
+ struct fileitem *prev_fileitem = NULL;
+
+ all_files = malloc(list_size * sizeof(struct fileitem));
+
+ for(i = pkglist; i; i = i->next) {
+ alpm_pkg_t *pkg = i->data;
+ alpm_filelist_t *filelist = alpm_pkg_get_files(pkg);
+ for(j = 0; j < filelist->count; j++) {
+ alpm_file_t *file = filelist->files + j;
+ /* only add files, not directories, to our big list */
+ if(file->name[strlen(file->name) - 1] == '/') {
+ continue;
+ }
+
+ /* do we need to reallocate and grow our array? */
+ if(offset >= list_size) {
+ struct fileitem *new_files;
+ new_files = realloc(all_files, list_size * 2 * sizeof(struct fileitem));
+ if(!new_files) {
+ free(all_files);
+ return 1;
+ }
+ all_files = new_files;
+ list_size *= 2;
+ }
+
+ /* we can finally add it to the list */
+ all_files[offset].file = file;
+ all_files[offset].pkg = pkg;
+ offset++;
+ }
+ }
+
+ /* now sort the list so we can find duplicates */
+ qsort(all_files, offset, sizeof(struct fileitem), fileitem_cmp);
+
+ /* do a 'uniq' style check on the list */
+ for(j = 0; j < offset; j++) {
+ struct fileitem *fileitem = all_files + j;
+ if(prev_fileitem && fileitem_cmp(prev_fileitem, fileitem) == 0) {
+ pm_printf(ALPM_LOG_ERROR, "file owned by '%s' and '%s': '%s'\n",
+ alpm_pkg_get_name(prev_fileitem->pkg),
+ alpm_pkg_get_name(fileitem->pkg),
+ fileitem->file->name);
+ }
+ prev_fileitem = fileitem;
+ }
+
+ free(all_files);
+ return ret;
+}
+
+/**
+ * @brief Check 'local' package database for consistency
+ *
+ * @return 0 on success, >=1 on failure
+ */
+static int check_db_local(void) {
+ int ret = 0;
+ alpm_db_t *db = NULL;
+ alpm_list_t *pkglist;
+
+ ret = check_db_local_files();
+ if(ret) {
+ return ret;
+ }
+
+ db = alpm_get_localdb(config->handle);
+ pkglist = alpm_db_get_pkgcache(db);
+ ret += check_db_missing_deps(pkglist);
+ ret += check_db_local_package_conflicts(pkglist);
+ ret += check_db_local_filelist_conflicts(pkglist);
+
+ return 0;
+}
+
+/**
+ * @brief Check 'sync' package databases for consistency
+ *
+ * @return 0 on success, >=1 on failure
+ */
+static int check_db_sync(void) {
+ int ret = 0;
+ alpm_list_t *i, *dblist, *pkglist, *syncpkglist = NULL;
+
+ dblist = alpm_get_syncdbs(config->handle);
+ for(i = dblist; i; i = alpm_list_next(i)) {
+ pkglist = alpm_db_get_pkgcache(i->data);
+ syncpkglist = alpm_list_join(syncpkglist, alpm_list_copy(pkglist));
+ }
+ ret = check_db_missing_deps(syncpkglist);
+
+ alpm_list_free(syncpkglist);
+ return ret;
+}
+
+int pacman_database(alpm_list_t *targets)
+{
+ int ret = 0;
+
+ if(config->op_q_check) {
+ if(config->op_q_check == 1) {
+ ret = check_db_local();
+ } else {
+ ret = check_db_sync();
+ }
+ }
+
+ if(config->flags & (ALPM_TRANS_FLAG_ALLDEPS | ALPM_TRANS_FLAG_ALLEXPLICIT)) {
+ ret = change_install_reason(targets);
+ }
+
+ return ret;
}
/* vim: set noet: */
diff --git a/src/pacman/ini.c b/src/pacman/ini.c
index 2eb32302..ca1363f1 100644
--- a/src/pacman/ini.c
+++ b/src/pacman/ini.c
@@ -18,7 +18,6 @@
*/
#include <errno.h>
-#include <glob.h>
#include <limits.h>
#include <string.h> /* strdup */
@@ -27,43 +26,38 @@
#include "ini.h"
#include "util.h"
-static const int ini_max_recursion = 10;
-
/**
- * @brief INI parser backend.
+ * @brief Parse a pacman-style INI config file.
*
* @param file path to the config file
* @param cb callback for key/value pairs
* @param data caller defined data to be passed to the callback
- * @param section_name the name of the current section
- * @param line buffer to read into, must be at least PATH_MAX long
- * @param depth recursion depth, should initially be 0
*
- * @return 0 on success, 1 on parsing errors, the callback return value
- * otherwise
+ * @return the callback return value
+ *
+ * @note The callback will be called at the beginning of each section with an
+ * empty key and value and for each key/value pair.
+ *
+ * @note If the parser encounters an error the callback will be called with
+ * section, key, and value set to NULL and errno set by fopen, fgets, or
+ * strdup.
+ *
+ * @note The @a key and @a value passed to @ cb will be overwritten between
+ * calls. The section name will remain valid until after @a cb is called to
+ * begin a new section.
+ *
+ * @note Parsing will immediately stop if the callback returns non-zero.
*/
-static int _parse_ini(const char *file, ini_parser_fn cb, void *data,
- char **section_name, char *line, int depth)
+int parse_ini(const char *file, ini_parser_fn cb, void *data)
{
+ char line[PATH_MAX], *section_name = NULL;
FILE *fp = NULL;
int linenum = 0;
int ret = 0;
- if(depth >= ini_max_recursion) {
- pm_printf(ALPM_LOG_ERROR,
- _("config parsing exceeded max recursion depth of %d.\n"),
- ini_max_recursion);
- ret = 1;
- goto cleanup;
- }
-
- pm_printf(ALPM_LOG_DEBUG, "config: attempting to read file %s\n", file);
fp = fopen(file, "r");
if(fp == NULL) {
- pm_printf(ALPM_LOG_ERROR, _("config file %s could not be read: %s\n"),
- file, strerror(errno));
- ret = 1;
- goto cleanup;
+ return cb(file, 0, NULL, NULL, NULL, data);
}
while(safe_fgets(line, PATH_MAX, fp)) {
@@ -85,20 +79,13 @@ static int _parse_ini(const char *file, ini_parser_fn cb, void *data,
if(line[0] == '[' && line[line_len - 1] == ']') {
char *name;
- /* only possibility here is a line == '[]' */
- if(line_len <= 2) {
- pm_printf(ALPM_LOG_ERROR, _("config file %s, line %d: bad section name.\n"),
- file, linenum);
- ret = 1;
- goto cleanup;
- }
/* new config section, skip the '[' */
name = strdup(line + 1);
name[line_len - 2] = '\0';
ret = cb(file, linenum, name, NULL, NULL, data);
- free(*section_name);
- *section_name = name;
+ free(section_name);
+ section_name = name;
/* we're at a new section; perform any post-actions for the prior */
if(ret) {
@@ -115,103 +102,15 @@ static int _parse_ini(const char *file, ini_parser_fn cb, void *data,
strtrim(key);
strtrim(value);
- if(key == NULL) {
- pm_printf(ALPM_LOG_ERROR, _("config file %s, line %d: syntax error in config file- missing key.\n"),
- file, linenum);
- ret = 1;
- goto cleanup;
- }
- /* Include is allowed in both options and repo sections */
- if(strcmp(key, "Include") == 0) {
- glob_t globbuf;
- int globret;
- size_t gindex;
-
- if(value == NULL) {
- pm_printf(ALPM_LOG_ERROR, _("config file %s, line %d: directive '%s' needs a value\n"),
- file, linenum, key);
- ret = 1;
- goto cleanup;
- }
- /* Ignore include failures... assume non-critical */
- globret = glob(value, GLOB_NOCHECK, NULL, &globbuf);
- switch(globret) {
- case GLOB_NOSPACE:
- pm_printf(ALPM_LOG_DEBUG,
- "config file %s, line %d: include globbing out of space\n",
- file, linenum);
- break;
- case GLOB_ABORTED:
- pm_printf(ALPM_LOG_DEBUG,
- "config file %s, line %d: include globbing read error for %s\n",
- file, linenum, value);
- break;
- case GLOB_NOMATCH:
- pm_printf(ALPM_LOG_DEBUG,
- "config file %s, line %d: no include found for %s\n",
- file, linenum, value);
- break;
- default:
- for(gindex = 0; gindex < globbuf.gl_pathc; gindex++) {
- pm_printf(ALPM_LOG_DEBUG, "config file %s, line %d: including %s\n",
- file, linenum, globbuf.gl_pathv[gindex]);
- ret =_parse_ini(globbuf.gl_pathv[gindex], cb, data,
- section_name, line, depth + 1);
- if(ret) {
- globfree(&globbuf);
- goto cleanup;
- }
- }
- break;
- }
- globfree(&globbuf);
- continue;
- }
- if((ret = cb(file, linenum, *section_name, key, value, data)) != 0) {
+ if((ret = cb(file, linenum, section_name, key, value, data)) != 0) {
goto cleanup;
}
}
- if(depth == 0) {
- ret = cb(NULL, 0, NULL, NULL, NULL, data);
- }
-
cleanup:
- if(fp) {
- fclose(fp);
- }
- if(depth == 0) {
- free(*section_name);
- *section_name = NULL;
- }
- pm_printf(ALPM_LOG_DEBUG, "config: finished parsing %s\n", file);
+ fclose(fp);
+ free(section_name);
return ret;
}
-/**
- * @brief Parse a pacman-style INI config file.
- *
- * @param file path to the config file
- * @param cb callback for key/value pairs
- * @param data caller defined data to be passed to the callback
- *
- * @return 0 on success, 1 on parsing errors, the callback return value
- * otherwise
- *
- * @note The callback will be called at the beginning of each section with an
- * empty key and value, for each key/value pair, and when parsing is complete
- * with all arguments except @a data empty.
- *
- * @note The @a key and @a value passed to @ cb will be overwritten between
- * calls. The section name will remain valid until after @a cb is called to
- * begin a new section.
- *
- * @note Parsing will immediately stop if the callback returns non-zero.
- */
-int parse_ini(const char *file, ini_parser_fn cb, void *data)
-{
- char *section_name = NULL, line[PATH_MAX];
- return _parse_ini(file, cb, data, &section_name, line, 0);
-}
-
/* vim: set noet: */
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 6f05c68c..792c9946 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -169,6 +169,7 @@ static void usage(int op, const char * const myname)
printf("%s:\n", str_opt);
addlist(_(" --asdeps mark packages as non-explicitly installed\n"));
addlist(_(" --asexplicit mark packages as explicitly installed\n"));
+ addlist(_(" -k, --check test local database for validity (-kk for sync databases)\n"));
} else if(op == PM_OP_DEPTEST) {
printf("%s: %s {-T --deptest} [%s] [%s]\n", str_usg, myname, str_opt, str_pkg);
printf("%s:\n", str_opt);
@@ -484,9 +485,18 @@ static int parsearg_global(int opt)
static int parsearg_database(int opt)
{
switch(opt) {
- case OP_ASDEPS: config->flags |= ALPM_TRANS_FLAG_ALLDEPS; break;
- case OP_ASEXPLICIT: config->flags |= ALPM_TRANS_FLAG_ALLEXPLICIT; break;
- default: return 1;
+ case OP_ASDEPS:
+ config->flags |= ALPM_TRANS_FLAG_ALLDEPS;
+ break;
+ case OP_ASEXPLICIT:
+ config->flags |= ALPM_TRANS_FLAG_ALLEXPLICIT;
+ break;
+ case OP_CHECK:
+ case 'k':
+ (config->op_q_check)++;
+ break;
+ default:
+ return 1;
}
return 0;
}
@@ -496,6 +506,13 @@ static void checkargs_database(void)
invalid_opt(config->flags & ALPM_TRANS_FLAG_ALLDEPS
&& config->flags & ALPM_TRANS_FLAG_ALLEXPLICIT,
"--asdeps", "--asexplicit");
+
+ if(config->op_q_check) {
+ invalid_opt(config->flags & ALPM_TRANS_FLAG_ALLDEPS,
+ "--asdeps", "--check");
+ invalid_opt(config->flags & ALPM_TRANS_FLAG_ALLEXPLICIT,
+ "--asexplicit", "--check");
+ }
}
static int parsearg_query(int opt)
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 36f4414a..8720ba11 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -105,7 +105,7 @@ int needs_root(void)
{
switch(config->op) {
case PM_OP_DATABASE:
- return 1;
+ return !config->op_q_check;
case PM_OP_UPGRADE:
case PM_OP_REMOVE:
return !config->print;
@@ -284,6 +284,7 @@ void indentprint(const char *str, unsigned short indent, unsigned short cols)
cidx = indent;
if(!p || !len) {
+ free(wcstr);
return;
}
diff --git a/src/util/.gitignore b/src/util/.gitignore
index 1813506b..202fb753 100644
--- a/src/util/.gitignore
+++ b/src/util/.gitignore
@@ -6,8 +6,6 @@ pacsort
pacsort.exe
pactree
pactree.exe
-testdb
-testdb.exe
testpkg
testpkg.exe
vercmp
diff --git a/src/util/Makefile.am b/src/util/Makefile.am
index a0075887..25c025b5 100644
--- a/src/util/Makefile.am
+++ b/src/util/Makefile.am
@@ -4,7 +4,7 @@ dbpath = ${localstatedir}/lib/pacman/
gpgdir = ${sysconfdir}/pacman.d/gnupg/
cachedir = ${localstatedir}/cache/pacman/pkg/
-bin_PROGRAMS = vercmp testpkg testdb cleanupdelta pacsort pactree
+bin_PROGRAMS = vercmp testpkg cleanupdelta pacsort pactree
AM_CPPFLAGS = \
-imacros $(top_builddir)/config.h \
@@ -26,9 +26,6 @@ pacsort_LDADD = $(top_builddir)/lib/libalpm/.libs/libalpm.la
pactree_SOURCES = pactree.c
pactree_LDADD = $(top_builddir)/lib/libalpm/.libs/libalpm.la
-testdb_SOURCES = testdb.c
-testdb_LDADD = $(top_builddir)/lib/libalpm/.libs/libalpm.la
-
testpkg_SOURCES = testpkg.c
testpkg_LDADD = $(top_builddir)/lib/libalpm/.libs/libalpm.la
diff --git a/src/util/pacsort.c b/src/util/pacsort.c
index 665f2180..c59ba131 100644
--- a/src/util/pacsort.c
+++ b/src/util/pacsort.c
@@ -227,6 +227,7 @@ static struct input_t *input_new(const char *path, int pathlen)
in->data = strndup(path, pathlen);
if(in->data == NULL) {
+ free(in);
return NULL;
}
diff --git a/src/util/testdb.c b/src/util/testdb.c
deleted file mode 100644
index cd8c4d83..00000000
--- a/src/util/testdb.c
+++ /dev/null
@@ -1,297 +0,0 @@
-/*
- * testdb.c : Test a pacman local database for validity
- *
- * Copyright (c) 2007-2014 Pacman Development Team <pacman-dev@archlinux.org>
- * Copyright (c) 2007 by Aaron Griffin <aaronmgriffin@gmail.com>
- *
- * 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
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
-
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include <string.h>
-#include <dirent.h>
-
-#include <alpm.h>
-#include <alpm_list.h>
-
-alpm_handle_t *handle = NULL;
-
-static void cleanup(int signum)
-{
- if(handle && alpm_release(handle) == -1) {
- fprintf(stderr, "error releasing alpm\n");
- }
-
- exit(signum);
-}
-
-__attribute__((format(printf, 2, 0)))
-static void output_cb(alpm_loglevel_t level, const char *fmt, va_list args)
-{
- if(strlen(fmt)) {
- switch(level) {
- case ALPM_LOG_ERROR: printf("error: "); break;
- case ALPM_LOG_WARNING: printf("warning: "); break;
- default: return;
- }
- vprintf(fmt, args);
- }
-}
-
-static int check_localdb_files(void)
-{
- struct dirent *ent;
- const char *dbpath;
- char path[4096];
- int ret = 0;
- DIR *dir;
-
- dbpath = alpm_option_get_dbpath(handle);
- snprintf(path, sizeof(path), "%slocal", dbpath);
- if(!(dir = opendir(path))) {
- fprintf(stderr, "error : '%s' : %s\n", path, strerror(errno));
- return 1;
- }
-
- while((ent = readdir(dir)) != NULL) {
- if(strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0
- || strcmp(ent->d_name, "ALPM_DB_VERSION") == 0) {
- continue;
- }
- /* check for known db files in local database */
- snprintf(path, sizeof(path), "%slocal/%s/desc", dbpath, ent->d_name);
- if(access(path, F_OK)) {
- printf("'%s': description file is missing\n", ent->d_name);
- ret++;
- }
- snprintf(path, sizeof(path), "%slocal/%s/files", dbpath, ent->d_name);
- if(access(path, F_OK)) {
- printf("'%s': file list is missing\n", ent->d_name);
- ret++;
- }
- }
- if(closedir(dir)) {
- fprintf(stderr, "error closing dbpath : %s\n", strerror(errno));
- return 1;
- }
-
- return ret;
-}
-
-static int check_deps(alpm_list_t *pkglist)
-{
- alpm_list_t *data, *i;
- int ret = 0;
- /* check dependencies */
- data = alpm_checkdeps(handle, NULL, NULL, pkglist, 0);
- for(i = data; i; i = alpm_list_next(i)) {
- alpm_depmissing_t *miss = i->data;
- char *depstring = alpm_dep_compute_string(miss->depend);
- printf("missing '%s' dependency for '%s'\n", depstring, miss->target);
- free(depstring);
- ret++;
- }
- FREELIST(data);
- return ret;
-}
-
-static int check_conflicts(alpm_list_t *pkglist)
-{
- alpm_list_t *data, *i;
- int ret = 0;
- /* check conflicts */
- data = alpm_checkconflicts(handle, pkglist);
- for(i = data; i; i = i->next) {
- alpm_conflict_t *conflict = i->data;
- printf("'%s' conflicts with '%s'\n",
- conflict->package1, conflict->package2);
- ret++;
- }
- FREELIST(data);
- return ret;
-}
-
-struct fileitem {
- alpm_file_t *file;
- alpm_pkg_t *pkg;
-};
-
-static int fileitem_cmp(const void *p1, const void *p2)
-{
- const struct fileitem * fi1 = p1;
- const struct fileitem * fi2 = p2;
- return strcmp(fi1->file->name, fi2->file->name);
-}
-
-static int check_filelists(alpm_list_t *pkglist)
-{
- alpm_list_t *i;
- int ret = 0;
- size_t list_size = 4096;
- size_t offset = 0, j;
- struct fileitem *all_files;
- struct fileitem *prev_fileitem = NULL;
-
- all_files = malloc(list_size * sizeof(struct fileitem));
-
- for(i = pkglist; i; i = i->next) {
- alpm_pkg_t *pkg = i->data;
- alpm_filelist_t *filelist = alpm_pkg_get_files(pkg);
- for(j = 0; j < filelist->count; j++) {
- alpm_file_t *file = filelist->files + j;
- /* only add files, not directories, to our big list */
- if(file->name[strlen(file->name) - 1] == '/') {
- continue;
- }
-
- /* do we need to reallocate and grow our array? */
- if(offset >= list_size) {
- struct fileitem *new_files;
- new_files = realloc(all_files, list_size * 2 * sizeof(struct fileitem));
- if(!new_files) {
- free(all_files);
- return 1;
- }
- all_files = new_files;
- list_size *= 2;
- }
-
- /* we can finally add it to the list */
- all_files[offset].file = file;
- all_files[offset].pkg = pkg;
- offset++;
- }
- }
-
- /* now sort the list so we can find duplicates */
- qsort(all_files, offset, sizeof(struct fileitem), fileitem_cmp);
-
- /* do a 'uniq' style check on the list */
- for(j = 0; j < offset; j++) {
- struct fileitem *fileitem = all_files + j;
- if(prev_fileitem && fileitem_cmp(prev_fileitem, fileitem) == 0) {
- printf("file owned by '%s' and '%s': '%s'\n",
- alpm_pkg_get_name(prev_fileitem->pkg),
- alpm_pkg_get_name(fileitem->pkg),
- fileitem->file->name);
- }
- prev_fileitem = fileitem;
- }
-
- free(all_files);
- return ret;
-}
-
-static int check_localdb(void)
-{
- int ret = 0;
- alpm_db_t *db = NULL;
- alpm_list_t *pkglist;
-
- ret = check_localdb_files();
- if(ret) {
- return ret;
- }
-
- db = alpm_get_localdb(handle);
- pkglist = alpm_db_get_pkgcache(db);
- ret += check_deps(pkglist);
- ret += check_conflicts(pkglist);
- ret += check_filelists(pkglist);
- return ret;
-}
-
-static int check_syncdbs(alpm_list_t *dbnames)
-{
- int ret = 0;
- alpm_db_t *db = NULL;
- alpm_list_t *i, *pkglist, *syncpkglist = NULL;
- const alpm_siglevel_t level = ALPM_SIG_DATABASE | ALPM_SIG_DATABASE_OPTIONAL;
-
- for(i = dbnames; i; i = alpm_list_next(i)) {
- const char *dbname = i->data;
- db = alpm_register_syncdb(handle, dbname, level);
- if(db == NULL) {
- fprintf(stderr, "error: could not register sync database (%s)\n",
- alpm_strerror(alpm_errno(handle)));
- ret = 1;
- goto cleanup;
- }
- pkglist = alpm_db_get_pkgcache(db);
- syncpkglist = alpm_list_join(syncpkglist, alpm_list_copy(pkglist));
- }
- ret += check_deps(syncpkglist);
-
-cleanup:
- alpm_list_free(syncpkglist);
- return ret;
-}
-
-static void usage(void)
-{
- fprintf(stderr, "testdb (pacman) v" PACKAGE_VERSION "\n\n"
- "Test a pacman local database for validity.\n\n"
- "Usage: testdb [options]\n\n"
- " -b <pacman db> : check the local database\n"
- " -b <pacman db> core extra ... : check the listed sync databases\n");
- exit(1);
-}
-
-int main(int argc, char *argv[])
-{
- int errors = 0;
- alpm_errno_t err;
- const char *dbpath = DBPATH;
- int a = 1;
- alpm_list_t *dbnames = NULL;
-
- while(a < argc) {
- if(strcmp(argv[a], "-b") == 0) {
- if(++a < argc) {
- dbpath = argv[a];
- } else {
- usage();
- }
- } else if(strcmp(argv[a], "-h") == 0 ||
- strcmp(argv[a], "--help") == 0 ) {
- usage();
- } else {
- dbnames = alpm_list_add(dbnames, argv[a]);
- }
- a++;
- }
-
- handle = alpm_initialize(ROOTDIR, dbpath, &err);
- if(!handle) {
- fprintf(stderr, "cannot initialize alpm: %s\n", alpm_strerror(err));
- return EXIT_FAILURE;
- }
-
- /* let us get log messages from libalpm */
- alpm_option_set_logcb(handle, output_cb);
-
- if(!dbnames) {
- errors = check_localdb();
- } else {
- errors = check_syncdbs(dbnames);
- alpm_list_free(dbnames);
- }
-
- cleanup(errors > 0);
-}
-
-/* vim: set noet: */
diff --git a/test/pacman/README b/test/pacman/README
index 8d8354ab..6c601b2f 100644
--- a/test/pacman/README
+++ b/test/pacman/README
@@ -310,7 +310,6 @@ its DEPENDS field.
FILE_TYPE=path/to/file|type (possible types: dir, file, link)
FILE_PACNEW=path/to/file
FILE_PACSAVE=path/to/file
- FILE_PACORIG=path/to/file
Example:
FILE_EXIST=etc/test.conf
diff --git a/test/pacman/pmrule.py b/test/pacman/pmrule.py
index c2336c5d..8e6b2c0c 100644
--- a/test/pacman/pmrule.py
+++ b/test/pacman/pmrule.py
@@ -146,9 +146,6 @@ class pmrule(object):
elif case == "PACNEW":
if not os.path.isfile("%s.pacnew" % filename):
success = 0
- elif case == "PACORIG":
- if not os.path.isfile("%s.pacorig" % filename):
- success = 0
elif case == "PACSAVE":
if not os.path.isfile("%s.pacsave" % filename):
success = 0
diff --git a/test/pacman/tests/upgrade015.py b/test/pacman/tests/upgrade015.py
index ea6046cb..64fe2813 100644
--- a/test/pacman/tests/upgrade015.py
+++ b/test/pacman/tests/upgrade015.py
@@ -12,4 +12,3 @@ self.addrule("PACMAN_RETCODE=0")
self.addrule("PKG_EXIST=dummy")
self.addrule("FILE_MODIFIED=etc/dummy.conf")
self.addrule("!FILE_PACNEW=etc/dummy.conf")
-self.addrule("!FILE_PACORIG=etc/dummy.conf")
diff --git a/test/pacman/tests/upgrade016.py b/test/pacman/tests/upgrade016.py
index b6b3f3ae..ddf57e8c 100644
--- a/test/pacman/tests/upgrade016.py
+++ b/test/pacman/tests/upgrade016.py
@@ -11,6 +11,5 @@ self.args = "-U --force %s" % p.filename()
self.addrule("PACMAN_RETCODE=0")
self.addrule("PKG_EXIST=dummy")
-self.addrule("FILE_MODIFIED=etc/dummy.conf")
-self.addrule("!FILE_PACNEW=etc/dummy.conf")
-self.addrule("FILE_PACORIG=etc/dummy.conf")
+self.addrule("!FILE_MODIFIED=etc/dummy.conf")
+self.addrule("FILE_PACNEW=etc/dummy.conf")
diff --git a/test/pacman/tests/upgrade027.py b/test/pacman/tests/upgrade027.py
index 99087f34..3dd694af 100644
--- a/test/pacman/tests/upgrade027.py
+++ b/test/pacman/tests/upgrade027.py
@@ -18,5 +18,4 @@ self.addrule("PACMAN_RETCODE=0")
self.addrule("PKG_VERSION=dummy|1.0-2")
self.addrule("FILE_PACNEW=etc/dummy.conf")
self.addrule("!FILE_PACSAVE=etc/dummy.conf")
-self.addrule("!FILE_PACORIG=etc/dummy.conf")
self.addrule("FILE_EXIST=etc/dummy.conf")
diff --git a/test/pacman/tests/upgrade028.py b/test/pacman/tests/upgrade028.py
index 18a10f57..1e31aa31 100644
--- a/test/pacman/tests/upgrade028.py
+++ b/test/pacman/tests/upgrade028.py
@@ -18,5 +18,4 @@ self.addrule("PACMAN_RETCODE=0")
self.addrule("PKG_VERSION=dummy|1.0-2")
self.addrule("!FILE_PACNEW=etc/dummy.conf")
self.addrule("!FILE_PACSAVE=etc/dummy.conf")
-self.addrule("!FILE_PACORIG=etc/dummy.conf")
self.addrule("FILE_EXIST=etc/dummy.conf")
diff --git a/test/pacman/tests/upgrade029.py b/test/pacman/tests/upgrade029.py
index c308f426..eef5c700 100644
--- a/test/pacman/tests/upgrade029.py
+++ b/test/pacman/tests/upgrade029.py
@@ -20,5 +20,4 @@ self.addrule("PACMAN_RETCODE=1")
self.addrule("PKG_VERSION=dummy|1.0-1")
self.addrule("!FILE_PACNEW=etc/dummy.conf")
self.addrule("!FILE_PACSAVE=etc/dummy.conf")
-self.addrule("!FILE_PACORIG=etc/dummy.conf")
self.addrule("FILE_EXIST=etc/dummy.conf")
diff --git a/test/scripts/Makefile.am b/test/scripts/Makefile.am
index 8d6bc842..ed1a9511 100644
--- a/test/scripts/Makefile.am
+++ b/test/scripts/Makefile.am
@@ -1,6 +1,7 @@
check_SCRIPTS = \
parseopts_test.sh \
pacman-db-upgrade-v9.py \
+ makepkg-template_test.sh \
human_to_size_test.sh
noinst_SCRIPTS = $(check_SCRIPTS)
diff --git a/test/scripts/human_to_size_test.sh b/test/scripts/human_to_size_test.sh
index dfa01f72..6334495f 100755
--- a/test/scripts/human_to_size_test.sh
+++ b/test/scripts/human_to_size_test.sh
@@ -1,82 +1,57 @@
#!/bin/bash
-declare -i testcount=0 fail=0 pass=0 total=15
+source "$(dirname "$0")"/../tap.sh || exit 1
# source the library function
lib=${1:-${PMTEST_SCRIPTLIB_DIR}human_to_size.sh}
if [[ -z $lib || ! -f $lib ]]; then
- printf "Bail out! human_to_size library (%s) could not be located\n" "${lib}"
+ tap_bail "human_to_size library (%s) could not be located" "${lib}"
exit 1
fi
. "$lib"
if ! type -t human_to_size &>/dev/null; then
- printf "Bail out! human_to_size function not found\n"
+ tap_bail "human_to_size function not found"
exit 1
fi
-parse_hts() {
- local input=$1 expected=$2 result
-
- (( ++testcount ))
-
- result=$(human_to_size "$1")
- if [[ $result = "$expected" ]]; then
- (( ++pass ))
- printf "ok %d - %s\n" "$testcount" "$input"
- else
- (( ++fail ))
- printf "not ok %d - %s\n" "$testcount" "$input"
- printf '# [TEST %3s]: FAIL\n' "$testcount"
- printf '# input: %s\n' "$input"
- printf '# output: %s\n' "$result"
- printf '# expected: %s\n' "$expected"
- fi
+tap_parse_hts() {
+ local input=$1 expected=$2
+ tap_is_str "$(human_to_size "$input")" "$expected" "$input"
}
-summarize() {
- if (( !fail )); then
- printf '# All %s tests successful\n\n' "$testcount"
- exit 0
- else
- printf '# %s of %s tests failed\n\n' "$fail" "$testcount"
- exit 1
- fi
-}
-trap 'summarize' EXIT
-
-printf '# Beginning human_to_size tests\n'
+tap_plan 15
-echo "1..$total"
+# tap_parse_hts <input> <expected output>
-# parse_hts <input> <expected output>
+tap_parse_hts '1MiB' 1048576
-parse_hts '1MiB' 1048576
+tap_parse_hts '10XiB' ''
-parse_hts '10XiB' ''
+tap_parse_hts '10 MiB' 10485760
-parse_hts '10 MiB' 10485760
+tap_parse_hts '10 XiB' ''
-parse_hts '10 XiB' ''
+tap_parse_hts '.1 TiB' 109951162778
-parse_hts '.1 TiB' 109951162778
+tap_parse_hts ' -3 KiB ' -3072
-parse_hts ' -3 KiB ' -3072
+tap_parse_hts 'foo3KiB' ''
-parse_hts 'foo3KiB' ''
+tap_parse_hts '3KiBfoo' ''
-parse_hts '3KiBfoo' ''
+tap_parse_hts '3kib' ''
-parse_hts '3kib' ''
+tap_parse_hts '+1KiB' 1024
-parse_hts '+1KiB' 1024
+tap_parse_hts '+1.0 KiB' 1024
-parse_hts '+1.0 KiB' 1024
+tap_parse_hts '1MB' 1000000
-parse_hts '1MB' 1000000
+tap_parse_hts '1M' 1048576
-parse_hts '1M' 1048576
+tap_parse_hts ' 1 G ' 1073741824
-parse_hts ' 1 G ' 1073741824
+tap_parse_hts '1Q' ''
-parse_hts '1Q' ''
+# vim: set noet:
diff --git a/test/scripts/makepkg-template-tests/invalid-key/PKGBUILD b/test/scripts/makepkg-template-tests/invalid-key/PKGBUILD
new file mode 100644
index 00000000..02bfadcc
--- /dev/null
+++ b/test/scripts/makepkg-template-tests/invalid-key/PKGBUILD
@@ -0,0 +1 @@
+# template input; []³|>=bar;
diff --git a/test/scripts/makepkg-template-tests/invalid-key/testcase-config b/test/scripts/makepkg-template-tests/invalid-key/testcase-config
new file mode 100644
index 00000000..4e4725e2
--- /dev/null
+++ b/test/scripts/makepkg-template-tests/invalid-key/testcase-config
@@ -0,0 +1,11 @@
+arguments+=()
+expected_exitcode=255
+
+# set IFS="" if you want trailing new lines, otherwise remove it
+IFS="" read -d '' expected_output <<'EOF'
+invalid key/value pair
+./makepkg-template-tests/invalid-key/PKGBUILD:1: # template input; []³|>=bar;
+EOF
+
+IFS="" read -d '' expected_result <<'EOF'
+EOF
diff --git a/test/scripts/makepkg-template-tests/invalid-template-line-missing-name/PKGBUILD b/test/scripts/makepkg-template-tests/invalid-template-line-missing-name/PKGBUILD
new file mode 100644
index 00000000..d0a20c18
--- /dev/null
+++ b/test/scripts/makepkg-template-tests/invalid-template-line-missing-name/PKGBUILD
@@ -0,0 +1 @@
+# template input;
diff --git a/test/scripts/makepkg-template-tests/invalid-template-line-missing-name/testcase-config b/test/scripts/makepkg-template-tests/invalid-template-line-missing-name/testcase-config
new file mode 100644
index 00000000..6bfda327
--- /dev/null
+++ b/test/scripts/makepkg-template-tests/invalid-template-line-missing-name/testcase-config
@@ -0,0 +1,11 @@
+arguments+=()
+expected_exitcode=255
+
+# set IFS="" if you want trailing new lines, otherwise remove it
+IFS="" read -d '' expected_output <<'EOF'
+invalid template line: can't find template name
+./makepkg-template-tests/invalid-template-line-missing-name/PKGBUILD:1: # template input;
+EOF
+
+IFS="" read -d '' expected_result <<'EOF'
+EOF
diff --git a/test/scripts/makepkg-template-tests/invalid-template-line-unknown-marker/PKGBUILD b/test/scripts/makepkg-template-tests/invalid-template-line-unknown-marker/PKGBUILD
new file mode 100644
index 00000000..645ea371
--- /dev/null
+++ b/test/scripts/makepkg-template-tests/invalid-template-line-unknown-marker/PKGBUILD
@@ -0,0 +1,9 @@
+pkgname=foo
+pkgver=1
+
+build() {
+# template boom; name=test
+perl Makefile.pl
+make
+# template end;
+}
diff --git a/test/scripts/makepkg-template-tests/invalid-template-line-unknown-marker/testcase-config b/test/scripts/makepkg-template-tests/invalid-template-line-unknown-marker/testcase-config
new file mode 100644
index 00000000..077a85c3
--- /dev/null
+++ b/test/scripts/makepkg-template-tests/invalid-template-line-unknown-marker/testcase-config
@@ -0,0 +1,11 @@
+arguments+=()
+expected_exitcode=255
+
+# set IFS="" if you want trailing new lines, otherwise remove it
+IFS="" read -d '' expected_output <<'EOF'
+Unknown template marker 'boom'
+./makepkg-template-tests/invalid-template-line-unknown-marker/PKGBUILD:5: # template boom; name=test
+EOF
+
+IFS="" read -d '' expected_result <<'EOF'
+EOF
diff --git a/test/scripts/makepkg-template-tests/keep-old-version/PKGBUILD b/test/scripts/makepkg-template-tests/keep-old-version/PKGBUILD
new file mode 100644
index 00000000..09da2e03
--- /dev/null
+++ b/test/scripts/makepkg-template-tests/keep-old-version/PKGBUILD
@@ -0,0 +1,15 @@
+pkgname=foo
+pkgver=1
+
+build() {
+# template start; name=perl-module; version=1.0;
+echo "before bla template"
+# template start; name=perl-bla; version=1.2;
+bla bla
+# template end;
+echo "after bla template"
+perl Makefile.pl
+make
+make install
+# template end;
+}
diff --git a/test/scripts/makepkg-template-tests/keep-old-version/templates/perl-bla-1.2.template b/test/scripts/makepkg-template-tests/keep-old-version/templates/perl-bla-1.2.template
new file mode 100644
index 00000000..b72e7d48
--- /dev/null
+++ b/test/scripts/makepkg-template-tests/keep-old-version/templates/perl-bla-1.2.template
@@ -0,0 +1 @@
+bla bla
diff --git a/test/scripts/makepkg-template-tests/keep-old-version/templates/perl-module-1.0.template b/test/scripts/makepkg-template-tests/keep-old-version/templates/perl-module-1.0.template
new file mode 100644
index 00000000..415025ac
--- /dev/null
+++ b/test/scripts/makepkg-template-tests/keep-old-version/templates/perl-module-1.0.template
@@ -0,0 +1,6 @@
+echo "before bla template"
+# template input; name=perl-bla
+echo "after bla template"
+perl Makefile.pl
+make
+make install
diff --git a/test/scripts/makepkg-template-tests/keep-old-version/templates/perl-module-1.1.template b/test/scripts/makepkg-template-tests/keep-old-version/templates/perl-module-1.1.template
new file mode 100644
index 00000000..5ad32c3c
--- /dev/null
+++ b/test/scripts/makepkg-template-tests/keep-old-version/templates/perl-module-1.1.template
@@ -0,0 +1,7 @@
+echo "perl-module version 1.1"
+echo "before bla template"
+# template input; name=perl-bla
+echo "after bla template"
+perl Makefile.pl
+make
+make install
diff --git a/test/scripts/makepkg-template-tests/keep-old-version/testcase-config b/test/scripts/makepkg-template-tests/keep-old-version/testcase-config
new file mode 100644
index 00000000..b9448a08
--- /dev/null
+++ b/test/scripts/makepkg-template-tests/keep-old-version/testcase-config
@@ -0,0 +1,29 @@
+arguments+=()
+expected_exitcode=0
+
+_setup_testcase() {
+ ln -sr "templates/"{perl-bla-1.2.template,perl-bla.template}
+ ln -sr "templates/"{perl-module-1.1.template,perl-module.template}
+}
+
+# set IFS="" if you want trailing new lines, otherwise remove it
+IFS="" read -d '' expected_output <<'EOF'
+EOF
+
+IFS="" read -d '' expected_result <<'EOF'
+pkgname=foo
+pkgver=1
+
+build() {
+# template start; name=perl-module; version=1.0;
+echo "before bla template"
+# template start; name=perl-bla; version=1.2;
+bla bla
+# template end;
+echo "after bla template"
+perl Makefile.pl
+make
+make install
+# template end;
+}
+EOF
diff --git a/test/scripts/makepkg-template-tests/missing-template-file/PKGBUILD b/test/scripts/makepkg-template-tests/missing-template-file/PKGBUILD
new file mode 100644
index 00000000..dbfda1dd
--- /dev/null
+++ b/test/scripts/makepkg-template-tests/missing-template-file/PKGBUILD
@@ -0,0 +1,7 @@
+pkgname=foo
+pkgver=1
+
+build() {
+# template start; name=perl-module; version=1.0;
+# template end;
+}
diff --git a/test/scripts/makepkg-template-tests/missing-template-file/testcase-config b/test/scripts/makepkg-template-tests/missing-template-file/testcase-config
new file mode 100644
index 00000000..bdfde40d
--- /dev/null
+++ b/test/scripts/makepkg-template-tests/missing-template-file/testcase-config
@@ -0,0 +1,14 @@
+arguments+=()
+expected_exitcode=2
+
+_setup_testcase() {
+ ln -sr "templates/"{perl-module-1.0.template,perl-module.template}
+}
+
+# set IFS="" if you want trailing new lines, otherwise remove it
+IFS="" read -d '' expected_output <<'EOF'
+failed to open './makepkg-template-tests/missing-template-file/templates/perl-module-1.0.template': No such file or directory
+EOF
+
+IFS="" read -d '' expected_result <<'EOF'
+EOF
diff --git a/test/scripts/makepkg-template-tests/missing-template-symlink/PKGBUILD b/test/scripts/makepkg-template-tests/missing-template-symlink/PKGBUILD
new file mode 100644
index 00000000..8ee94aca
--- /dev/null
+++ b/test/scripts/makepkg-template-tests/missing-template-symlink/PKGBUILD
@@ -0,0 +1,7 @@
+pkgname=foo
+pkgver=1
+
+build() {
+# template start; name=perl-module;
+# template end;
+}
diff --git a/test/scripts/makepkg-template-tests/missing-template-symlink/templates/perl-module-1.0.template b/test/scripts/makepkg-template-tests/missing-template-symlink/templates/perl-module-1.0.template
new file mode 100644
index 00000000..f499d252
--- /dev/null
+++ b/test/scripts/makepkg-template-tests/missing-template-symlink/templates/perl-module-1.0.template
@@ -0,0 +1 @@
+this should not be included
diff --git a/test/scripts/makepkg-template-tests/missing-template-symlink/testcase-config b/test/scripts/makepkg-template-tests/missing-template-symlink/testcase-config
new file mode 100644
index 00000000..c0eabe0d
--- /dev/null
+++ b/test/scripts/makepkg-template-tests/missing-template-symlink/testcase-config
@@ -0,0 +1,9 @@
+arguments+=()
+expected_exitcode=255
+
+IFS="" read -d '' expected_output <<'EOF'
+Couldn't detect version for template 'perl-module'
+EOF
+
+IFS="" read -d '' expected_result <<'EOF'
+EOF
diff --git a/test/scripts/makepkg-template-tests/name-charset-invalid/PKGBUILD b/test/scripts/makepkg-template-tests/name-charset-invalid/PKGBUILD
new file mode 100644
index 00000000..36ed75bb
--- /dev/null
+++ b/test/scripts/makepkg-template-tests/name-charset-invalid/PKGBUILD
@@ -0,0 +1,8 @@
+pkgname=foo
+pkgver=1
+
+build() {
+# template start; name=foo/
+make install
+# template end;
+}
diff --git a/test/scripts/makepkg-template-tests/name-charset-invalid/testcase-config b/test/scripts/makepkg-template-tests/name-charset-invalid/testcase-config
new file mode 100644
index 00000000..7ea9502c
--- /dev/null
+++ b/test/scripts/makepkg-template-tests/name-charset-invalid/testcase-config
@@ -0,0 +1,10 @@
+arguments+=()
+expected_exitcode=255
+
+IFS="" read -d '' expected_output <<'EOF'
+invalid chars used in name 'foo/'. allowed: [:alnum:]+_.@-
+./makepkg-template-tests/name-charset-invalid/PKGBUILD:5: # template start; name=foo/
+EOF
+
+IFS="" read -d '' expected_result <<'EOF'
+EOF
diff --git a/test/scripts/makepkg-template-tests/name-charset-valid/PKGBUILD b/test/scripts/makepkg-template-tests/name-charset-valid/PKGBUILD
new file mode 100644
index 00000000..ec21cdb4
--- /dev/null
+++ b/test/scripts/makepkg-template-tests/name-charset-valid/PKGBUILD
@@ -0,0 +1,8 @@
+pkgname=foo
+pkgver=1
+
+build() {
+# template start; name=foo@-_.+a
+make install
+# template end;
+}
diff --git a/test/scripts/makepkg-template-tests/name-charset-valid/templates/foo@-_.+a-1.template b/test/scripts/makepkg-template-tests/name-charset-valid/templates/foo@-_.+a-1.template
new file mode 100644
index 00000000..d0884a6c
--- /dev/null
+++ b/test/scripts/makepkg-template-tests/name-charset-valid/templates/foo@-_.+a-1.template
@@ -0,0 +1 @@
+42 cookies
diff --git a/test/scripts/makepkg-template-tests/name-charset-valid/testcase-config b/test/scripts/makepkg-template-tests/name-charset-valid/testcase-config
new file mode 100644
index 00000000..409444a9
--- /dev/null
+++ b/test/scripts/makepkg-template-tests/name-charset-valid/testcase-config
@@ -0,0 +1,19 @@
+arguments+=()
+expected_exitcode=0
+
+_setup_testcase() {
+ ln -sr "templates/"{foo\@-_.+a-1.template,foo\@-_.+a.template}
+}
+IFS="" read -d '' expected_output <<'EOF'
+EOF
+
+IFS="" read -d '' expected_result <<'EOF'
+pkgname=foo
+pkgver=1
+
+build() {
+# template start; name=foo@-_.+a; version=1;
+42 cookies
+# template end;
+}
+EOF
diff --git a/test/scripts/makepkg-template-tests/template-without-version/PKGBUILD b/test/scripts/makepkg-template-tests/template-without-version/PKGBUILD
new file mode 100644
index 00000000..a4509a1a
--- /dev/null
+++ b/test/scripts/makepkg-template-tests/template-without-version/PKGBUILD
@@ -0,0 +1,8 @@
+pkgname=foo
+pkgver=1
+
+build() {
+# template start; name=template-without_version
+make install
+# template end;
+}
diff --git a/test/scripts/makepkg-template-tests/template-without-version/templates/template-without_version.template b/test/scripts/makepkg-template-tests/template-without-version/templates/template-without_version.template
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/test/scripts/makepkg-template-tests/template-without-version/templates/template-without_version.template
diff --git a/test/scripts/makepkg-template-tests/template-without-version/testcase-config b/test/scripts/makepkg-template-tests/template-without-version/testcase-config
new file mode 100644
index 00000000..ec04f2fa
--- /dev/null
+++ b/test/scripts/makepkg-template-tests/template-without-version/testcase-config
@@ -0,0 +1,9 @@
+arguments+=()
+expected_exitcode=255
+
+IFS="" read -d '' expected_output <<'EOF'
+Couldn't detect version for template 'template-without_version'
+EOF
+
+IFS="" read -d '' expected_result <<'EOF'
+EOF
diff --git a/test/scripts/makepkg-template-tests/testcase-config-template b/test/scripts/makepkg-template-tests/testcase-config-template
new file mode 100644
index 00000000..66267d3b
--- /dev/null
+++ b/test/scripts/makepkg-template-tests/testcase-config-template
@@ -0,0 +1,9 @@
+arguments+=()
+expected_exitcode=0
+
+# set IFS="" if you want trailing new line(s), otherwise remove it
+IFS="" read -d '' expected_output <<'EOF'
+EOF
+
+IFS="" read -d '' expected_result <<'EOF'
+EOF
diff --git a/test/scripts/makepkg-template-tests/update-version-with-newest-option/PKGBUILD b/test/scripts/makepkg-template-tests/update-version-with-newest-option/PKGBUILD
new file mode 100644
index 00000000..e1687cc8
--- /dev/null
+++ b/test/scripts/makepkg-template-tests/update-version-with-newest-option/PKGBUILD
@@ -0,0 +1,7 @@
+pkgname=foo
+pkgver=1
+
+build() {
+# template start; name=perl-module; version=1.0
+# template end;
+}
diff --git a/test/scripts/makepkg-template-tests/update-version-with-newest-option/templates/perl-bla-1.2.template b/test/scripts/makepkg-template-tests/update-version-with-newest-option/templates/perl-bla-1.2.template
new file mode 100644
index 00000000..b72e7d48
--- /dev/null
+++ b/test/scripts/makepkg-template-tests/update-version-with-newest-option/templates/perl-bla-1.2.template
@@ -0,0 +1 @@
+bla bla
diff --git a/test/scripts/makepkg-template-tests/update-version-with-newest-option/templates/perl-module-1.0.template b/test/scripts/makepkg-template-tests/update-version-with-newest-option/templates/perl-module-1.0.template
new file mode 100644
index 00000000..415025ac
--- /dev/null
+++ b/test/scripts/makepkg-template-tests/update-version-with-newest-option/templates/perl-module-1.0.template
@@ -0,0 +1,6 @@
+echo "before bla template"
+# template input; name=perl-bla
+echo "after bla template"
+perl Makefile.pl
+make
+make install
diff --git a/test/scripts/makepkg-template-tests/update-version-with-newest-option/templates/perl-module-1.1.template b/test/scripts/makepkg-template-tests/update-version-with-newest-option/templates/perl-module-1.1.template
new file mode 100644
index 00000000..5ad32c3c
--- /dev/null
+++ b/test/scripts/makepkg-template-tests/update-version-with-newest-option/templates/perl-module-1.1.template
@@ -0,0 +1,7 @@
+echo "perl-module version 1.1"
+echo "before bla template"
+# template input; name=perl-bla
+echo "after bla template"
+perl Makefile.pl
+make
+make install
diff --git a/test/scripts/makepkg-template-tests/update-version-with-newest-option/testcase-config b/test/scripts/makepkg-template-tests/update-version-with-newest-option/testcase-config
new file mode 100644
index 00000000..5956a0a2
--- /dev/null
+++ b/test/scripts/makepkg-template-tests/update-version-with-newest-option/testcase-config
@@ -0,0 +1,29 @@
+arguments+=(-n)
+expected_exitcode=0
+
+_setup_testcase() {
+ ln -sr "templates/"{perl-bla-1.2.template,perl-bla.template}
+ ln -sr "templates/"{perl-module-1.1.template,perl-module.template}
+}
+
+IFS="" read -d '' expected_output <<'EOF'
+EOF
+
+IFS="" read -d '' expected_result <<'EOF'
+pkgname=foo
+pkgver=1
+
+build() {
+# template start; name=perl-module; version=1.1;
+echo "perl-module version 1.1"
+echo "before bla template"
+# template start; name=perl-bla; version=1.2;
+bla bla
+# template end;
+echo "after bla template"
+perl Makefile.pl
+make
+make install
+# template end;
+}
+EOF
diff --git a/test/scripts/makepkg-template_test.sh b/test/scripts/makepkg-template_test.sh
new file mode 100755
index 00000000..b2531d4a
--- /dev/null
+++ b/test/scripts/makepkg-template_test.sh
@@ -0,0 +1,67 @@
+#!/bin/bash
+
+source "$(dirname "$0")"/../tap.sh || exit 1
+
+script=${1:-${PMTEST_SCRIPT_DIR}makepkg-template}
+
+if ! type -p "$script" &>/dev/null; then
+ tap_bail "makepkg-template executable (%s) could not be located" "${script}"
+ exit 1
+fi
+
+TMPDIR="$(mktemp -d "/tmp/${0##*/}.XXXXXX")"
+trap "rm -rf '${TMPDIR}'" EXIT TERM
+cp -r "${0%/*}/makepkg-template-tests" "$TMPDIR/makepkg-template-tests"
+
+# normalize paths
+script="$(readlink -f $(type -p "$script"))"
+cd "$TMPDIR"
+testdir="./makepkg-template-tests"
+
+
+total=$(find "$testdir" -maxdepth 1 -mindepth 1 -type d | wc -l)
+if [[ -z "$total" ]]; then
+ tap_bail "unable to determine total number of tests"
+ exit 1
+fi
+tap_plan "$((total*3))"
+
+run_test() {
+ local testcase=$1 exitcode expected_result expected_output
+ local -a arguments
+ local -i expected_exitcode=-1
+
+ [[ -f "$testdir/$testcase/testcase-config" ]] || continue
+ source "$testdir/$testcase/testcase-config"
+
+ mkdir "$TMPDIR/$testcase"
+ touch "$TMPDIR/$testcase/result"
+
+ # work around autotools not putting symlinks into the release tarball
+ [[ -d "$TMPDIR/$testdir/$testcase/templates" ]] || mkdir "$TMPDIR/$testdir/$testcase/templates"
+ if type -t _setup_testcase >/dev/null; then
+ cd "$TMPDIR/$testdir/$testcase"
+ _setup_testcase
+ unset -f _setup_testcase
+ cd "$TMPDIR"
+ fi
+
+ LC_ALL=C "$script" \
+ --template-dir "$testdir/$testcase/templates" \
+ -p "$testdir/$testcase/PKGBUILD" \
+ -o "$TMPDIR/$testcase/result" \
+ &> "$TMPDIR/$testcase/output" "${arguments[@]}"
+ exitcode=$?
+
+ tap_is_int "$exitcode" "$expected_exitcode" "$testcase exitcode"
+ tap_diff "$TMPDIR/$testcase/output" <(printf "%s" "$expected_output") "$testcase output"
+ tap_diff "$TMPDIR/$testcase/result" <(printf "%s" "$expected_result") "$testcase resulting PKGBUILD"
+}
+
+for dir in "$testdir/"*; do
+ if [[ -d "$dir" ]]; then
+ run_test "${dir##*/}"
+ fi
+done
+
+tap_finish
diff --git a/test/scripts/parseopts_test.sh b/test/scripts/parseopts_test.sh
index 2c055b1b..a8738a4c 100755
--- a/test/scripts/parseopts_test.sh
+++ b/test/scripts/parseopts_test.sh
@@ -1,17 +1,17 @@
#!/bin/bash
-declare -i testcount=0 pass=0 fail=0 total=25
+source "$(dirname "$0")"/../tap.sh || exit 1
# source the library function
lib=${1:-${PMTEST_SCRIPTLIB_DIR}parseopts.sh}
if [[ -z $lib || ! -f $lib ]]; then
- printf "Bail out! parseopts library ($lib) could not be located\n"
+ tap_bail "parseopts library ($lib) could not be located"
exit 1
fi
. "$lib"
if ! type -t parseopts &>/dev/null; then
- printf "Bail out! parseopts function not found\n"
+ tap_bail "parseopts function not found"
exit 1
fi
@@ -23,120 +23,94 @@ OPT_LONG=('allsource' 'asroot' 'ignorearch' 'check' 'clean:' 'cleanall' 'nodeps'
'repackage' 'skipinteg' 'sign' 'source' 'syncdeps' 'version' 'config:'
'noconfirm' 'noprogressbar')
-parse() {
+tap_parse() {
local result=$1 tokencount=$2; shift 2
-
- (( ++testcount ))
parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@" 2>/dev/null
- test_result "$result" "$tokencount" "$*" "${OPTRET[@]}"
+ tap_is_int "${#OPTRET[@]}" "$tokencount" "$* - tokencount"
+ tap_is_str "$result" "${OPTRET[*]}" "$* - result"
unset OPTRET
}
-test_result() {
- local result=$1 tokencount=$2 input=$3; shift 3
-
- if [[ $result = "$*" ]] && (( tokencount == $# )); then
- (( ++pass ))
- printf 'ok %d - %s\n' "$testcount" "$input"
- else
- printf 'not ok %d - %s\n' "$testcount" "$input"
- printf '# [TEST %3s]: FAIL\n' "$testcount"
- printf '# input: %s\n' "$input"
- printf '# output: %s (%s tokens)\n' "$*" "$#"
- printf '# expected: %s (%s tokens)\n' "$result" "$tokencount"
- (( ++fail ))
- fi
-}
-
-summarize() {
- if (( !fail )); then
- printf '# All %s tests successful\n\n' "$testcount"
- exit 0
- else
- printf '# %s of %s tests failed\n\n' "$fail" "$testcount"
- exit 1
- fi
-}
-trap 'summarize' EXIT
-
-printf '# Beginning parseopts tests\n'
-
-echo "1..$total"
+tap_plan 50
-# usage: parse <expected result> <token count> test-params...
-# a failed parse will match only the end of options marker '--'
+# usage: tap_parse <expected result> <token count> test-params...
+# a failed tap_parse will match only the end of options marker '--'
# no options
-parse '--' 1
+tap_parse '--' 1
# short options
-parse '-s -r --' 3 -s -r
+tap_parse '-s -r --' 3 -s -r
# short options, no spaces
-parse '-s -r --' 3 -sr
+tap_parse '-s -r --' 3 -sr
# short opt missing an opt arg
-parse '--' 1 -s -p
+tap_parse '--' 1 -s -p
# short opt with an opt arg
-parse '-p PKGBUILD -L --' 4 -p PKGBUILD -L
+tap_parse '-p PKGBUILD -L --' 4 -p PKGBUILD -L
# short opt with an opt arg, no space
-parse '-p PKGBUILD --' 3 -pPKGBUILD
+tap_parse '-p PKGBUILD --' 3 -pPKGBUILD
# valid shortopts as a long opt
-parse '--' 1 --sir
+tap_parse '--' 1 --sir
# long opt with no optarg
-parse '--log --' 2 --log
+tap_parse '--log --' 2 --log
# long opt with missing optarg
-parse '--' 1 -sr --pkg
+tap_parse '--' 1 -sr --pkg
# long opt with optarg
-parse '--pkg foo --' 3 --pkg foo
+tap_parse '--pkg foo --' 3 --pkg foo
# long opt with optarg with whitespace
-parse '--pkg foo bar -- baz' 4 --pkg "foo bar" baz
+tap_parse '--pkg foo bar -- baz' 4 --pkg "foo bar" baz
# long opt with optarg with =
-parse '--pkg foo=bar -- baz' 4 --pkg foo=bar baz
+tap_parse '--pkg foo=bar -- baz' 4 --pkg foo=bar baz
# long opt with explicit optarg
-parse '--pkg bar -- foo baz' 5 foo --pkg=bar baz
+tap_parse '--pkg bar -- foo baz' 5 foo --pkg=bar baz
# long opt with explicit optarg, with whitespace
-parse '--pkg foo bar -- baz' 4 baz --pkg="foo bar"
+tap_parse '--pkg foo bar -- baz' 4 baz --pkg="foo bar"
# long opt with explicit optarg that doesn't take optarg
-parse '--' 1 --force=always -s
+tap_parse '--' 1 --force=always -s
# long opt with explicit optarg with =
-parse '--pkg foo=bar --' 3 --pkg=foo=bar
+tap_parse '--pkg foo=bar --' 3 --pkg=foo=bar
# explicit end of options with options after
-parse '-s -r -- foo bar baz' 6 -s -r -- foo bar baz
+tap_parse '-s -r -- foo bar baz' 6 -s -r -- foo bar baz
# non-option parameters mixed in with options
-parse '-s -r -- foo baz' 5 -s foo baz -r
+tap_parse '-s -r -- foo baz' 5 -s foo baz -r
# optarg with whitespace
-parse '-p foo bar -s --' 4 -p'foo bar' -s
+tap_parse '-p foo bar -s --' 4 -p'foo bar' -s
# non-option parameter with whitespace
-parse '-i -- foo bar' 3 -i 'foo bar'
+tap_parse '-i -- foo bar' 3 -i 'foo bar'
# successful stem match (opt has no arg)
-parse '--nocolor --' 2 --nocol
+tap_parse '--nocolor --' 2 --nocol
# successful stem match (opt has arg)
-parse '--config foo --' 3 --conf foo
+tap_parse '--config foo --' 3 --conf foo
# ambiguous long opt
-parse '--' 1 '--for'
+tap_parse '--' 1 '--for'
# exact match on a possible stem (--force & --forcever)
-parse '--force --' 2 --force
+tap_parse '--force --' 2 --force
# exact match on possible stem (opt has optarg)
-parse '--clean foo --' 3 --clean=foo
+tap_parse '--clean foo --' 3 --clean=foo
+
+tap_finish
+
+# vim: set noet:
diff --git a/test/tap.sh b/test/tap.sh
new file mode 100644
index 00000000..38852691
--- /dev/null
+++ b/test/tap.sh
@@ -0,0 +1,163 @@
+# Copyright 2014 Andrew Gregory <andrew.gregory.8@gmail.com>
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to
+# deal in the Software without restriction, including without limitation the
+# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+# sell copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+# IN THE SOFTWARE.
+#
+# Project URL: http://github.com/andrewgregory/tap.sh
+
+declare -i tap_planned=0 tap_run=0 tap_failed=0 tap_passed=0
+declare tap_todo=''
+
+tap_plan() {
+ tap_planned=$1
+ printf "1..%d\n" "$tap_planned"
+}
+
+tap_done_testing() {
+ tap_plan $tap_run
+}
+
+tap_skip_all() {
+ printf "1..0 # SKIP"
+ _tap_print_reason " " "$@"
+ printf "\n"
+}
+
+tap_diag() {
+ if [[ -n $tap_todo ]]; then
+ tap_note "$@"
+ else
+ tap_note "$@" 1>&2
+ fi
+}
+
+tap_note() {
+ printf "# "
+ printf -- "$@"
+ printf "\n"
+}
+
+tap_bail() {
+ printf "Bail out!"
+ _tap_print_reason " " "$@"
+ printf "\n"
+}
+
+tap_finish() {
+ local tap_todo=''
+ if (( tap_planned != tap_run )); then
+ tap_note "Looks like you planned %d tests but ran %d." "$tap_planned" "$tap_run"
+ elif (( tap_planned == tap_run && tap_failed == 0 )); then
+ tap_note "All %d tests successfully run." "$tap_planned"
+ else
+ tap_note "Failed %d of %d tests." "$tap_failed" "$tap_planned"
+ fi
+ (( tap_planned == tap_run && tap_failed == 0 ))
+}
+
+tap_skip() {
+ local -i count="$1"; shift
+ while (( count-- )); do
+ (( tap_run++ ))
+ printf "ok %d # SKIP" "$tap_run"
+ _tap_print_reason " " "$@"
+ printf "\n"
+ done
+}
+
+_tap_print_reason() {
+ local sep="$1"; shift
+ if [[ $# -gt 0 ]]; then
+ printf "%s" "$sep"
+ printf -- "$@"
+ fi
+}
+
+tap_ok() {
+ local ok="$1"; shift
+ (( tap_run++ ))
+ if [[ $ok -eq 0 ]]; then
+ (( tap_passed++ ))
+ printf "ok %d" "$tap_run"
+ else
+ (( tap_failed++ ))
+ printf "not ok %d" "$tap_run"
+ fi
+ _tap_print_reason " - " "$@"
+ if [[ -n $tap_todo ]]; then
+ printf " # TODO %s" "$tap_todo"
+ fi
+ printf "\n"
+ if [[ $ok -ne 0 ]]; then
+ local line func file
+ local -i i=0
+
+ read line func file < <(caller $i)
+ while [[ -n $func && $func == tap_* ]]; do
+ (( i++ ))
+ read line func file < <(caller $i)
+ done
+
+ if [[ -n $file ]]; then
+ file=${file##*/}
+ if [[ -n $tap_todo ]]; then
+ tap_diag " Failed (TODO) test at %s line %d." "${file}" "$line"
+ else
+ tap_diag " Failed test at %s line %d." "${file}" "$line"
+ fi
+ fi
+ fi
+ return $ok
+}
+
+tap_is_str() {
+ local got="$1" expected="$2"; shift 2
+ [[ $got == $expected ]]
+ local ret=$?
+ if ! tap_ok $ret "$@"; then
+ tap_diag " got: '%s'" "$got"
+ tap_diag " expected: '%s'" "$expected"
+ fi
+ return $ret
+}
+
+tap_is_int() {
+ local got="$1" expected="$2"; shift 2
+ [[ $got -eq $expected ]]
+ local ret=$?
+ if ! tap_ok $ret "$@"; then
+ tap_diag " got: '%s'" "$got"
+ tap_diag " expected: '%s'" "$expected"
+ fi
+ return $ret
+}
+
+tap_diff() {
+ local got="$1" expected="$2"; shift 2
+ local output ret
+ output="$(diff -u --label got --label expected "$got" "$expected" 2>&1)"
+ ret=$?
+ if ! tap_ok $ret "$@"; then
+ while IFS= read line; do
+ tap_diag "$line"
+ done <<<"$output"
+ fi
+ return $ret
+}
+
+# vim: ft=sh
diff --git a/test/util/pacsorttest.sh b/test/util/pacsorttest.sh
index 49d6d8ed..f42c8fd5 100755
--- a/test/util/pacsorttest.sh
+++ b/test/util/pacsorttest.sh
@@ -18,85 +18,69 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+source "$(dirname "$0")"/../tap.sh || exit 1
+
# default binary if one was not specified as $1
bin=${1:-${PMTEST_UTIL_DIR}pacsort}
-# holds counts of tests
-total=26
-run=0
-failure=0
if ! type -p "$bin" &>/dev/null; then
- echo "Bail out! pacsort binary ($bin) could not be located"
+ tap_bail "pacsort binary ($bin) could not be located"
exit 1
fi
# args:
# runtest input expected test_description optional_opts
-runtest() {
+tap_runtest() {
# run the test
- ((run++))
- out=$(diff -u <(printf "$1" | $bin $4) <(printf "$2"))
- if [[ $? -eq 0 ]]; then
- echo "ok $run - $3"
- else
- ((failure++))
- echo "not ok $run - $3"
- while read line; do
- echo " # $line"
- done <<<"$out"
- fi
+ tap_diff <(printf "$1" | $bin $4) <(printf "$2") "$3"
}
-echo "# Running pacsort tests..."
-
-echo "1..$total"
-
-# BEGIN TESTS
+tap_plan 26
in="1\n2\n3\n4\n"
-runtest $in $in "already ordered"
+tap_runtest $in $in "already ordered"
in="4\n2\n3\n1\n"
ex="1\n2\n3\n4\n"
-runtest $in $ex "easy reordering"
+tap_runtest $in $ex "easy reordering"
in="1\n2\n3\n4"
ex="1\n2\n3\n4\n"
-runtest $in $ex "add trailing newline"
+tap_runtest $in $ex "add trailing newline"
in="1\n2\n4\n3"
ex="1\n2\n3\n4\n"
-runtest $in $ex "add trailing newline"
+tap_runtest $in $ex "add trailing newline"
in="1.0-1\n1.0\n1.0-2\n1.0\n"
-runtest $in $in "stable sort"
+tap_runtest $in $in "stable sort"
in="firefox-18.0-2-x86_64.pkg.tar.xz\nfirefox-18.0.1-1-x86_64.pkg.tar.xz\n"
-runtest $in $in "filename sort" "--files"
+tap_runtest $in $in "filename sort" "--files"
in="firefox-18.0-2\nfirefox-18.0.1-1-x86_64.pkg.tar.xz\n"
-runtest $in $in "filename sort with invalid filename" "--files"
+tap_runtest $in $in "filename sort with invalid filename" "--files"
in="firefox-18.0-2-x86_64.pkg.tar.xz\n/path2/firefox-18.0.1-1-x86_64.pkg.tar.xz\n"
-runtest $in $in "filename sort maybe with leading paths" "--files"
+tap_runtest $in $in "filename sort maybe with leading paths" "--files"
in="/path1/firefox-18.0-2-x86_64.pkg.tar.xz\n/path2/firefox-18.0.1-1-x86_64.pkg.tar.xz\n"
-runtest $in $in "filename sort with different leading paths" "--files"
+tap_runtest $in $in "filename sort with different leading paths" "--files"
in="/path2/firefox-18.0-2-x86_64.pkg.tar.xz\n/path1/path2/firefox-18.0.1-1-x86_64.pkg.tar.xz\n"
-runtest $in $in "filename sort with uneven leading path components" "--files"
+tap_runtest $in $in "filename sort with uneven leading path components" "--files"
in="firefox-18.0-2-i686.pkg.tar.xz\nfirefox-18.0.1-1-x86_64.pkg.tar.gz\n"
-runtest $in $in "filename sort with different extensions" "--files"
+tap_runtest $in $in "filename sort with different extensions" "--files"
in="/packages/dialog-1.2_20131001-1-x86_64.pkg.tar.xz\n/packages/dialog-1:1.2_20130928-1-x86_64.pkg.tar.xz\n"
-runtest $in $in "filename sort with epoch" "--files"
+tap_runtest $in $in "filename sort with epoch" "--files"
in="/packages/dia-log-1:1.2_20130928-1-x86_64.pkg.tar.xz\n/packages/dialog-1.2_20131001-1-x86_64.pkg.tar.xz\n"
-runtest $in $in "filename sort with differing package names and epoch" "--files"
+tap_runtest $in $in "filename sort with differing package names and epoch" "--files"
in="/packages/systemd-217-1-x86_64.pkg.tar.xz\n/packages/systemd-sysvcompat-217-1-x86_64.pkg.tar.xz\n"
-runtest $in $in "filename sort with package names as shared substring" "--files"
+tap_runtest $in $in "filename sort with package names as shared substring" "--files"
# generate some long input/expected for the next few tests
declare normal reverse names_normal names_reverse
@@ -109,27 +93,21 @@ for ((i=1; i<600; i++)); do
separator_reverse="${separator_reverse}colA|bogus${i}|$((600 - ${i}))\n"
done
-runtest $normal $normal "really long input"
-runtest $reverse $normal "really long input"
-runtest $reverse $reverse "really long input, reversed" "-r"
-runtest $normal $reverse "really long input, reversed" "-r"
+tap_runtest $normal $normal "really long input"
+tap_runtest $reverse $normal "really long input"
+tap_runtest $reverse $reverse "really long input, reversed" "-r"
+tap_runtest $normal $reverse "really long input, reversed" "-r"
-runtest "$fields" "$fields" "really long input, sort key" "-k3"
-runtest "$fields_reverse" "$fields" "really long input, sort key" "-k3"
-runtest "$fields_reverse" "$fields_reverse" "really long input, sort key, reversed" "-k 3 -r"
-runtest "$fields" "$fields_reverse" "really long input, sort key, reversed" "-k 3 -r"
+tap_runtest "$fields" "$fields" "really long input, sort key" "-k3"
+tap_runtest "$fields_reverse" "$fields" "really long input, sort key" "-k3"
+tap_runtest "$fields_reverse" "$fields_reverse" "really long input, sort key, reversed" "-k 3 -r"
+tap_runtest "$fields" "$fields_reverse" "really long input, sort key, reversed" "-k 3 -r"
-runtest "$separator" "$separator" "really long input, sort key, separator" "-k3 -t|"
-runtest "$separator_reverse" "$separator" "really long input, sort key, separator" "-k3 -t|"
-runtest "$separator_reverse" "$separator_reverse" "really long input, sort key, separator, reversed" "-k 3 -t| -r"
-runtest "$separator" "$separator_reverse" "really long input, sort key, separator, reversed" "-k 3 -t| -r"
+tap_runtest "$separator" "$separator" "really long input, sort key, separator" "-k3 -t|"
+tap_runtest "$separator_reverse" "$separator" "really long input, sort key, separator" "-k3 -t|"
+tap_runtest "$separator_reverse" "$separator_reverse" "really long input, sort key, separator, reversed" "-k 3 -t| -r"
+tap_runtest "$separator" "$separator_reverse" "really long input, sort key, separator, reversed" "-k 3 -t| -r"
-#END TESTS
-
-if [[ $failure -eq 0 ]]; then
- echo "# All $run tests successful"
- exit 0
-fi
+tap_finish
-echo "# $failure of $run tests failed"
-exit 1
+# vim: set noet:
diff --git a/test/util/vercmptest.sh b/test/util/vercmptest.sh
index 9032cbf9..04edb155 100755
--- a/test/util/vercmptest.sh
+++ b/test/util/vercmptest.sh
@@ -18,136 +18,101 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
+source "$(dirname "$0")"/../tap.sh || exit 1
+
# default binary if one was not specified as $1
bin=${1:-${PMTEST_UTIL_DIR}vercmp}
-# holds counts of tests
-total=92
-run=0
-failure=0
# use first arg as our binary if specified
if ! type -p "$bin" &>/dev/null; then
- echo "Bail out! vercmp binary ($bin) could not be located"
+ tap_bail "vercmp binary ($bin) could not be located"
exit 1
fi
# args:
-# pass ver1 ver2 ret expected
-pass() {
- echo "ok $run - ver1: $1 ver2: $2 ret: $3"
-}
-
-# args:
-# fail ver1 ver2 ret expected
-fail() {
- echo "not ok $run - test: ver1: $1 ver2: $2 ret: $3 expected: $4"
- ((failure++))
-}
-
-# args:
# runtest ver1 ver2 expected
-runtest() {
- # run the test
- ((run++))
- ret=$($bin $1 $2)
- func='pass'
- [[ -n $ret && $ret -eq $3 ]] || func='fail'
- $func $1 $2 $ret $3
+tap_runtest() {
+ local ver1=$1 ver2=$2 exp=$3
+ tap_is_str "$($bin "$ver1" "$ver2")" "$exp" "$ver1 $ver2"
# and run its mirror case just to be sure
- ((run++))
- reverse=0
- [[ $3 -eq 1 ]] && reverse=-1
- [[ $3 -eq -1 ]] && reverse=1
- ret=$($bin $2 $1)
- func='pass'
- [[ -n $ret && $ret -eq $reverse ]] || func='fail'
- $func $2 $1 $ret $reverse
+ (( exp *= -1 ))
+ tap_is_str "$($bin "$ver2" "$ver1")" "$exp" "$ver2 $ver1"
}
-echo "# Running vercmp tests..."
-
-echo "1..$total"
-
-# BEGIN TESTS
+tap_plan 92
# all similar length, no pkgrel
-runtest 1.5.0 1.5.0 0
-runtest 1.5.1 1.5.0 1
+tap_runtest 1.5.0 1.5.0 0
+tap_runtest 1.5.1 1.5.0 1
# mixed length
-runtest 1.5.1 1.5 1
+tap_runtest 1.5.1 1.5 1
# with pkgrel, simple
-runtest 1.5.0-1 1.5.0-1 0
-runtest 1.5.0-1 1.5.0-2 -1
-runtest 1.5.0-1 1.5.1-1 -1
-runtest 1.5.0-2 1.5.1-1 -1
+tap_runtest 1.5.0-1 1.5.0-1 0
+tap_runtest 1.5.0-1 1.5.0-2 -1
+tap_runtest 1.5.0-1 1.5.1-1 -1
+tap_runtest 1.5.0-2 1.5.1-1 -1
# with pkgrel, mixed lengths
-runtest 1.5-1 1.5.1-1 -1
-runtest 1.5-2 1.5.1-1 -1
-runtest 1.5-2 1.5.1-2 -1
+tap_runtest 1.5-1 1.5.1-1 -1
+tap_runtest 1.5-2 1.5.1-1 -1
+tap_runtest 1.5-2 1.5.1-2 -1
# mixed pkgrel inclusion
-runtest 1.5 1.5-1 0
-runtest 1.5-1 1.5 0
-runtest 1.1-1 1.1 0
-runtest 1.0-1 1.1 -1
-runtest 1.1-1 1.0 1
+tap_runtest 1.5 1.5-1 0
+tap_runtest 1.5-1 1.5 0
+tap_runtest 1.1-1 1.1 0
+tap_runtest 1.0-1 1.1 -1
+tap_runtest 1.1-1 1.0 1
# alphanumeric versions
-runtest 1.5b-1 1.5-1 -1
-runtest 1.5b 1.5 -1
-runtest 1.5b-1 1.5 -1
-runtest 1.5b 1.5.1 -1
+tap_runtest 1.5b-1 1.5-1 -1
+tap_runtest 1.5b 1.5 -1
+tap_runtest 1.5b-1 1.5 -1
+tap_runtest 1.5b 1.5.1 -1
# from the manpage
-runtest 1.0a 1.0alpha -1
-runtest 1.0alpha 1.0b -1
-runtest 1.0b 1.0beta -1
-runtest 1.0beta 1.0rc -1
-runtest 1.0rc 1.0 -1
+tap_runtest 1.0a 1.0alpha -1
+tap_runtest 1.0alpha 1.0b -1
+tap_runtest 1.0b 1.0beta -1
+tap_runtest 1.0beta 1.0rc -1
+tap_runtest 1.0rc 1.0 -1
# going crazy? alpha-dotted versions
-runtest 1.5.a 1.5 1
-runtest 1.5.b 1.5.a 1
-runtest 1.5.1 1.5.b 1
+tap_runtest 1.5.a 1.5 1
+tap_runtest 1.5.b 1.5.a 1
+tap_runtest 1.5.1 1.5.b 1
# alpha dots and dashes
-runtest 1.5.b-1 1.5.b 0
-runtest 1.5-1 1.5.b -1
+tap_runtest 1.5.b-1 1.5.b 0
+tap_runtest 1.5-1 1.5.b -1
# same/similar content, differing separators
-runtest 2.0 2_0 0
-runtest 2.0_a 2_0.a 0
-runtest 2.0a 2.0.a -1
-runtest 2___a 2_a 1
+tap_runtest 2.0 2_0 0
+tap_runtest 2.0_a 2_0.a 0
+tap_runtest 2.0a 2.0.a -1
+tap_runtest 2___a 2_a 1
# epoch included version comparisons
-runtest 0:1.0 0:1.0 0
-runtest 0:1.0 0:1.1 -1
-runtest 1:1.0 0:1.0 1
-runtest 1:1.0 0:1.1 1
-runtest 1:1.0 2:1.1 -1
+tap_runtest 0:1.0 0:1.0 0
+tap_runtest 0:1.0 0:1.1 -1
+tap_runtest 1:1.0 0:1.0 1
+tap_runtest 1:1.0 0:1.1 1
+tap_runtest 1:1.0 2:1.1 -1
# epoch + sometimes present pkgrel
-runtest 1:1.0 0:1.0-1 1
-runtest 1:1.0-1 0:1.1-1 1
+tap_runtest 1:1.0 0:1.0-1 1
+tap_runtest 1:1.0-1 0:1.1-1 1
# epoch included on one version
-runtest 0:1.0 1.0 0
-runtest 0:1.0 1.1 -1
-runtest 0:1.1 1.0 1
-runtest 1:1.0 1.0 1
-runtest 1:1.0 1.1 1
-runtest 1:1.1 1.1 1
-
-#END TESTS
-
-if [[ $failure -eq 0 ]]; then
- echo "# All $run tests successful"
- exit 0
-fi
+tap_runtest 0:1.0 1.0 0
+tap_runtest 0:1.0 1.1 -1
+tap_runtest 0:1.1 1.0 1
+tap_runtest 1:1.0 1.0 1
+tap_runtest 1:1.0 1.1 1
+tap_runtest 1:1.1 1.1 1
+
+tap_finish
-echo "# $failure of $run tests failed"
-exit 1
+# vim: set noet: