summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README2
-rw-r--r--configure.ac3
-rw-r--r--contrib/bash_completion.in4
-rw-r--r--contrib/zsh_completion.in4
-rw-r--r--doc/makepkg.8.txt4
-rw-r--r--doc/pacman.8.txt2
-rw-r--r--doc/pacman.conf.5.txt14
-rw-r--r--lib/libalpm/add.c124
-rw-r--r--lib/libalpm/alpm.c4
-rw-r--r--lib/libalpm/alpm.h29
-rw-r--r--lib/libalpm/alpm_list.c13
-rw-r--r--lib/libalpm/alpm_list.h1
-rw-r--r--lib/libalpm/base64.c2
-rw-r--r--lib/libalpm/base64.h2
-rw-r--r--lib/libalpm/be_local.c9
-rw-r--r--lib/libalpm/be_package.c90
-rw-r--r--lib/libalpm/be_sync.c45
-rw-r--r--lib/libalpm/conflict.c10
-rw-r--r--lib/libalpm/db.h2
-rw-r--r--lib/libalpm/diskspace.c102
-rw-r--r--lib/libalpm/diskspace.h2
-rw-r--r--lib/libalpm/dload.c4
-rw-r--r--lib/libalpm/dload.h3
-rw-r--r--lib/libalpm/error.c4
-rw-r--r--lib/libalpm/handle.c2
-rw-r--r--lib/libalpm/handle.h4
-rw-r--r--lib/libalpm/package.c74
-rw-r--r--lib/libalpm/package.h9
-rw-r--r--lib/libalpm/remove.c20
-rw-r--r--lib/libalpm/signing.c22
-rw-r--r--lib/libalpm/sync.c199
-rw-r--r--lib/libalpm/util.c501
-rw-r--r--lib/libalpm/util.h25
-rw-r--r--scripts/makepkg.sh.in2
-rw-r--r--scripts/pacman-optimize.sh.in2
-rw-r--r--scripts/repo-add.sh.in57
-rw-r--r--src/pacman/callback.c62
-rw-r--r--src/pacman/conf.c9
-rw-r--r--src/pacman/conf.h3
-rw-r--r--src/pacman/deptest.c4
-rw-r--r--src/pacman/package.c24
-rw-r--r--src/pacman/pacman.c18
-rw-r--r--src/pacman/query.c36
-rw-r--r--src/pacman/remove.c20
-rw-r--r--src/pacman/sync.c82
-rw-r--r--src/pacman/upgrade.c2
-rw-r--r--src/pacman/util.c144
-rw-r--r--src/util/cleanupdelta.c8
-rw-r--r--src/util/pactree.c8
-rw-r--r--src/util/testdb.c8
-rw-r--r--src/util/testpkg.c2
-rw-r--r--test/pacman/tests/ignore008.py29
-rw-r--r--test/pacman/tests/remove031.py11
-rw-r--r--test/pacman/tests/sync139.py23
-rw-r--r--test/pacman/tests/sync502.py17
-rw-r--r--test/pacman/tests/sync503.py18
-rw-r--r--test/pacman/tests/upgrade012.py2
-rw-r--r--test/pacman/tests/upgrade014.py2
-rw-r--r--test/pacman/tests/upgrade015.py2
-rw-r--r--test/pacman/tests/upgrade016.py2
-rw-r--r--test/pacman/tests/upgrade046.py2
61 files changed, 1219 insertions, 715 deletions
diff --git a/README b/README
index 0e5a512d..c4199ddb 100644
--- a/README
+++ b/README
@@ -389,7 +389,7 @@ API CHANGES BETWEEN 3.5 AND 4.0
- PM_ prefixes for enum values are now ALPM_
- pm prefixes for structs and enums are now alpm_
- alpm_initialize now has parameters: char *root, char *dbpath,
- _alpm_errno_t *err and returns an alpm_handle_t struct.
+ alpm_errno_t *err and returns an alpm_handle_t struct.
- alpm_release now takes an alpm_handle_t *.
- alpm_db_register_sync() now requires a extra parameter of a alpm_siglevel_t.
- alpm_pkg_load() now requires an extra parameter of an alpm_siglevel_t
diff --git a/configure.ac b/configure.ac
index 0de908a3..d4ec6779 100644
--- a/configure.ac
+++ b/configure.ac
@@ -201,6 +201,7 @@ AC_CHECK_FUNCS([dup2 getcwd geteuid getmntinfo gettimeofday memmove memset \
mkdir realpath regcomp rmdir setenv setlocale strcasecmp \
strchr strcspn strdup strerror strndup strrchr strsep strstr \
strtol swprintf tcflush wcwidth uname])
+AC_CHECK_MEMBERS([struct stat.st_blksize],,,[[#include <sys/stat.h>]])
# For the diskspace code
FS_STATS_TYPE
@@ -295,8 +296,6 @@ AC_MSG_CHECKING(for debug mode request)
if test "x$debug" = "xyes" ; then
AC_MSG_RESULT(yes)
AC_DEFINE([PACMAN_DEBUG], , [Enable debug code])
- # Check for mcheck
- AC_CHECK_HEADERS([mcheck.h])
# Check for -fstack-protector availability
GCC_STACK_PROTECT_LIB
GCC_STACK_PROTECT_CC
diff --git a/contrib/bash_completion.in b/contrib/bash_completion.in
index 78bde21d..eb31b5e5 100644
--- a/contrib/bash_completion.in
+++ b/contrib/bash_completion.in
@@ -76,8 +76,8 @@ _pacman() {
remove=('cascade dbonly nodeps nosave print recursive unneeded' 'c n p s u')
sync=('asdeps asexplicit clean dbonly downloadonly force groups ignore ignoregroup
info list needed nodeps print refresh recursive search sysupgrade'
- 'c f g i l p s u w y')
- upgrade=('asdeps asexplicit force needed nodeps print recursive' 'f p')
+ 'c g i l p s u w y')
+ upgrade=('asdeps asexplicit force needed nodeps print recursive' 'p')
common=('arch cachedir config dbpath debug help logfile noconfirm
noprogressbar noscriptlet quiet root verbose' 'b d h q r v')
core=('database help query remove sync upgrade version' 'D Q R S U V h')
diff --git a/contrib/zsh_completion.in b/contrib/zsh_completion.in
index f7e0b923..71ef901b 100644
--- a/contrib/zsh_completion.in
+++ b/contrib/zsh_completion.in
@@ -32,8 +32,8 @@ _pacman_opts_common=(
# options for passing to _arguments: options for --upgrade commands
_pacman_opts_pkgfile=(
'-d[Skip dependency checks]'
- '-f[Overwrite conflicting files]'
'--dbonly[Only remove database entry, do not remove files]'
+ '--force[Overwrite conflicting files]'
'--needed[Do not reinstall up to date packages]'
'--recursive[Reinstall all dependencies of target packages]'
'*:package file:_files -g "*.pkg.tar.*(.)"'
@@ -85,7 +85,6 @@ _pacman_opts_sync_actions=(
# options for passing to _arguments: options for --sync command
_pacman_opts_sync_modifiers=(
'-d[Skip dependency checks]'
- '-f[Overwrite conflicting files]'
'-i[View package information]'
'-l[List all packages in a repository]'
'-p[Print download URIs for each package to be installed]'
@@ -98,6 +97,7 @@ _pacman_opts_sync_modifiers=(
_pacman_completions_all_groups'
'--asdeps[Install packages as non-explicitly installed]'
'--asexplicit[Install packages as explicitly installed]'
+ '--force[Overwrite conflicting files]'
)
# handles --help subcommand
diff --git a/doc/makepkg.8.txt b/doc/makepkg.8.txt
index f693a5a8..df41e187 100644
--- a/doc/makepkg.8.txt
+++ b/doc/makepkg.8.txt
@@ -207,6 +207,10 @@ Environment Variables
Folder where the downloaded sources will be stored. Overrides the
corresponding value defined in linkman:makepkg.conf[5].
+**PACKAGER=**"John Doe <john@doe.com>"::
+ String to identify the creator of the resulting package. Overrides
+ the corresponding value defined in linkman:makepkg.conf[5].
+
**BUILDDIR=**"/path/to/folder"::
Folder where the package will be built. Overrides the corresponding
value defined in linkman:makepkg.conf[5].
diff --git a/doc/pacman.8.txt b/doc/pacman.8.txt
index 59853812..39551e15 100644
--- a/doc/pacman.8.txt
+++ b/doc/pacman.8.txt
@@ -201,7 +201,7 @@ Transaction Options (apply to '-S', '-R' and '-U')
Upgrade Options (apply to '-S' and '-U')[[UO]]
--------------------------------------------
-*-f, \--force*::
+*\--force*::
Bypass file conflict checks and overwrite conflicting files. If the
package that is about to be installed contains files that are already
installed, this option will cause all those files to be overwritten.
diff --git a/doc/pacman.conf.5.txt b/doc/pacman.conf.5.txt
index e793e78b..2c1a24b2 100644
--- a/doc/pacman.conf.5.txt
+++ b/doc/pacman.conf.5.txt
@@ -86,11 +86,12 @@ Options
*HoldPkg =* package ...::
If a user tries to '\--remove' a package that's listed in `HoldPkg`,
- pacman will ask for confirmation before proceeding.
+ pacman will ask for confirmation before proceeding. Shell-style glob
+ patterns are allowed.
*IgnorePkg =* package ...::
Instructs pacman to ignore any upgrades for this package when performing
- a '\--sysupgrade'.
+ a '\--sysupgrade'. Shell-style glob patterns are allowed.
*SyncFirst =* package ...::
Instructs pacman to check for newer version of these packages before any
@@ -103,7 +104,8 @@ Options
*IgnoreGroup =* group ...::
Instructs pacman to ignore any upgrades for all packages in this
- group when performing a '\--sysupgrade'.
+ group when performing a '\--sysupgrade'. Shell-style glob patterns are
+ allowed.
*Include =* path::
Include another config file. This file can include repositories or
@@ -134,7 +136,8 @@ Options
a package install/upgrade, and the new files will be installed with a
'.pacnew' extension.
These files refer to files in the package archive, so do not include the
- leading slash (the RootDir) when specifying them.
+ leading slash (the RootDir) when specifying them. Shell-style glob patterns
+ are allowed.
*NoExtract =* file ...::
All files listed with a `NoExtract` directive will never be extracted from
@@ -143,7 +146,8 @@ Options
'index.php', then you would not want the 'index.html' file to be extracted
from the 'apache' package.
These files refer to files in the package archive, so do not include the
- leading slash (the RootDir) when specifying them.
+ leading slash (the RootDir) when specifying them. Shell-style glob patterns
+ are allowed.
*CleanMethod =* KeepInstalled &| KeepCurrent::
If set to `KeepInstalled` (the default), the '-Sc' operation will clean
diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
index 6c2f0cb6..78615bb1 100644
--- a/lib/libalpm/add.c
+++ b/lib/libalpm/add.c
@@ -22,7 +22,6 @@
#include <stdlib.h>
#include <errno.h>
-#include <time.h>
#include <string.h>
#include <limits.h>
#include <fcntl.h>
@@ -132,6 +131,18 @@ static int perform_extraction(alpm_handle_t *handle, struct archive *archive,
return 0;
}
+static int try_rename(alpm_handle_t *handle, const char *src, const char *dest)
+{
+ if(rename(src, dest)) {
+ _alpm_log(handle, ALPM_LOG_ERROR, _("could not rename %s to %s (%s)\n"),
+ src, dest, strerror(errno));
+ alpm_logaction(handle, "error: could not rename %s to %s (%s)\n",
+ src, dest, strerror(errno));
+ return 1;
+ }
+ return 0;
+}
+
static int extract_single_file(alpm_handle_t *handle, struct archive *archive,
struct archive_entry *entry, alpm_pkg_t *newpkg, alpm_pkg_t *oldpkg)
{
@@ -146,8 +157,6 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive,
entryname = archive_entry_pathname(entry);
entrymode = archive_entry_mode(entry);
- memset(filename, 0, PATH_MAX); /* just to be sure */
-
if(strcmp(entryname, ".INSTALL") == 0) {
/* the install script goes inside the db */
snprintf(filename, PATH_MAX, "%s%s-%s/install",
@@ -170,7 +179,7 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive,
}
/* if a file is in NoExtract then we never extract it */
- if(alpm_list_find_str(handle->noextract, entryname)) {
+ if(alpm_list_find(handle->noextract, entryname, _alpm_fnmatch)) {
_alpm_log(handle, ALPM_LOG_DEBUG, "%s is in NoExtract, skipping extraction\n",
entryname);
alpm_logaction(handle, "note: %s is in NoExtract, skipping extraction\n",
@@ -250,7 +259,7 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive,
} else if(S_ISREG(entrymode)) {
/* case 4,7: */
/* if file is in NoUpgrade, don't touch it */
- if(alpm_list_find_str(handle->noupgrade, entryname)) {
+ if(alpm_list_find(handle->noupgrade, entryname, _alpm_fnmatch)) {
notouch = 1;
} else {
alpm_backup_t *backup;
@@ -282,17 +291,18 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive,
STRDUP(entryname_orig, entryname, RET_ERR(handle, ALPM_ERR_MEMORY, -1));
if(needbackup) {
- char checkfile[PATH_MAX];
+ char *checkfile;
char *hash_local = NULL, *hash_pkg = NULL;
- int ret;
+ size_t len;
- snprintf(checkfile, PATH_MAX, "%s.paccheck", filename);
+ len = strlen(filename) + 10;
+ MALLOC(checkfile, len,
+ errors++; handle->pm_errno = ALPM_ERR_MEMORY; goto needbackup_cleanup);
+ snprintf(checkfile, len, "%s.paccheck", filename);
- ret = perform_extraction(handle, archive, entry, checkfile, entryname_orig);
- if(ret == 1) {
- /* error */
- FREE(entryname_orig);
- return 1;
+ if(perform_extraction(handle, archive, entry, checkfile, entryname_orig)) {
+ errors++;
+ goto needbackup_cleanup;
}
hash_local = alpm_compute_md5sum(filename);
@@ -320,29 +330,26 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive,
if(hash_local && hash_pkg && strcmp(hash_local, hash_pkg) != 0) {
/* looks like we have a local file that has a different hash as the
* file in the package, move it to a .pacorig */
- char newpath[PATH_MAX];
- snprintf(newpath, PATH_MAX, "%s.pacorig", filename);
+ char *newpath;
+ size_t newlen = strlen(filename) + 9;
+ 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(rename(filename, newpath)) {
- _alpm_log(handle, ALPM_LOG_ERROR, _("could not rename %s to %s (%s)\n"),
- filename, newpath, strerror(errno));
- alpm_logaction(handle, "error: could not rename %s to %s (%s)\n",
- filename, newpath, strerror(errno));
+ if(try_rename(handle, filename, newpath)) {
+ errors++;
errors++;
} else {
/* rename the file we extracted to the real name */
- if(rename(checkfile, filename)) {
- _alpm_log(handle, ALPM_LOG_ERROR, _("could not rename %s to %s (%s)\n"),
- checkfile, filename, strerror(errno));
- alpm_logaction(handle, "error: could not rename %s to %s (%s)\n",
- checkfile, filename, strerror(errno));
+ if(try_rename(handle, checkfile, filename)) {
errors++;
} else {
_alpm_log(handle, ALPM_LOG_WARNING, _("%s saved as %s\n"), filename, newpath);
alpm_logaction(handle, "warning: %s saved as %s\n", filename, newpath);
}
}
+ free(newpath);
} else {
/* local file is identical to pkg one, so just remove pkg one */
unlink(checkfile);
@@ -356,11 +363,7 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive,
_alpm_log(handle, ALPM_LOG_DEBUG, "action: installing new file: %s\n",
entryname_orig);
- if(rename(checkfile, filename)) {
- _alpm_log(handle, ALPM_LOG_ERROR, _("could not rename %s to %s (%s)\n"),
- checkfile, filename, strerror(errno));
- alpm_logaction(handle, "error: could not rename %s to %s (%s)\n",
- checkfile, filename, strerror(errno));
+ if(try_rename(handle, checkfile, filename)) {
errors++;
}
} else {
@@ -382,29 +385,30 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive,
_alpm_log(handle, ALPM_LOG_DEBUG, "action: leaving existing file in place\n");
unlink(checkfile);
} else {
- char newpath[PATH_MAX];
+ char *newpath;
+ size_t newlen = strlen(filename) + 8;
_alpm_log(handle, ALPM_LOG_DEBUG, "action: keeping current file and installing"
" new one with .pacnew ending\n");
- snprintf(newpath, PATH_MAX, "%s.pacnew", filename);
- if(rename(checkfile, newpath)) {
- _alpm_log(handle, ALPM_LOG_ERROR, _("could not install %s as %s (%s)\n"),
- filename, newpath, strerror(errno));
- alpm_logaction(handle, "error: could not install %s as %s (%s)\n",
- filename, newpath, strerror(errno));
+ 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_log(handle, ALPM_LOG_WARNING, _("%s installed as %s\n"),
filename, newpath);
alpm_logaction(handle, "warning: %s installed as %s\n",
filename, newpath);
}
+ free(newpath);
}
}
- FREE(hash_local);
- FREE(hash_pkg);
+needbackup_cleanup:
+ free(checkfile);
+ free(hash_local);
+ free(hash_pkg);
} else {
- int ret;
-
/* we didn't need a backup */
if(notouch) {
/* change the path to a .pacnew extension */
@@ -423,11 +427,11 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive,
unlink(filename);
}
- ret = perform_extraction(handle, archive, entry, filename, entryname_orig);
- if(ret == 1) {
+ if(perform_extraction(handle, archive, entry, filename, entryname_orig)) {
/* error */
- FREE(entryname_orig);
- return 1;
+ free(entryname_orig);
+ errors++;
+ return errors;
}
/* calculate an hash if this is in newpkg's backup */
@@ -444,7 +448,7 @@ static int extract_single_file(alpm_handle_t *handle, struct archive *archive,
backup->hash = newhash;
}
}
- FREE(entryname_orig);
+ free(entryname_orig);
return errors;
}
@@ -521,31 +525,20 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg,
if(!(trans->flags & ALPM_TRANS_FLAG_DBONLY)) {
struct archive *archive;
struct archive_entry *entry;
- int cwdfd;
+ struct stat buf;
+ int fd, cwdfd;
_alpm_log(handle, ALPM_LOG_DEBUG, "extracting files\n");
- if((archive = archive_read_new()) == NULL) {
- handle->pm_errno = ALPM_ERR_LIBARCHIVE;
- ret = -1;
- goto cleanup;
- }
-
- archive_read_support_compression_all(archive);
- archive_read_support_format_all(archive);
-
- _alpm_log(handle, ALPM_LOG_DEBUG, "archive: %s\n", pkgfile);
- if(archive_read_open_filename(archive, pkgfile,
- ALPM_BUFFER_SIZE) != ARCHIVE_OK) {
- handle->pm_errno = ALPM_ERR_PKG_OPEN;
+ fd = _alpm_open_archive(db->handle, pkgfile, &buf,
+ &archive, ALPM_ERR_PKG_OPEN);
+ if(fd < 0) {
ret = -1;
goto cleanup;
}
/* save the cwd so we can restore it later */
- do {
- cwdfd = open(".", O_RDONLY);
- } while(cwdfd == -1 && errno == EINTR);
+ OPEN(cwdfd, ".", O_RDONLY);
if(cwdfd < 0) {
_alpm_log(handle, ALPM_LOG_ERROR, _("could not get current working directory\n"));
}
@@ -554,6 +547,8 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg,
if(chdir(handle->root) != 0) {
_alpm_log(handle, ALPM_LOG_ERROR, _("could not change directory to %s (%s)\n"),
handle->root, strerror(errno));
+ archive_read_finish(archive);
+ CLOSE(fd);
ret = -1;
goto cleanup;
}
@@ -595,6 +590,7 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg,
errors += extract_single_file(handle, archive, entry, newpkg, oldpkg);
}
archive_read_finish(archive);
+ CLOSE(fd);
/* restore the old cwd if we have it */
if(cwdfd >= 0) {
@@ -602,7 +598,7 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg,
_alpm_log(handle, ALPM_LOG_ERROR,
_("could not restore working directory (%s)\n"), strerror(errno));
}
- close(cwdfd);
+ CLOSE(cwdfd);
}
if(errors) {
diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c
index 38843342..e957f1aa 100644
--- a/lib/libalpm/alpm.c
+++ b/lib/libalpm/alpm.c
@@ -47,9 +47,9 @@
* @return a context handle on success, NULL on error, err will be set if provided
*/
alpm_handle_t SYMEXPORT *alpm_initialize(const char *root, const char *dbpath,
- enum _alpm_errno_t *err)
+ alpm_errno_t *err)
{
- enum _alpm_errno_t myerr;
+ alpm_errno_t myerr;
const char *lf = "db.lck";
size_t lockfilelen;
alpm_handle_t *myhandle = _alpm_handle_new();
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index a93d4e3e..1751c81c 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -27,9 +27,9 @@
extern "C" {
#endif
-#include <sys/types.h> /* for off_t */
-#include <time.h> /* for time_t */
-#include <stdarg.h> /* for va_list */
+#include <inttypes.h> /* int64_t */
+#include <sys/types.h> /* off_t */
+#include <stdarg.h> /* va_list */
#include <alpm_list.h>
@@ -44,6 +44,8 @@ extern "C" {
* @{
*/
+typedef int64_t alpm_time_t;
+
/*
* Enumerations
* These ones are used in multiple contexts, so are forward-declared.
@@ -222,8 +224,11 @@ typedef struct _alpm_pgpkey_t {
char *uid;
char *name;
char *email;
- time_t created;
- time_t expires;
+ alpm_time_t created;
+ alpm_time_t expires;
+ unsigned int length;
+ unsigned int revoked;
+ char pubkey_algo;
} alpm_pgpkey_t;
/** Signature result. Contains the key, status, and validity of a given
@@ -754,13 +759,13 @@ const char *alpm_pkg_get_url(alpm_pkg_t *pkg);
* @param pkg a pointer to package
* @return the timestamp of the build time
*/
-time_t alpm_pkg_get_builddate(alpm_pkg_t *pkg);
+alpm_time_t alpm_pkg_get_builddate(alpm_pkg_t *pkg);
/** Returns the install timestamp of the package.
* @param pkg a pointer to package
* @return the timestamp of the install time
*/
-time_t alpm_pkg_get_installdate(alpm_pkg_t *pkg);
+alpm_time_t alpm_pkg_get_installdate(alpm_pkg_t *pkg);
/** Returns the packager's name.
* @param pkg a pointer to package
@@ -1113,7 +1118,7 @@ char *alpm_compute_sha256sum(const char *filename);
/** @addtogroup alpm_api_errors Error Codes
* @{
*/
-enum _alpm_errno_t {
+typedef enum _alpm_errno_t {
ALPM_ERR_MEMORY = 1,
ALPM_ERR_SYSTEM,
ALPM_ERR_BADPERMS,
@@ -1177,19 +1182,19 @@ enum _alpm_errno_t {
ALPM_ERR_LIBCURL,
ALPM_ERR_EXTERNAL_DOWNLOAD,
ALPM_ERR_GPGME
-};
+} alpm_errno_t;
/** Returns the current error code from the handle. */
-enum _alpm_errno_t alpm_errno(alpm_handle_t *handle);
+alpm_errno_t alpm_errno(alpm_handle_t *handle);
/** Returns the string corresponding to an error number. */
-const char *alpm_strerror(enum _alpm_errno_t err);
+const char *alpm_strerror(alpm_errno_t err);
/* End of alpm_api_errors */
/** @} */
alpm_handle_t *alpm_initialize(const char *root, const char *dbpath,
- enum _alpm_errno_t *err);
+ alpm_errno_t *err);
int alpm_release(alpm_handle_t *handle);
enum alpm_caps {
diff --git a/lib/libalpm/alpm_list.c b/lib/libalpm/alpm_list.c
index 15286aa1..cad6d096 100644
--- a/lib/libalpm/alpm_list.c
+++ b/lib/libalpm/alpm_list.c
@@ -576,19 +576,6 @@ alpm_list_t SYMEXPORT *alpm_list_last(const alpm_list_t *list)
}
}
-/**
- * @brief Get the data member of a list node.
- *
- * @param node the list node
- *
- * @return the contained data, or NULL if none
- */
-void SYMEXPORT *alpm_list_getdata(const alpm_list_t *node)
-{
- if(node == NULL) return NULL;
- return node->data;
-}
-
/* Misc */
/**
diff --git a/lib/libalpm/alpm_list.h b/lib/libalpm/alpm_list.h
index cd7b0291..9f69e2c2 100644
--- a/lib/libalpm/alpm_list.h
+++ b/lib/libalpm/alpm_list.h
@@ -71,7 +71,6 @@ alpm_list_t *alpm_list_nth(const alpm_list_t *list, size_t n);
alpm_list_t *alpm_list_next(const alpm_list_t *list);
alpm_list_t *alpm_list_previous(const alpm_list_t *list);
alpm_list_t *alpm_list_last(const alpm_list_t *list);
-void *alpm_list_getdata(const alpm_list_t *entry);
/* misc */
size_t alpm_list_count(const alpm_list_t *list);
diff --git a/lib/libalpm/base64.c b/lib/libalpm/base64.c
index 5c9fa814..0d29f656 100644
--- a/lib/libalpm/base64.c
+++ b/lib/libalpm/base64.c
@@ -62,6 +62,7 @@ static const unsigned char base64_dec_map[128] =
49, 50, 51, 127, 127, 127, 127, 127
};
+#if 0
/*
* Encode a buffer into base64 format
*/
@@ -124,6 +125,7 @@ int base64_encode( unsigned char *dst, size_t *dlen,
return( 0 );
}
+#endif
/*
* Decode a base64-formatted buffer
diff --git a/lib/libalpm/base64.h b/lib/libalpm/base64.h
index 406aefa1..df684ab7 100644
--- a/lib/libalpm/base64.h
+++ b/lib/libalpm/base64.h
@@ -30,6 +30,7 @@
#define POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL -0x0010 /**< Output buffer too small. */
#define POLARSSL_ERR_BASE64_INVALID_CHARACTER -0x0012 /**< Invalid character in input. */
+#if 0
/**
* \brief Encode a buffer into base64 format
*
@@ -47,6 +48,7 @@
*/
int base64_encode( unsigned char *dst, size_t *dlen,
const unsigned char *src, size_t slen );
+#endif
/**
* \brief Decode a base64-formatted buffer
diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
index 56cf38bb..21d27481 100644
--- a/lib/libalpm/be_local.c
+++ b/lib/libalpm/be_local.c
@@ -28,7 +28,6 @@
#include <stdint.h> /* intmax_t */
#include <sys/stat.h>
#include <dirent.h>
-#include <time.h>
#include <limits.h> /* PATH_MAX */
/* libalpm */
@@ -69,13 +68,13 @@ static const char *_cache_get_url(alpm_pkg_t *pkg)
return pkg->url;
}
-static time_t _cache_get_builddate(alpm_pkg_t *pkg)
+static alpm_time_t _cache_get_builddate(alpm_pkg_t *pkg)
{
LAZY_LOAD(INFRQ_DESC, 0);
return pkg->builddate;
}
-static time_t _cache_get_installdate(alpm_pkg_t *pkg)
+static alpm_time_t _cache_get_installdate(alpm_pkg_t *pkg)
{
LAZY_LOAD(INFRQ_DESC, 0);
return pkg->installdate;
@@ -794,11 +793,11 @@ int _alpm_local_db_write(alpm_db_t *db, alpm_pkg_t *info, alpm_dbinfrq_t inforeq
}
if(info->builddate) {
fprintf(fp, "%%BUILDDATE%%\n"
- "%ld\n\n", info->builddate);
+ "%jd\n\n", (intmax_t)info->builddate);
}
if(info->installdate) {
fprintf(fp, "%%INSTALLDATE%%\n"
- "%ld\n\n", info->installdate);
+ "%jd\n\n", (intmax_t)info->installdate);
}
if(info->packager) {
fprintf(fp, "%%PACKAGER%%\n"
diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c
index 4d9d0e82..4f530e0b 100644
--- a/lib/libalpm/be_package.c
+++ b/lib/libalpm/be_package.c
@@ -23,6 +23,9 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
/* libarchive */
#include <archive.h>
@@ -37,6 +40,11 @@
#include "package.h"
#include "deps.h" /* _alpm_splitdep */
+struct package_changelog {
+ struct archive *archive;
+ int fd;
+};
+
/**
* Open a package changelog for reading. Similar to fopen in functionality,
* except that the returned 'file stream' is from an archive.
@@ -47,31 +55,38 @@ static void *_package_changelog_open(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return NULL);
- struct archive *archive = NULL;
+ struct package_changelog *changelog;
+ struct archive *archive;
struct archive_entry *entry;
const char *pkgfile = pkg->origin_data.file;
+ struct stat buf;
+ int fd;
- if((archive = archive_read_new()) == NULL) {
- RET_ERR(pkg->handle, ALPM_ERR_LIBARCHIVE, NULL);
- }
-
- archive_read_support_compression_all(archive);
- archive_read_support_format_all(archive);
-
- if(archive_read_open_filename(archive, pkgfile,
- ALPM_BUFFER_SIZE) != ARCHIVE_OK) {
- RET_ERR(pkg->handle, ALPM_ERR_PKG_OPEN, NULL);
+ fd = _alpm_open_archive(pkg->handle, pkgfile, &buf,
+ &archive, ALPM_ERR_PKG_OPEN);
+ if(fd < 0) {
+ return NULL;
}
while(archive_read_next_header(archive, &entry) == ARCHIVE_OK) {
const char *entry_name = archive_entry_pathname(entry);
if(strcmp(entry_name, ".CHANGELOG") == 0) {
- return archive;
+ changelog = malloc(sizeof(struct package_changelog));
+ if(!changelog) {
+ pkg->handle->pm_errno = ALPM_ERR_MEMORY;
+ archive_read_finish(archive);
+ CLOSE(fd);
+ return NULL;
+ }
+ changelog->archive = archive;
+ changelog->fd = fd;
+ return changelog;
}
}
/* we didn't find a changelog */
archive_read_finish(archive);
+ CLOSE(fd);
errno = ENOENT;
return NULL;
@@ -89,7 +104,8 @@ static void *_package_changelog_open(alpm_pkg_t *pkg)
static size_t _package_changelog_read(void *ptr, size_t size,
const alpm_pkg_t UNUSED *pkg, void *fp)
{
- ssize_t sret = archive_read_data((struct archive *)fp, ptr, size);
+ struct package_changelog *changelog = fp;
+ ssize_t sret = archive_read_data(changelog->archive, ptr, size);
/* Report error (negative values) */
if(sret < 0) {
RET_ERR(pkg->handle, ALPM_ERR_LIBARCHIVE, 0);
@@ -107,7 +123,12 @@ static size_t _package_changelog_read(void *ptr, size_t size,
*/
static int _package_changelog_close(const alpm_pkg_t UNUSED *pkg, void *fp)
{
- return archive_read_finish((struct archive *)fp);
+ int ret;
+ struct package_changelog *changelog = fp;
+ ret = archive_read_finish(changelog->archive);
+ CLOSE(changelog->fd);
+ free(changelog);
+ return ret;
}
/** Package file operations struct accessor. We implement this as a method
@@ -355,7 +376,7 @@ int _alpm_pkg_validate_internal(alpm_handle_t *handle,
alpm_pkg_t *_alpm_pkg_load_internal(alpm_handle_t *handle,
const char *pkgfile, int full)
{
- int ret, config = 0;
+ int ret, fd, config = 0;
struct archive *archive;
struct archive_entry *entry;
alpm_pkg_t *newpkg = NULL;
@@ -367,33 +388,22 @@ alpm_pkg_t *_alpm_pkg_load_internal(alpm_handle_t *handle,
RET_ERR(handle, ALPM_ERR_WRONG_ARGS, NULL);
}
- /* attempt to stat the package file, ensure it exists */
- if(stat(pkgfile, &st) == 0) {
- newpkg = _alpm_pkg_new();
- if(newpkg == NULL) {
- RET_ERR(handle, ALPM_ERR_MEMORY, NULL);
+ fd = _alpm_open_archive(handle, pkgfile, &st, &archive, ALPM_ERR_PKG_OPEN);
+ if(fd < 0) {
+ if(errno == ENOENT) {
+ handle->pm_errno = ALPM_ERR_PKG_NOT_FOUND;
}
- newpkg->filename = strdup(pkgfile);
- newpkg->size = st.st_size;
- } else {
- /* couldn't stat the pkgfile, return an error */
- RET_ERR(handle, ALPM_ERR_PKG_NOT_FOUND, NULL);
- }
-
- /* try to create an archive object to read in the package */
- if((archive = archive_read_new()) == NULL) {
- alpm_pkg_free(newpkg);
- RET_ERR(handle, ALPM_ERR_LIBARCHIVE, NULL);
+ goto error;
}
- archive_read_support_compression_all(archive);
- archive_read_support_format_all(archive);
-
- if(archive_read_open_filename(archive, pkgfile,
- ALPM_BUFFER_SIZE) != ARCHIVE_OK) {
- alpm_pkg_free(newpkg);
- RET_ERR(handle, ALPM_ERR_PKG_OPEN, NULL);
+ newpkg = _alpm_pkg_new();
+ if(newpkg == NULL) {
+ handle->pm_errno = ALPM_ERR_MEMORY;
+ goto error;
}
+ STRDUP(newpkg->filename, pkgfile,
+ handle->pm_errno = ALPM_ERR_MEMORY; goto error);
+ newpkg->size = st.st_size;
_alpm_log(handle, ALPM_LOG_DEBUG, "starting package load for %s\n", pkgfile);
@@ -476,6 +486,7 @@ alpm_pkg_t *_alpm_pkg_load_internal(alpm_handle_t *handle,
}
archive_read_finish(archive);
+ CLOSE(fd);
/* internal fields for package struct */
newpkg->origin = PKG_FROM_FILE;
@@ -504,6 +515,9 @@ pkg_invalid:
error:
_alpm_pkg_free(newpkg);
archive_read_finish(archive);
+ if(fd >= 0) {
+ CLOSE(fd);
+ }
return NULL;
}
diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c
index 3c990246..54c4f879 100644
--- a/lib/libalpm/be_sync.c
+++ b/lib/libalpm/be_sync.c
@@ -21,7 +21,9 @@
#include "config.h"
#include <errno.h>
+#include <sys/types.h>
#include <sys/stat.h>
+#include <fcntl.h>
#include <unistd.h>
/* libarchive */
@@ -212,6 +214,7 @@ int SYMEXPORT alpm_db_update(int force, alpm_db_t *db)
/* print server + filename into a buffer */
len = strlen(server) + strlen(db->treename) + 5;
+ /* TODO fix leak syncpath and umask unset */
MALLOC(payload.fileurl, len, RET_ERR(handle, ALPM_ERR_MEMORY, -1));
snprintf(payload.fileurl, len, "%s/%s.db", server, db->treename);
payload.handle = handle;
@@ -234,6 +237,7 @@ int SYMEXPORT alpm_db_update(int force, alpm_db_t *db)
/* if we downloaded a DB, we want the .sig from the same server */
/* print server + filename into a buffer (leave space for .sig) */
len = strlen(server) + strlen(db->treename) + 9;
+ /* TODO fix leak syncpath and umask unset */
MALLOC(payload.fileurl, len, RET_ERR(handle, ALPM_ERR_MEMORY, -1));
snprintf(payload.fileurl, len, "%s/%s.db.sig", server, db->treename);
payload.handle = handle;
@@ -411,7 +415,7 @@ static int sync_db_populate(alpm_db_t *db)
{
const char *dbpath;
size_t est_count;
- int count = 0;
+ int count = -1, fd;
struct stat buf;
struct archive *archive;
struct archive_entry *entry;
@@ -423,38 +427,24 @@ static int sync_db_populate(alpm_db_t *db)
if(db->status & DB_STATUS_MISSING) {
RET_ERR(db->handle, ALPM_ERR_DB_NOT_FOUND, -1);
}
-
- if((archive = archive_read_new()) == NULL) {
- RET_ERR(db->handle, ALPM_ERR_LIBARCHIVE, -1);
- }
-
- archive_read_support_compression_all(archive);
- archive_read_support_format_all(archive);
-
dbpath = _alpm_db_path(db);
if(!dbpath) {
/* pm_errno set in _alpm_db_path() */
return -1;
}
- _alpm_log(db->handle, ALPM_LOG_DEBUG, "opening database archive %s\n", dbpath);
-
- if(archive_read_open_filename(archive, dbpath,
- ALPM_BUFFER_SIZE) != ARCHIVE_OK) {
- _alpm_log(db->handle, ALPM_LOG_ERROR, _("could not open file %s: %s\n"), dbpath,
- archive_error_string(archive));
- archive_read_finish(archive);
- RET_ERR(db->handle, ALPM_ERR_DB_OPEN, -1);
- }
- if(stat(dbpath, &buf) != 0) {
- RET_ERR(db->handle, ALPM_ERR_DB_OPEN, -1);
+ fd = _alpm_open_archive(db->handle, dbpath, &buf,
+ &archive, ALPM_ERR_DB_OPEN);
+ if(fd < 0) {
+ goto cleanup;
}
est_count = estimate_package_count(&buf, archive);
/* initialize hash at 66% full */
db->pkgcache = _alpm_pkghash_create(est_count * 3 / 2);
if(db->pkgcache == NULL) {
- RET_ERR(db->handle, ALPM_ERR_MEMORY, -1);
+ db->handle->pm_errno = ALPM_ERR_MEMORY;
+ goto cleanup;
}
while(archive_read_next_header(archive, &entry) == ARCHIVE_OK) {
@@ -473,14 +463,19 @@ static int sync_db_populate(alpm_db_t *db)
}
count = alpm_list_count(db->pkgcache->list);
-
if(count > 0) {
- db->pkgcache->list = alpm_list_msort(db->pkgcache->list, (size_t)count, _alpm_pkg_cmp);
+ db->pkgcache->list = alpm_list_msort(db->pkgcache->list,
+ (size_t)count, _alpm_pkg_cmp);
}
- archive_read_finish(archive);
- _alpm_log(db->handle, ALPM_LOG_DEBUG, "added %d packages to package cache for db '%s'\n",
+ _alpm_log(db->handle, ALPM_LOG_DEBUG,
+ "added %d packages to package cache for db '%s'\n",
count, db->treename);
+cleanup:
+ archive_read_finish(archive);
+ if(fd >= 0) {
+ CLOSE(fd);
+ }
return count;
}
diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c
index 32f6f303..486f4bf3 100644
--- a/lib/libalpm/conflict.c
+++ b/lib/libalpm/conflict.c
@@ -318,12 +318,16 @@ const alpm_file_t *_alpm_filelist_contains(alpm_filelist_t *filelist,
const char *name)
{
size_t i;
- const alpm_file_t *file = filelist->files;
- for(i = 0; i < filelist->count; i++) {
+ const alpm_file_t *file;
+
+ if(!filelist) {
+ return NULL;
+ }
+
+ for(file = filelist->files, i = 0; i < filelist->count; file++, i++) {
if(strcmp(file->name, name) == 0) {
return file;
}
- file++;
}
return NULL;
}
diff --git a/lib/libalpm/db.h b/lib/libalpm/db.h
index 224bfbeb..a1249d3e 100644
--- a/lib/libalpm/db.h
+++ b/lib/libalpm/db.h
@@ -22,8 +22,6 @@
#ifndef _ALPM_DB_H
#define _ALPM_DB_H
-#include <time.h>
-
/* libarchive */
#include <archive.h>
#include <archive_entry.h>
diff --git a/lib/libalpm/diskspace.c b/lib/libalpm/diskspace.c
index fe2036d5..cfd6402c 100644
--- a/lib/libalpm/diskspace.c
+++ b/lib/libalpm/diskspace.c
@@ -55,6 +55,17 @@ static int mount_point_cmp(const void *p1, const void *p2)
return -strcmp(mp1->mount_dir, mp2->mount_dir);
}
+static void mount_point_list_free(alpm_list_t *mount_points)
+{
+ alpm_list_t *i;
+
+ for(i = mount_points; i; i = i->next) {
+ alpm_mountpoint_t *data = i->data;
+ FREE(data->mount_dir);
+ }
+ FREELIST(mount_points);
+}
+
static alpm_list_t *mount_point_list(alpm_handle_t *handle)
{
alpm_list_t *mount_points = NULL, *ptr;
@@ -232,6 +243,72 @@ static int calculate_installed_size(alpm_handle_t *handle,
return 0;
}
+static int check_mountpoint(alpm_handle_t *handle, alpm_mountpoint_t *mp)
+{
+ /* cushion is roughly min(5% capacity, 20MiB) */
+ fsblkcnt_t fivepc = (mp->fsp.f_blocks / 20) + 1;
+ fsblkcnt_t twentymb = (20 * 1024 * 1024 / mp->fsp.f_bsize) + 1;
+ fsblkcnt_t cushion = fivepc < twentymb ? fivepc : twentymb;
+ blkcnt_t needed = mp->max_blocks_needed + cushion;
+
+ _alpm_log(handle, ALPM_LOG_DEBUG,
+ "partition %s, needed %jd, cushion %ju, free %ju\n",
+ mp->mount_dir, (intmax_t)mp->max_blocks_needed,
+ (uintmax_t)cushion, (uintmax_t)mp->fsp.f_bfree);
+ if(needed >= 0 && (fsblkcnt_t)needed > mp->fsp.f_bfree) {
+ _alpm_log(handle, ALPM_LOG_ERROR,
+ _("Partition %s too full: %jd blocks needed, %jd blocks free\n"),
+ mp->mount_dir, (intmax_t)needed, (uintmax_t)mp->fsp.f_bfree);
+ return 1;
+ }
+ return 0;
+}
+
+int _alpm_check_downloadspace(alpm_handle_t *handle, const char *cachedir,
+ size_t num_files, off_t *file_sizes)
+{
+ alpm_list_t *mount_points;
+ alpm_mountpoint_t *cachedir_mp;
+ size_t j;
+ int error = 0;
+
+ mount_points = mount_point_list(handle);
+ if(mount_points == NULL) {
+ _alpm_log(handle, ALPM_LOG_ERROR, _("could not determine filesystem mount points\n"));
+ return -1;
+ }
+
+ cachedir_mp = match_mount_point(mount_points, cachedir);
+ if(cachedir == NULL) {
+ _alpm_log(handle, ALPM_LOG_ERROR, _("could not determine cachedir mount point %s\n"),
+ cachedir);
+ error = 1;
+ goto finish;
+ }
+
+ /* there's no need to check for a R/O mounted filesystem here, as
+ * _alpm_filecache_setup will never give us a non-writable directory */
+
+ /* round up the size of each file to the nearest block and accumulate */
+ for(j = 0; j < num_files; j++) {
+ cachedir_mp->max_blocks_needed += (file_sizes[j] + cachedir_mp->fsp.f_bsize + 1) /
+ cachedir_mp->fsp.f_bsize;
+ }
+
+ if(check_mountpoint(handle, cachedir_mp)) {
+ error = 1;
+ }
+
+finish:
+ mount_point_list_free(mount_points);
+
+ if(error) {
+ RET_ERR(handle, ALPM_ERR_DISK_SPACE, -1);
+ }
+
+ return 0;
+}
+
int _alpm_check_diskspace(alpm_handle_t *handle)
{
alpm_list_t *mount_points, *i;
@@ -300,32 +377,13 @@ int _alpm_check_diskspace(alpm_handle_t *handle)
_alpm_log(handle, ALPM_LOG_ERROR, _("Partition %s is mounted read only\n"),
data->mount_dir);
error = 1;
- } else if(data->used & USED_INSTALL) {
- /* cushion is roughly min(5% capacity, 20MiB) */
- fsblkcnt_t fivepc = (data->fsp.f_blocks / 20) + 1;
- fsblkcnt_t twentymb = (20 * 1024 * 1024 / data->fsp.f_bsize) + 1;
- fsblkcnt_t cushion = fivepc < twentymb ? fivepc : twentymb;
- blkcnt_t needed = data->max_blocks_needed + cushion;
-
- _alpm_log(handle, ALPM_LOG_DEBUG,
- "partition %s, needed %jd, cushion %ju, free %ju\n",
- data->mount_dir, (intmax_t)data->max_blocks_needed,
- (uintmax_t)cushion, (uintmax_t)data->fsp.f_bfree);
- if(needed >= 0 && (fsblkcnt_t)needed > data->fsp.f_bfree) {
- _alpm_log(handle, ALPM_LOG_ERROR,
- _("Partition %s too full: %jd blocks needed, %jd blocks free\n"),
- data->mount_dir, (intmax_t)needed, (uintmax_t)data->fsp.f_bfree);
- error = 1;
- }
+ } else if(data->used & USED_INSTALL && check_mountpoint(handle, data)) {
+ error = 1;
}
}
finish:
- for(i = mount_points; i; i = i->next) {
- alpm_mountpoint_t *data = i->data;
- FREE(data->mount_dir);
- }
- FREELIST(mount_points);
+ mount_point_list_free(mount_points);
if(error) {
RET_ERR(handle, ALPM_ERR_DISK_SPACE, -1);
diff --git a/lib/libalpm/diskspace.h b/lib/libalpm/diskspace.h
index 5944bb17..a613e232 100644
--- a/lib/libalpm/diskspace.h
+++ b/lib/libalpm/diskspace.h
@@ -50,6 +50,8 @@ typedef struct __alpm_mountpoint_t {
} alpm_mountpoint_t;
int _alpm_check_diskspace(alpm_handle_t *handle);
+int _alpm_check_downloadspace(alpm_handle_t *handle, const char *cachedir,
+ size_t num_files, off_t *file_sizes);
#endif /* _ALPM_DISKSPACE_H */
diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c
index efd469d5..76bb00f9 100644
--- a/lib/libalpm/dload.c
+++ b/lib/libalpm/dload.c
@@ -306,9 +306,7 @@ static FILE *create_tempfile(struct dload_payload *payload, const char *localpat
fchmod(fd, ~(_getumask()) & 0666) ||
!(fp = fdopen(fd, payload->tempfile_openmode))) {
unlink(randpath);
- if(fd >= 0) {
- close(fd);
- }
+ CLOSE(fd);
_alpm_log(payload->handle, ALPM_LOG_ERROR,
_("failed to create temporary file for download\n"));
return NULL;
diff --git a/lib/libalpm/dload.h b/lib/libalpm/dload.h
index f5f2cd9c..9ab90b42 100644
--- a/lib/libalpm/dload.h
+++ b/lib/libalpm/dload.h
@@ -23,8 +23,6 @@
#include "alpm_list.h"
#include "alpm.h"
-#include <time.h>
-
struct dload_payload {
alpm_handle_t *handle;
const char *tempfile_openmode;
@@ -40,6 +38,7 @@ struct dload_payload {
int allow_resume;
int errors_ok;
int unlink_on_fail;
+ alpm_list_t *servers;
#ifdef HAVE_LIBCURL
CURLcode curlerr; /* last error produced by curl */
#endif
diff --git a/lib/libalpm/error.c b/lib/libalpm/error.c
index b3f56819..044dec7c 100644
--- a/lib/libalpm/error.c
+++ b/lib/libalpm/error.c
@@ -29,12 +29,12 @@
#include "alpm.h"
#include "handle.h"
-enum _alpm_errno_t SYMEXPORT alpm_errno(alpm_handle_t *handle)
+alpm_errno_t SYMEXPORT alpm_errno(alpm_handle_t *handle)
{
return handle->pm_errno;
}
-const char SYMEXPORT *alpm_strerror(enum _alpm_errno_t err)
+const char SYMEXPORT *alpm_strerror(alpm_errno_t err)
{
switch(err) {
/* System */
diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c
index 7402be50..01f59555 100644
--- a/lib/libalpm/handle.c
+++ b/lib/libalpm/handle.c
@@ -339,7 +339,7 @@ static char *canonicalize_path(const char *path) {
return new_path;
}
-enum _alpm_errno_t _alpm_set_directory_option(const char *value,
+alpm_errno_t _alpm_set_directory_option(const char *value,
char **storage, int must_exist)
{
struct stat st;
diff --git a/lib/libalpm/handle.h b/lib/libalpm/handle.h
index 8477dcae..d568fb42 100644
--- a/lib/libalpm/handle.h
+++ b/lib/libalpm/handle.h
@@ -93,7 +93,7 @@ struct __alpm_handle_t {
alpm_siglevel_t siglevel; /* Default signature verification level */
/* error code */
- enum _alpm_errno_t pm_errno;
+ alpm_errno_t pm_errno;
};
alpm_handle_t *_alpm_handle_new(void);
@@ -102,7 +102,7 @@ void _alpm_handle_free(alpm_handle_t *handle);
int _alpm_handle_lock(alpm_handle_t *handle);
int _alpm_handle_unlock(alpm_handle_t *handle);
-enum _alpm_errno_t _alpm_set_directory_option(const char *value,
+alpm_errno_t _alpm_set_directory_option(const char *value,
char **storage, int must_exist);
#endif /* _ALPM_HANDLE_H */
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index a5ff238f..e96177a2 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -87,12 +87,12 @@ int SYMEXPORT alpm_pkg_checkmd5sum(alpm_pkg_t *pkg)
* populated package structures. */
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 time_t _pkg_get_builddate(alpm_pkg_t *pkg) { return pkg->builddate; }
-static time_t _pkg_get_installdate(alpm_pkg_t *pkg) { return pkg->installdate; }
+static alpm_time_t _pkg_get_builddate(alpm_pkg_t *pkg) { return pkg->builddate; }
+static alpm_time_t _pkg_get_installdate(alpm_pkg_t *pkg) { return pkg->installdate; }
static const char *_pkg_get_packager(alpm_pkg_t *pkg) { return pkg->packager; }
static const char *_pkg_get_arch(alpm_pkg_t *pkg) { return pkg->arch; }
static off_t _pkg_get_isize(alpm_pkg_t *pkg) { return pkg->isize; }
-static alpm_pkgreason_t _pkg_get_reason(alpm_pkg_t *pkg) { return pkg->reason; }
+static alpm_pkgreason_t _pkg_get_reason(alpm_pkg_t *pkg) { return pkg->reason; }
static int _pkg_has_scriptlet(alpm_pkg_t *pkg) { return pkg->scriptlet; }
static alpm_list_t *_pkg_get_licenses(alpm_pkg_t *pkg) { return pkg->licenses; }
@@ -200,14 +200,14 @@ const char SYMEXPORT *alpm_pkg_get_url(alpm_pkg_t *pkg)
return pkg->ops->get_url(pkg);
}
-time_t SYMEXPORT alpm_pkg_get_builddate(alpm_pkg_t *pkg)
+alpm_time_t SYMEXPORT alpm_pkg_get_builddate(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return -1);
pkg->handle->pm_errno = 0;
return pkg->ops->get_builddate(pkg);
}
-time_t SYMEXPORT alpm_pkg_get_installdate(alpm_pkg_t *pkg)
+alpm_time_t SYMEXPORT alpm_pkg_get_installdate(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return -1);
pkg->handle->pm_errno = 0;
@@ -461,6 +461,15 @@ alpm_pkg_t *_alpm_pkg_new(void)
return pkg;
}
+static alpm_list_t *list_depdup(alpm_list_t *old)
+{
+ alpm_list_t *i, *new = NULL;
+ for(i = old; i; i = i->next) {
+ new = alpm_list_add(new, _alpm_dep_dup(i->data));
+ }
+ return new;
+}
+
/**
* Duplicate a package data struct.
* @param pkg the package to duplicate
@@ -509,10 +518,19 @@ int _alpm_pkg_dup(alpm_pkg_t *pkg, alpm_pkg_t **new_ptr)
newpkg->reason = pkg->reason;
newpkg->licenses = alpm_list_strdup(pkg->licenses);
- for(i = pkg->replaces; i; i = i->next) {
- newpkg->replaces = alpm_list_add(newpkg->replaces, _alpm_dep_dup(i->data));
- }
+ newpkg->replaces = list_depdup(pkg->replaces);
newpkg->groups = alpm_list_strdup(pkg->groups);
+ for(i = pkg->backup; i; i = i->next) {
+ newpkg->backup = alpm_list_add(newpkg->backup, _alpm_backup_dup(i->data));
+ }
+ newpkg->depends = list_depdup(pkg->depends);
+ newpkg->optdepends = alpm_list_strdup(pkg->optdepends);
+ newpkg->conflicts = list_depdup(pkg->conflicts);
+ newpkg->provides = list_depdup(pkg->provides);
+ for(i = pkg->deltas; i; i = i->next) {
+ newpkg->deltas = alpm_list_add(newpkg->deltas, _alpm_delta_dup(i->data));
+ }
+
if(pkg->files.count) {
size_t filenum;
size_t len = sizeof(alpm_file_t) * pkg->files.count;
@@ -525,22 +543,6 @@ int _alpm_pkg_dup(alpm_pkg_t *pkg, alpm_pkg_t **new_ptr)
}
newpkg->files.count = pkg->files.count;
}
- for(i = pkg->backup; i; i = i->next) {
- newpkg->backup = alpm_list_add(newpkg->backup, _alpm_backup_dup(i->data));
- }
- for(i = pkg->depends; i; i = i->next) {
- newpkg->depends = alpm_list_add(newpkg->depends, _alpm_dep_dup(i->data));
- }
- newpkg->optdepends = alpm_list_strdup(pkg->optdepends);
- for(i = pkg->conflicts; i; i = i->next) {
- newpkg->conflicts = alpm_list_add(newpkg->conflicts, _alpm_dep_dup(i->data));
- }
- for(i = pkg->provides; i; i = i->next) {
- newpkg->provides = alpm_list_add(newpkg->provides, _alpm_dep_dup(i->data));
- }
- for(i = pkg->deltas; i; i = i->next) {
- newpkg->deltas = alpm_list_add(newpkg->deltas, _alpm_delta_dup(i->data));
- }
/* internal */
newpkg->infolevel = pkg->infolevel;
@@ -561,6 +563,12 @@ cleanup:
RET_ERR(pkg->handle, ALPM_ERR_MEMORY, -1);
}
+static void free_deplist(alpm_list_t *deps)
+{
+ alpm_list_free_inner(deps, (alpm_list_fn_free)_alpm_dep_free);
+ alpm_list_free(deps);
+}
+
void _alpm_pkg_free(alpm_pkg_t *pkg)
{
if(pkg == NULL) {
@@ -579,8 +587,7 @@ void _alpm_pkg_free(alpm_pkg_t *pkg)
FREE(pkg->arch);
FREELIST(pkg->licenses);
- alpm_list_free_inner(pkg->replaces, (alpm_list_fn_free)_alpm_dep_free);
- alpm_list_free(pkg->replaces);
+ free_deplist(pkg->replaces);
FREELIST(pkg->groups);
if(pkg->files.count) {
size_t i;
@@ -591,13 +598,10 @@ void _alpm_pkg_free(alpm_pkg_t *pkg)
}
alpm_list_free_inner(pkg->backup, (alpm_list_fn_free)_alpm_backup_free);
alpm_list_free(pkg->backup);
- alpm_list_free_inner(pkg->depends, (alpm_list_fn_free)_alpm_dep_free);
- alpm_list_free(pkg->depends);
+ free_deplist(pkg->depends);
FREELIST(pkg->optdepends);
- alpm_list_free_inner(pkg->conflicts, (alpm_list_fn_free)_alpm_dep_free);
- alpm_list_free(pkg->conflicts);
- alpm_list_free_inner(pkg->provides, (alpm_list_fn_free)_alpm_dep_free);
- alpm_list_free(pkg->provides);
+ free_deplist(pkg->conflicts);
+ free_deplist(pkg->provides);
alpm_list_free_inner(pkg->deltas, (alpm_list_fn_free)_alpm_delta_free);
alpm_list_free(pkg->deltas);
alpm_list_free(pkg->delta_path);
@@ -690,14 +694,14 @@ int _alpm_pkg_should_ignore(alpm_handle_t *handle, alpm_pkg_t *pkg)
alpm_list_t *groups = NULL;
/* first see if the package is ignored */
- if(alpm_list_find_str(handle->ignorepkg, pkg->name)) {
+ if(alpm_list_find(handle->ignorepkg, pkg->name, _alpm_fnmatch)) {
return 1;
}
/* next see if the package is in a group that is ignored */
- for(groups = handle->ignoregroup; groups; groups = groups->next) {
+ for(groups = alpm_pkg_get_groups(pkg); groups; groups = groups->next) {
char *grp = groups->data;
- if(alpm_list_find_str(alpm_pkg_get_groups(pkg), grp)) {
+ if(alpm_list_find(handle->ignoregroup, grp, _alpm_fnmatch)) {
return 1;
}
}
diff --git a/lib/libalpm/package.h b/lib/libalpm/package.h
index eff7d898..82a83264 100644
--- a/lib/libalpm/package.h
+++ b/lib/libalpm/package.h
@@ -27,7 +27,6 @@
#include "config.h" /* ensure off_t is correct length */
#include <sys/types.h> /* off_t */
-#include <time.h> /* time_t */
#include "alpm.h"
#include "backup.h"
@@ -44,8 +43,8 @@
struct pkg_operations {
const char *(*get_desc) (alpm_pkg_t *);
const char *(*get_url) (alpm_pkg_t *);
- time_t (*get_builddate) (alpm_pkg_t *);
- time_t (*get_installdate) (alpm_pkg_t *);
+ alpm_time_t (*get_builddate) (alpm_pkg_t *);
+ alpm_time_t (*get_installdate) (alpm_pkg_t *);
const char *(*get_packager) (alpm_pkg_t *);
const char *(*get_arch) (alpm_pkg_t *);
off_t (*get_isize) (alpm_pkg_t *);
@@ -89,8 +88,8 @@ struct __alpm_pkg_t {
char *base64_sig;
char *arch;
- time_t builddate;
- time_t installdate;
+ alpm_time_t builddate;
+ alpm_time_t installdate;
off_t size;
off_t isize;
diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c
index 44f3ee93..d7e06bc8 100644
--- a/lib/libalpm/remove.c
+++ b/lib/libalpm/remove.c
@@ -216,7 +216,7 @@ static int can_remove_file(alpm_handle_t *handle, const alpm_file_t *file,
{
char filepath[PATH_MAX];
- if(alpm_list_find_str(skip_remove, file->name)) {
+ if(alpm_list_find(skip_remove, file->name, _alpm_fnmatch)) {
/* return success because we will never actually remove this file */
return 1;
}
@@ -239,8 +239,9 @@ static int can_remove_file(alpm_handle_t *handle, const alpm_file_t *file,
/* Helper function for iterating through a package's file and deleting them
* Used by _alpm_remove_commit. */
-static int unlink_file(alpm_handle_t *handle, alpm_pkg_t *info,
- const alpm_file_t *fileobj, alpm_list_t *skip_remove, int nosave)
+static int unlink_file(alpm_handle_t *handle, alpm_pkg_t *oldpkg,
+ alpm_pkg_t *newpkg, const alpm_file_t *fileobj, alpm_list_t *skip_remove,
+ int nosave)
{
struct stat buf;
char file[PATH_MAX];
@@ -250,7 +251,7 @@ static int unlink_file(alpm_handle_t *handle, alpm_pkg_t *info,
/* check the remove skip list before removing the file.
* see the big comment block in db_find_fileconflicts() for an
* explanation. */
- if(alpm_list_find_str(skip_remove, fileobj->name)) {
+ if(alpm_list_find(skip_remove, fileobj->name, _alpm_fnmatch)) {
_alpm_log(handle, ALPM_LOG_DEBUG,
"%s is in skip_remove, skipping removal\n", file);
return 1;
@@ -274,6 +275,10 @@ static int unlink_file(alpm_handle_t *handle, alpm_pkg_t *info,
} else if(files < 0) {
_alpm_log(handle, ALPM_LOG_DEBUG,
"keeping directory %s (could not count files)\n", file);
+ } else if(newpkg && _alpm_filelist_contains(alpm_pkg_get_files(newpkg),
+ fileobj->name)) {
+ _alpm_log(handle, ALPM_LOG_DEBUG,
+ "keeping directory %s (in new package)\n", file);
} else {
/* one last check- does any other package own this file? */
alpm_list_t *local, *local_pkgs;
@@ -285,7 +290,8 @@ static int unlink_file(alpm_handle_t *handle, alpm_pkg_t *info,
/* we duplicated the package when we put it in the removal list, so we
* so we can't use direct pointer comparison here. */
- if(_alpm_pkg_cmp(info, local_pkg) == 0) {
+ if(oldpkg->name_hash == local_pkg->name_hash
+ && strcmp(oldpkg->name, local_pkg->name) == 0) {
continue;
}
filelist = alpm_pkg_get_files(local_pkg);
@@ -308,7 +314,7 @@ static int unlink_file(alpm_handle_t *handle, alpm_pkg_t *info,
}
} else {
/* if the file needs backup and has been modified, back it up to .pacsave */
- alpm_backup_t *backup = _alpm_needbackup(fileobj->name, info);
+ alpm_backup_t *backup = _alpm_needbackup(fileobj->name, oldpkg);
if(backup) {
if(nosave) {
_alpm_log(handle, ALPM_LOG_DEBUG, "transaction is set to NOSAVE, not backing up '%s'\n", file);
@@ -431,7 +437,7 @@ int _alpm_remove_single_package(alpm_handle_t *handle,
alpm_file_t *file = filelist->files + i - 1;
int percent;
/* TODO: check return code and handle accordingly */
- unlink_file(handle, oldpkg, file, skip_remove,
+ unlink_file(handle, oldpkg, newpkg, file, skip_remove,
handle->trans->flags & ALPM_TRANS_FLAG_NOSAVE);
if(!newpkg) {
diff --git a/lib/libalpm/signing.c b/lib/libalpm/signing.c
index 92f34b56..0bef4451 100644
--- a/lib/libalpm/signing.c
+++ b/lib/libalpm/signing.c
@@ -270,6 +270,28 @@ static int key_search(alpm_handle_t *handle, const char *fpr,
pgpkey->email = key->uids->email;
pgpkey->created = key->subkeys->timestamp;
pgpkey->expires = key->subkeys->expires;
+ pgpkey->length = key->subkeys->length;
+ pgpkey->revoked = key->subkeys->revoked;
+
+ switch (key->subkeys->pubkey_algo) {
+ case GPGME_PK_RSA:
+ case GPGME_PK_RSA_E:
+ case GPGME_PK_RSA_S:
+ pgpkey->pubkey_algo = 'R';
+ break;
+
+ case GPGME_PK_DSA:
+ pgpkey->pubkey_algo = 'D';
+ break;
+
+ case GPGME_PK_ELG_E:
+ case GPGME_PK_ELG:
+ case GPGME_PK_ECDSA:
+ case GPGME_PK_ECDH:
+ pgpkey->pubkey_algo = 'E';
+ break;
+ }
+
ret = 1;
error:
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index cf209717..3817ec84 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -423,7 +423,7 @@ int _alpm_sync_prepare(alpm_handle_t *handle, alpm_list_t **data)
see if they'd like to ignore them rather than failing the sync */
if(unresolvable != NULL) {
int remove_unresolvable = 0;
- enum _alpm_errno_t saved_err = handle->pm_errno;
+ alpm_errno_t saved_err = handle->pm_errno;
QUESTION(handle, ALPM_QUESTION_REMOVE_PKGS, unresolvable,
NULL, NULL, &remove_unresolvable);
if(remove_unresolvable) {
@@ -695,11 +695,11 @@ static int apply_deltas(alpm_handle_t *handle)
} else {
/* len = cachedir len + from len + '/' + null */
len = strlen(cachedir) + strlen(d->from) + 2;
- CALLOC(from, len, sizeof(char), RET_ERR(handle, ALPM_ERR_MEMORY, 1));
+ MALLOC(from, len, RET_ERR(handle, ALPM_ERR_MEMORY, 1));
snprintf(from, len, "%s/%s", cachedir, d->from);
}
len = strlen(cachedir) + strlen(d->to) + 2;
- CALLOC(to, len, sizeof(char), RET_ERR(handle, ALPM_ERR_MEMORY, 1));
+ MALLOC(to, len, RET_ERR(handle, ALPM_ERR_MEMORY, 1));
snprintf(to, len, "%s/%s", cachedir, d->to);
/* build the patch command */
@@ -757,7 +757,7 @@ static int apply_deltas(alpm_handle_t *handle)
* @return 1 if file was removed, 0 otherwise
*/
static int prompt_to_delete(alpm_handle_t *handle, const char *filepath,
- enum _alpm_errno_t reason)
+ alpm_errno_t reason)
{
int doremove = 0;
QUESTION(handle, ALPM_QUESTION_CORRUPTED_PKG, (char *)filepath,
@@ -803,11 +803,92 @@ static int validate_deltas(alpm_handle_t *handle, alpm_list_t *deltas)
return 0;
}
+static struct dload_payload *build_payload(alpm_handle_t *handle,
+ const char *filename, size_t size, alpm_list_t *servers)
+{
+ 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));
+ payload->max_size = size;
+ payload->servers = servers;
+ return payload;
+}
+
+static int find_dl_candidates(alpm_db_t *repo, alpm_list_t **files, alpm_list_t **deltas)
+{
+ alpm_list_t *i;
+ alpm_handle_t *handle = repo->handle;
+
+ for(i = handle->trans->add; i; i = i->next) {
+ alpm_pkg_t *spkg = i->data;
+
+ if(spkg->origin != PKG_FROM_FILE && repo == spkg->origin_data.db) {
+ alpm_list_t *delta_path = spkg->delta_path;
+
+ if(!repo->servers) {
+ handle->pm_errno = ALPM_ERR_SERVER_NONE;
+ _alpm_log(handle, ALPM_LOG_ERROR, "%s: %s\n",
+ alpm_strerror(handle->pm_errno), repo->treename);
+ return 1;
+ }
+
+ if(delta_path) {
+ /* using deltas */
+ alpm_list_t *dlts;
+ for(dlts = delta_path; dlts; dlts = dlts->next) {
+ alpm_delta_t *delta = dlts->data;
+ if(delta->download_size != 0) {
+ struct dload_payload *payload = build_payload(
+ handle, delta->delta, delta->download_size, repo->servers);
+ ASSERT(payload, return -1);
+ *files = alpm_list_add(*files, payload);
+ }
+ /* keep a list of all the delta files for md5sums */
+ *deltas = alpm_list_add(*deltas, delta);
+ }
+
+ } else if(spkg->download_size != 0) {
+ struct dload_payload *payload;
+ ASSERT(spkg->filename != NULL, RET_ERR(handle, ALPM_ERR_PKG_INVALID_NAME, -1));
+ payload = build_payload(handle, spkg->filename, spkg->size, repo->servers);
+ ASSERT(payload, return -1);
+ *files = alpm_list_add(*files, payload);
+ }
+ }
+ }
+
+ return 0;
+}
+
+static int download_single_file(alpm_handle_t *handle, struct dload_payload *payload,
+ const char *cachedir)
+{
+ const alpm_list_t *server;
+
+ for(server = payload->servers; server; server = server->next) {
+ const char *server_url = server->data;
+ size_t len;
+
+ /* print server + filename into a buffer */
+ len = strlen(server_url) + strlen(payload->remote_name) + 2;
+ MALLOC(payload->fileurl, len, RET_ERR(handle, ALPM_ERR_MEMORY, -1));
+ snprintf(payload->fileurl, len, "%s/%s", server_url, payload->remote_name);
+ payload->handle = handle;
+ payload->allow_resume = 1;
+
+ if(_alpm_download(payload, cachedir, NULL) != -1) {
+ return 0;
+ }
+ }
+
+ return -1;
+}
+
static int download_files(alpm_handle_t *handle, alpm_list_t **deltas)
{
const char *cachedir;
- alpm_list_t *i, *j;
- alpm_list_t *files = NULL;
+ alpm_list_t *i, *files = NULL;
int errors = 0;
cachedir = _alpm_filecache_setup(handle);
@@ -826,91 +907,53 @@ static int download_files(alpm_handle_t *handle, alpm_list_t **deltas)
handle->totaldlcb(total_size);
}
- /* group sync records by repository and download */
for(i = handle->dbs_sync; i; i = i->next) {
- alpm_db_t *current = i->data;
-
- for(j = handle->trans->add; j; j = j->next) {
- alpm_pkg_t *spkg = j->data;
-
- if(spkg->origin != PKG_FROM_FILE && current == spkg->origin_data.db) {
- alpm_list_t *delta_path = spkg->delta_path;
- if(delta_path) {
- /* using deltas */
- alpm_list_t *dlts;
- for(dlts = delta_path; dlts; dlts = dlts->next) {
- alpm_delta_t *delta = dlts->data;
- if(delta->download_size != 0) {
- struct dload_payload *dpayload;
-
- CALLOC(dpayload, 1, sizeof(*dpayload), RET_ERR(handle, ALPM_ERR_MEMORY, -1));
- STRDUP(dpayload->remote_name, delta->delta, RET_ERR(handle, ALPM_ERR_MEMORY, -1));
- dpayload->max_size = delta->download_size;
-
- files = alpm_list_add(files, dpayload);
- }
- /* keep a list of all the delta files for md5sums */
- *deltas = alpm_list_add(*deltas, delta);
- }
+ errors += find_dl_candidates(i->data, &files, deltas);
+ }
- } else if(spkg->download_size != 0) {
- struct dload_payload *payload;
+ if(files) {
+ /* check for necessary disk space for download */
+ if(handle->checkspace) {
+ off_t *file_sizes;
+ size_t idx, num_files;
+ int ret;
- ASSERT(spkg->filename != NULL, RET_ERR(handle, ALPM_ERR_PKG_INVALID_NAME, -1));
- CALLOC(payload, 1, sizeof(*payload), RET_ERR(handle, ALPM_ERR_MEMORY, -1));
- STRDUP(payload->remote_name, spkg->filename, RET_ERR(handle, ALPM_ERR_MEMORY, -1));
- payload->max_size = spkg->size;
+ _alpm_log(handle, ALPM_LOG_DEBUG, "checking available disk space for download\n");
- files = alpm_list_add(files, payload);
- }
+ num_files = alpm_list_count(files);
+ CALLOC(file_sizes, num_files, sizeof(off_t), goto finish);
+ for(i = files, idx = 0; i; i = i->next, idx++) {
+ const struct dload_payload *payload = i->data;
+ file_sizes[idx] = payload->max_size;
}
- }
- if(files) {
- if(!current->servers) {
- handle->pm_errno = ALPM_ERR_SERVER_NONE;
- _alpm_log(handle, ALPM_LOG_ERROR, "%s: %s\n",
- alpm_strerror(handle->pm_errno), current->treename);
+ ret = _alpm_check_downloadspace(handle, cachedir, num_files, file_sizes);
+ free(file_sizes);
+
+ if(ret != 0) {
errors++;
- continue;
+ goto finish;
}
+ }
- EVENT(handle, ALPM_EVENT_RETRIEVE_START, current->treename, NULL);
- for(j = files; j; j = j->next) {
- struct dload_payload *payload = j->data;
- alpm_list_t *server;
- int ret = -1;
- for(server = current->servers; server; server = server->next) {
- const char *server_url = server->data;
- size_t len;
-
- /* print server + filename into a buffer */
- len = strlen(server_url) + strlen(payload->remote_name) + 2;
- MALLOC(payload->fileurl, len, RET_ERR(handle, ALPM_ERR_MEMORY, -1));
- snprintf(payload->fileurl, len, "%s/%s", server_url, payload->remote_name);
- payload->handle = handle;
- payload->allow_resume = 1;
-
- ret = _alpm_download(payload, cachedir, NULL);
- if(ret != -1) {
- break;
- }
- }
- if(ret == -1) {
- errors++;
- _alpm_log(handle, ALPM_LOG_WARNING, _("failed to retrieve some files from %s\n"),
- current->treename);
- }
+ EVENT(handle, ALPM_EVENT_RETRIEVE_START, NULL, NULL);
+ for(i = files; i; i = i->next) {
+ if(download_single_file(handle, i->data, cachedir) == -1) {
+ errors++;
+ _alpm_log(handle, ALPM_LOG_WARNING, _("failed to retrieve some files\n"));
}
-
- alpm_list_free_inner(files, (alpm_list_fn_free)_alpm_dload_payload_reset);
- FREELIST(files);
}
}
- for(j = handle->trans->add; j; j = j->next) {
- alpm_pkg_t *pkg = j->data;
+finish:
+ if(files) {
+ alpm_list_free_inner(files, (alpm_list_fn_free)_alpm_dload_payload_reset);
+ FREELIST(files);
+ }
+
+ for(i = handle->trans->add; i; i = i->next) {
+ alpm_pkg_t *pkg = i->data;
pkg->infolevel &= ~INFRQ_DSIZE;
pkg->download_size = 0;
}
@@ -931,7 +974,7 @@ static int check_validity(alpm_handle_t *handle,
char *path;
alpm_siglist_t *siglist;
alpm_siglevel_t level;
- enum _alpm_errno_t error;
+ alpm_errno_t error;
};
size_t current = 0, current_bytes = 0;
alpm_list_t *i, *errors = NULL;
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index c89f3c9c..d85a5036 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -24,22 +24,17 @@
#include "config.h"
-#include <stdio.h>
#include <stdlib.h>
-#include <stdarg.h>
-#include <string.h>
#include <unistd.h>
#include <ctype.h>
#include <dirent.h>
-#include <fcntl.h>
#include <time.h>
#include <syslog.h>
#include <errno.h>
#include <limits.h>
-#include <sys/types.h>
-#include <sys/stat.h>
#include <sys/wait.h>
#include <locale.h> /* setlocale */
+#include <fnmatch.h>
/* libarchive */
#include <archive.h>
@@ -62,8 +57,16 @@
#include "trans.h"
#ifndef HAVE_STRSEP
-/* This is a replacement for strsep which is not portable (missing on Solaris).
- * Copyright (c) 2001 by François Gouget <fgouget_at_codeweavers.com> */
+/** Extracts tokens from a string.
+ * Replaces strset which is not portable (missing on Solaris).
+ * Copyright (c) 2001 by François Gouget <fgouget_at_codeweavers.com>
+ * Modifies str to point to the first character after the token if one is
+ * found, or NULL if one is not.
+ * @param str string containing delimited tokens to parse
+ * @param delim character delimiting tokens in str
+ * @return pointer to the first token in str if str is not NULL, NULL if
+ * str is NULL
+ */
char* strsep(char** str, const char* delims)
{
char* token;
@@ -93,7 +96,11 @@ int _alpm_makepath(const char *path)
return _alpm_makepath_mode(path, 0755);
}
-/* does the same thing as 'mkdir -p' */
+/** Creates a directory, including parents if needed, similar to 'mkdir -p'.
+ * @param path directory path to create
+ * @param mode permission mode for created directories
+ * @return 0 on success, 1 on error
+ */
int _alpm_makepath_mode(const char *path, mode_t mode)
{
/* A bit of pointer hell here. Descriptions:
@@ -129,55 +136,65 @@ int _alpm_makepath_mode(const char *path, mode_t mode)
return ret;
}
+/** Copies a file.
+ * @param src file path to copy from
+ * @param dest file path to copy to
+ * @return 0 on success, 1 on error
+ */
int _alpm_copyfile(const char *src, const char *dest)
{
- FILE *in, *out;
- size_t len;
char *buf;
- int ret = 0;
+ int in, out, ret = 1;
+ ssize_t nread;
+ struct stat st;
- in = fopen(src, "rb");
- if(in == NULL) {
- return 1;
- }
- out = fopen(dest, "wb");
- if(out == NULL) {
- fclose(in);
- return 1;
- }
+ MALLOC(buf, (size_t)ALPM_BUFFER_SIZE, return 1);
- MALLOC(buf, (size_t)ALPM_BUFFER_SIZE, ret = 1; goto cleanup);
+ OPEN(in, src, O_RDONLY);
+ do {
+ out = open(dest, O_WRONLY | O_CREAT, 0000);
+ } while(out == -1 && errno == EINTR);
+ if(in < 0 || out < 0) {
+ goto cleanup;
+ }
- /* do the actual file copy */
- while((len = fread(buf, 1, ALPM_BUFFER_SIZE, in))) {
- size_t nwritten = 0;
- nwritten = fwrite(buf, 1, len, out);
- if((nwritten != len) || ferror(out)) {
- ret = -1;
- goto cleanup;
- }
+ if(fstat(in, &st) || fchmod(out, st.st_mode)) {
+ goto cleanup;
}
- /* chmod dest to permissions of src, as long as it is not a symlink */
- struct stat statbuf;
- if(!stat(src, &statbuf)) {
- if(! S_ISLNK(statbuf.st_mode)) {
- fchmod(fileno(out), statbuf.st_mode);
+ /* do the actual file copy */
+ while((nread = read(in, buf, ALPM_BUFFER_SIZE)) > 0 || errno == EINTR) {
+ ssize_t nwrite = 0;
+ if(nread < 0) {
+ continue;
}
- } else {
- /* stat was unsuccessful */
- ret = 1;
+ do {
+ nwrite = write(out, buf + nwrite, nread);
+ if(nwrite >= 0) {
+ nread -= nwrite;
+ } else if(errno != EINTR) {
+ goto cleanup;
+ }
+ } while(nread > 0);
}
+ ret = 0;
cleanup:
- fclose(in);
- fclose(out);
free(buf);
+ if(in >= 0) {
+ CLOSE(in);
+ }
+ if(out >= 0) {
+ CLOSE(out);
+ }
return ret;
}
-/* Trim whitespace and newlines from a string
-*/
+/** Trim leading and trailing whitespace, including newlines, from a string.
+ * Modifies str in place.
+ * @param str a string to trim
+ * @return str
+ */
char *_alpm_strtrim(char *str)
{
char *pch = str;
@@ -193,6 +210,7 @@ char *_alpm_strtrim(char *str)
if(pch != str) {
size_t len = strlen(pch);
if(len) {
+ /* move the remaining string to the beginning of str */
memmove(str, pch, len + 1);
} else {
*str = '\0';
@@ -213,8 +231,7 @@ char *_alpm_strtrim(char *str)
return str;
}
-/**
- * Trim trailing newline from a string (if one exists).
+/** Trim trailing newlines from a string (if any exist).
* @param str a single line of text
* @return the length of the trimmed string
*/
@@ -235,9 +252,64 @@ size_t _alpm_strip_newline(char *str)
/* Compression functions */
-/**
- * @brief Unpack a specific file in an archive.
- *
+/** Open an archive for reading and perform the necessary boilerplate.
+ * This takes care of creating the libarchive 'archive' struct, setting up
+ * compression and format options, opening a file descriptor, setting up the
+ * buffer size, and performing a stat on the path once opened.
+ * @param handle the context handle
+ * @param path the path of the archive to open
+ * @param buf space for a stat buffer for the given path
+ * @param archive pointer to place the created archive object
+ * @param error error code to set on failure to open archive
+ * @return -1 on failure, >=0 file descriptor on success
+ */
+int _alpm_open_archive(alpm_handle_t *handle, const char *path,
+ struct stat *buf, struct archive **archive, alpm_errno_t error)
+{
+ int fd;
+ size_t bufsize = ALPM_BUFFER_SIZE;
+
+ if((*archive = archive_read_new()) == NULL) {
+ RET_ERR(handle, ALPM_ERR_LIBARCHIVE, -1);
+ }
+
+ archive_read_support_compression_all(*archive);
+ archive_read_support_format_all(*archive);
+
+ _alpm_log(handle, ALPM_LOG_DEBUG, "opening archive %s\n", path);
+ OPEN(fd, path, O_RDONLY);
+ if(fd < 0) {
+ _alpm_log(handle, ALPM_LOG_ERROR,
+ _("could not open file %s: %s\n"), path, strerror(errno));
+ archive_read_finish(*archive);
+ RET_ERR(handle, error, -1);
+ }
+
+ if(fstat(fd, buf) != 0) {
+ _alpm_log(handle, ALPM_LOG_ERROR,
+ _("could not stat file %s: %s\n"), path, strerror(errno));
+ archive_read_finish(*archive);
+ CLOSE(fd);
+ RET_ERR(handle, error, -1);
+ }
+#ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
+ if(buf->st_blksize > ALPM_BUFFER_SIZE) {
+ bufsize = buf->st_blksize;
+ }
+#endif
+
+ if(archive_read_open_fd(*archive, fd, bufsize) != ARCHIVE_OK) {
+ _alpm_log(handle, ALPM_LOG_ERROR, _("could not open file %s: %s\n"),
+ path, archive_error_string(*archive));
+ archive_read_finish(*archive);
+ CLOSE(fd);
+ RET_ERR(handle, error, -1);
+ }
+
+ return fd;
+}
+
+/** Unpack a specific file in an archive.
* @param handle the context handle
* @param archive the archive to unpack
* @param prefix where to extract the files
@@ -258,46 +330,33 @@ int _alpm_unpack_single(alpm_handle_t *handle, const char *archive,
return ret;
}
-/**
- * @brief Unpack a list of files in an archive.
- *
+/** Unpack a list of files in an archive.
* @param handle the context handle
- * @param archive the archive to unpack
+ * @param path the archive to unpack
* @param prefix where to extract the files
* @param list a list of files within the archive to unpack or NULL for all
* @param breakfirst break after the first entry found
- *
* @return 0 on success, 1 on failure
*/
-int _alpm_unpack(alpm_handle_t *handle, const char *archive, const char *prefix,
+int _alpm_unpack(alpm_handle_t *handle, const char *path, const char *prefix,
alpm_list_t *list, int breakfirst)
{
int ret = 0;
mode_t oldmask;
- struct archive *_archive;
+ struct archive *archive;
struct archive_entry *entry;
- int cwdfd;
-
- if((_archive = archive_read_new()) == NULL) {
- RET_ERR(handle, ALPM_ERR_LIBARCHIVE, 1);
- }
-
- archive_read_support_compression_all(_archive);
- archive_read_support_format_all(_archive);
+ struct stat buf;
+ int fd, cwdfd;
- if(archive_read_open_filename(_archive, archive,
- ALPM_BUFFER_SIZE) != ARCHIVE_OK) {
- _alpm_log(handle, ALPM_LOG_ERROR, _("could not open file %s: %s\n"), archive,
- archive_error_string(_archive));
- RET_ERR(handle, ALPM_ERR_PKG_OPEN, 1);
+ fd = _alpm_open_archive(handle, path, &buf, &archive, ALPM_ERR_PKG_OPEN);
+ if(fd < 0) {
+ return 1;
}
oldmask = umask(0022);
/* save the cwd so we can restore it later */
- do {
- cwdfd = open(".", O_RDONLY);
- } while(cwdfd == -1 && errno == EINTR);
+ OPEN(cwdfd, ".", O_RDONLY);
if(cwdfd < 0) {
_alpm_log(handle, ALPM_LOG_ERROR, _("could not get current working directory\n"));
}
@@ -310,19 +369,12 @@ int _alpm_unpack(alpm_handle_t *handle, const char *archive, const char *prefix,
goto cleanup;
}
- while(archive_read_next_header(_archive, &entry) == ARCHIVE_OK) {
- const struct stat *st;
- const char *entryname; /* the name of the file in the archive */
+ while(archive_read_next_header(archive, &entry) == ARCHIVE_OK) {
+ const char *entryname;
+ mode_t mode;
- st = archive_entry_stat(entry);
entryname = archive_entry_pathname(entry);
- if(S_ISREG(st->st_mode)) {
- archive_entry_set_perm(entry, 0644);
- } else if(S_ISDIR(st->st_mode)) {
- archive_entry_set_perm(entry, 0755);
- }
-
/* If specific files were requested, skip entries that don't match. */
if(list) {
char *entry_prefix = strdup(entryname);
@@ -333,7 +385,7 @@ int _alpm_unpack(alpm_handle_t *handle, const char *archive, const char *prefix,
char *found = alpm_list_find_str(list, entry_prefix);
free(entry_prefix);
if(!found) {
- if(archive_read_data_skip(_archive) != ARCHIVE_OK) {
+ if(archive_read_data_skip(archive) != ARCHIVE_OK) {
ret = 1;
goto cleanup;
}
@@ -343,15 +395,22 @@ int _alpm_unpack(alpm_handle_t *handle, const char *archive, const char *prefix,
}
}
+ mode = archive_entry_mode(entry);
+ if(S_ISREG(mode)) {
+ archive_entry_set_perm(entry, 0644);
+ } else if(S_ISDIR(mode)) {
+ archive_entry_set_perm(entry, 0755);
+ }
+
/* Extract the archive entry. */
- int readret = archive_read_extract(_archive, entry, 0);
+ int readret = archive_read_extract(archive, entry, 0);
if(readret == ARCHIVE_WARN) {
/* operation succeeded but a non-critical error was encountered */
_alpm_log(handle, ALPM_LOG_WARNING, _("warning given when extracting %s (%s)\n"),
- entryname, archive_error_string(_archive));
+ entryname, archive_error_string(archive));
} else if(readret != ARCHIVE_OK) {
_alpm_log(handle, ALPM_LOG_ERROR, _("could not extract %s (%s)\n"),
- entryname, archive_error_string(_archive));
+ entryname, archive_error_string(archive));
ret = 1;
goto cleanup;
}
@@ -363,19 +422,23 @@ int _alpm_unpack(alpm_handle_t *handle, const char *archive, const char *prefix,
cleanup:
umask(oldmask);
- archive_read_finish(_archive);
+ archive_read_finish(archive);
+ CLOSE(fd);
if(cwdfd >= 0) {
if(fchdir(cwdfd) != 0) {
_alpm_log(handle, ALPM_LOG_ERROR,
_("could not restore working directory (%s)\n"), strerror(errno));
}
- close(cwdfd);
+ CLOSE(cwdfd);
}
return ret;
}
-/* does the same thing as 'rm -rf' */
+/** Recursively removes a path similar to 'rm -rf'.
+ * @param path path to remove
+ * @return 0 on success, number of paths that could not be removed on error
+ */
int _alpm_rmrf(const char *path)
{
int errflag = 0;
@@ -418,8 +481,7 @@ int _alpm_rmrf(const char *path)
return 0;
}
-/**
- * Determine if there are files in a directory
+/** Determine if there are files in a directory.
* @param handle the context handle
* @param path the full absolute directory path
* @param full_count whether to return an exact count of files
@@ -460,6 +522,13 @@ ssize_t _alpm_files_in_directory(alpm_handle_t *handle, const char *path,
return files;
}
+/** Write formatted message to log.
+ * @param handle the context handle
+ * @param format formatted string to write out
+ * @param args formatting arguments
+ * @return 0 or number of characters written on success, vfprintf return value
+ * on error
+ */
int _alpm_logaction(alpm_handle_t *handle, const char *fmt, va_list args)
{
int ret = 0;
@@ -491,16 +560,20 @@ int _alpm_logaction(alpm_handle_t *handle, const char *fmt, va_list args)
return ret;
}
-int _alpm_run_chroot(alpm_handle_t *handle, const char *path, char *const argv[])
+/** Execute a command with arguments in a chroot.
+ * @param handle the context handle
+ * @param cmd command to execute
+ * @param argv arguments to pass to cmd
+ * @return 0 on success, 1 on error
+ */
+int _alpm_run_chroot(alpm_handle_t *handle, const char *cmd, char *const argv[])
{
pid_t pid;
int pipefd[2], cwdfd;
int retval = 0;
/* save the cwd so we can restore it later */
- do {
- cwdfd = open(".", O_RDONLY);
- } while(cwdfd == -1 && errno == EINTR);
+ OPEN(cwdfd, ".", O_RDONLY);
if(cwdfd < 0) {
_alpm_log(handle, ALPM_LOG_ERROR, _("could not get current working directory\n"));
}
@@ -513,7 +586,7 @@ int _alpm_run_chroot(alpm_handle_t *handle, const char *path, char *const argv[]
}
_alpm_log(handle, ALPM_LOG_DEBUG, "executing \"%s\" under chroot \"%s\"\n",
- path, handle->root);
+ cmd, handle->root);
/* Flush open fds before fork() to avoid cloning buffers */
fflush(NULL);
@@ -534,12 +607,12 @@ int _alpm_run_chroot(alpm_handle_t *handle, const char *path, char *const argv[]
if(pid == 0) {
/* this code runs for the child only (the actual chroot/exec) */
- close(1);
- close(2);
+ CLOSE(1);
+ CLOSE(2);
while(dup2(pipefd[1], 1) == -1 && errno == EINTR);
while(dup2(pipefd[1], 2) == -1 && errno == EINTR);
- close(pipefd[0]);
- close(pipefd[1]);
+ CLOSE(pipefd[0]);
+ CLOSE(pipefd[1]);
/* use fprintf instead of _alpm_log to send output through the parent */
if(chroot(handle->root) != 0) {
@@ -552,7 +625,8 @@ int _alpm_run_chroot(alpm_handle_t *handle, const char *path, char *const argv[]
exit(1);
}
umask(0022);
- execv(path, argv);
+ execv(cmd, argv);
+ /* execv only returns if there was an error */
fprintf(stderr, _("call to execv failed (%s)\n"), strerror(errno));
exit(1);
} else {
@@ -560,10 +634,10 @@ int _alpm_run_chroot(alpm_handle_t *handle, const char *path, char *const argv[]
int status;
FILE *pipe_file;
- close(pipefd[1]);
+ CLOSE(pipefd[1]);
pipe_file = fdopen(pipefd[0], "r");
if(pipe_file == NULL) {
- close(pipefd[0]);
+ CLOSE(pipefd[0]);
retval = 1;
} else {
while(!feof(pipe_file)) {
@@ -605,12 +679,16 @@ cleanup:
_alpm_log(handle, ALPM_LOG_ERROR,
_("could not restore working directory (%s)\n"), strerror(errno));
}
- close(cwdfd);
+ CLOSE(cwdfd);
}
return retval;
}
+/** Run ldconfig in a chroot.
+ * @param handle the context handle
+ * @return 0 on success, 1 on error
+ */
int _alpm_ldconfig(alpm_handle_t *handle)
{
char line[PATH_MAX];
@@ -629,8 +707,13 @@ int _alpm_ldconfig(alpm_handle_t *handle)
return 0;
}
-/* Helper function for comparing strings using the
- * alpm "compare func" signature */
+/** Helper function for comparing strings using the alpm "compare func"
+ * signature.
+ * @param s1 first string to be compared
+ * @param s2 second string to be compared
+ * @return 0 if strings are equal, positive int if first unequal character
+ * has a greater value in s1, negative if it has a greater value in s2
+ */
int _alpm_str_cmp(const void *s1, const void *s2)
{
return strcmp(s1, s2);
@@ -739,51 +822,64 @@ int _alpm_lstat(const char *path, struct stat *buf)
}
#ifdef HAVE_LIBSSL
+/** Compute the MD5 message digest of a file.
+ * @param path file path of file to compute MD5 digest of
+ * @param output string to hold computed MD5 digest
+ * @return 0 on success, 1 on file open error, 2 on file read error
+ */
static int md5_file(const char *path, unsigned char output[16])
{
- FILE *f;
- size_t n;
MD5_CTX ctx;
unsigned char *buf;
+ ssize_t n;
+ int fd;
- CALLOC(buf, ALPM_BUFFER_SIZE, sizeof(unsigned char), return 1);
+ MALLOC(buf, (size_t)ALPM_BUFFER_SIZE, return 1);
- if((f = fopen(path, "rb")) == NULL) {
+ OPEN(fd, path, O_RDONLY);
+ if(fd < 0) {
free(buf);
return 1;
}
MD5_Init(&ctx);
- while((n = fread(buf, 1, ALPM_BUFFER_SIZE, f)) > 0) {
+ while((n = read(fd, buf, ALPM_BUFFER_SIZE)) > 0 || errno == EINTR) {
+ if(n < 0) {
+ continue;
+ }
MD5_Update(&ctx, buf, n);
}
- MD5_Final(output, &ctx);
-
- memset(&ctx, 0, sizeof(MD5_CTX));
+ CLOSE(fd);
free(buf);
- if(ferror(f) != 0) {
- fclose(f);
+ if(n < 0) {
return 2;
}
- fclose(f);
+ MD5_Final(output, &ctx);
return 0;
}
/* third param is so we match the PolarSSL definition */
+/** Compute the SHA-224 or SHA-256 message digest of a file.
+ * @param path file path of file to compute SHA2 digest of
+ * @param output string to hold computed SHA2 digest
+ * @param is224 use SHA-224 instead of SHA-256
+ * @return 0 on success, 1 on file open error, 2 on file read error
+ */
static int sha2_file(const char *path, unsigned char output[32], int is224)
{
- FILE *f;
- size_t n;
SHA256_CTX ctx;
unsigned char *buf;
+ ssize_t n;
+ int fd;
- CALLOC(buf, ALPM_BUFFER_SIZE, sizeof(unsigned char), return 1);
+ MALLOC(buf, (size_t)ALPM_BUFFER_SIZE, return 1);
- if((f = fopen(path, "rb")) == NULL) {
+ OPEN(fd, path, O_RDONLY);
+ if(fd < 0) {
free(buf);
return 1;
}
@@ -794,7 +890,10 @@ static int sha2_file(const char *path, unsigned char output[32], int is224)
SHA256_Init(&ctx);
}
- while((n = fread(buf, 1, ALPM_BUFFER_SIZE, f)) > 0) {
+ while((n = read(fd, buf, ALPM_BUFFER_SIZE)) > 0 || errno == EINTR) {
+ if(n < 0) {
+ continue;
+ }
if(is224) {
SHA224_Update(&ctx, buf, n);
} else {
@@ -802,25 +901,24 @@ static int sha2_file(const char *path, unsigned char output[32], int is224)
}
}
- if(is224) {
- SHA224_Final(output, &ctx);
- } else {
- SHA256_Final(output, &ctx);
- }
-
- memset(&ctx, 0, sizeof(SHA256_CTX));
+ CLOSE(fd);
free(buf);
- if(ferror(f) != 0) {
- fclose(f);
+ if(n < 0) {
return 2;
}
- fclose(f);
+ if(is224) {
+ SHA224_Final(output, &ctx);
+ } else {
+ SHA256_Final(output, &ctx);
+ }
return 0;
}
#endif
+static const char *hex_digits = "0123456789abcdef";
+
/** Get the md5 sum of file.
* @param filename name of the file
* @return the checksum on success, NULL on error
@@ -834,8 +932,7 @@ char SYMEXPORT *alpm_compute_md5sum(const char *filename)
ASSERT(filename != NULL, return NULL);
- /* allocate 32 chars plus 1 for null */
- CALLOC(md5sum, 33, sizeof(char), return NULL);
+ MALLOC(md5sum, (size_t)33, return NULL);
/* defined above for OpenSSL, otherwise defined in md5.h */
ret = md5_file(filename, output);
@@ -846,10 +943,12 @@ char SYMEXPORT *alpm_compute_md5sum(const char *filename)
/* Convert the result to something readable */
for (i = 0; i < 16; i++) {
- /* sprintf is acceptable here because we know our output */
- sprintf(md5sum +(i * 2), "%02x", output[i]);
+ int pos = i * 2;
+ /* high 4 bits are first digit, low 4 are second */
+ md5sum[pos] = hex_digits[output[i] >> 4];
+ md5sum[pos + 1] = hex_digits[output[i] & 0x0f];
}
-
+ md5sum[32] = '\0';
return md5sum;
}
@@ -866,8 +965,7 @@ char SYMEXPORT *alpm_compute_sha256sum(const char *filename)
ASSERT(filename != NULL, return NULL);
- /* allocate 64 chars plus 1 for null */
- CALLOC(sha256sum, 65, sizeof(char), return NULL);
+ MALLOC(sha256sum, (size_t)65, return NULL);
/* defined above for OpenSSL, otherwise defined in sha2.h */
ret = sha2_file(filename, output, 0);
@@ -878,13 +976,22 @@ char SYMEXPORT *alpm_compute_sha256sum(const char *filename)
/* Convert the result to something readable */
for (i = 0; i < 32; i++) {
- /* sprintf is acceptable here because we know our output */
- sprintf(sha256sum +(i * 2), "%02x", output[i]);
+ int pos = i * 2;
+ /* high 4 bits are first digit, low 4 are second */
+ sha256sum[pos] = hex_digits[output[i] >> 4];
+ sha256sum[pos + 1] = hex_digits[output[i] & 0x0f];
}
-
+ sha256sum[64] = '\0';
return sha256sum;
}
+/** Calculates a file's MD5 or SHA2 digest and compares it to an expected value.
+ * @param filepath path of the file to check
+ * @param expected hash value to compare against
+ * @param type digest type to use
+ * @return 0 if file matches the expected hash, 1 if they do not match, -1 on
+ * error
+ */
int _alpm_test_checksum(const char *filepath, const char *expected,
enum _alpm_csum type)
{
@@ -912,18 +1019,24 @@ int _alpm_test_checksum(const char *filepath, const char *expected,
}
/* Note: does NOT handle sparse files on purpose for speed. */
+/** TODO.
+ * Does not handle sparse files on purpose for speed.
+ * @param a
+ * @param b
+ * @return
+ */
int _alpm_archive_fgets(struct archive *a, struct archive_read_buffer *b)
{
- char *i = NULL;
- int64_t offset;
- int done = 0;
-
/* ensure we start populating our line buffer at the beginning */
b->line_offset = b->line;
while(1) {
+ size_t block_remaining;
+ char *eol;
+
/* have we processed this entire block? */
if(b->block + b->block_size == b->block_offset) {
+ int64_t offset;
if(b->ret == ARCHIVE_EOF) {
/* reached end of archive on the last read, now we are out of data */
goto cleanup;
@@ -933,20 +1046,20 @@ int _alpm_archive_fgets(struct archive *a, struct archive_read_buffer *b)
b->ret = archive_read_data_block(a, (void *)&b->block,
&b->block_size, &offset);
b->block_offset = b->block;
+ block_remaining = b->block_size;
/* error, cleanup */
if(b->ret < ARCHIVE_OK) {
goto cleanup;
}
+ } else {
+ block_remaining = b->block + b->block_size - b->block_offset;
}
- /* loop through the block looking for EOL characters */
- for(i = b->block_offset; i < (b->block + b->block_size); i++) {
- /* check if read value was null or newline */
- if(*i == '\0' || *i == '\n') {
- done = 1;
- break;
- }
+ /* look through the block looking for EOL characters */
+ eol = memchr(b->block_offset, '\n', block_remaining);
+ if(!eol) {
+ eol = memchr(b->block_offset, '\0', block_remaining);
}
/* allocate our buffer, or ensure our existing one is big enough */
@@ -956,8 +1069,10 @@ int _alpm_archive_fgets(struct archive *a, struct archive_read_buffer *b)
b->line_size = b->block_size + 1;
b->line_offset = b->line;
} else {
- size_t needed = (size_t)((b->line_offset - b->line)
- + (i - b->block_offset) + 1);
+ /* note: we know eol > b->block_offset and b->line_offset > b->line,
+ * so we know the result is unsigned and can fit in size_t */
+ size_t new = eol ? (size_t)(eol - b->block_offset) : block_remaining;
+ size_t needed = (size_t)((b->line_offset - b->line) + new + 1);
if(needed > b->max_line_size) {
b->ret = -ERANGE;
goto cleanup;
@@ -974,11 +1089,11 @@ int _alpm_archive_fgets(struct archive *a, struct archive_read_buffer *b)
}
}
- if(done) {
- size_t len = (size_t)(i - b->block_offset);
+ if(eol) {
+ size_t len = (size_t)(eol - b->block_offset);
memcpy(b->line_offset, b->block_offset, len);
b->line_offset[len] = '\0';
- b->block_offset = ++i;
+ b->block_offset = eol + 1;
/* this is the main return point; from here you can read b->line */
return ARCHIVE_OK;
} else {
@@ -986,7 +1101,7 @@ int _alpm_archive_fgets(struct archive *a, struct archive_read_buffer *b)
size_t len = (size_t)(b->block + b->block_size - b->block_offset);
memcpy(b->line_offset, b->block_offset, len);
b->line_offset += len;
- b->block_offset = i;
+ b->block_offset = b->block + b->block_size;
/* there was no new data, return what is left; saved ARCHIVE_EOF will be
* returned on next call */
if(len == 0) {
@@ -1005,6 +1120,14 @@ cleanup:
}
}
+/** Parse a full package specifier.
+ * @param target package specifier to parse, such as: "pacman-4.0.1-2",
+ * "pacman-4.01-2/", or "pacman-4.0.1-2/desc"
+ * @param name to hold package name
+ * @param version to hold package version
+ * @param name_hash to hold package name hash
+ * @return 0 on success, -1 on error
+ */
int _alpm_splitname(const char *target, char **name, char **version,
unsigned long *name_hash)
{
@@ -1057,8 +1180,7 @@ int _alpm_splitname(const char *target, char **name, char **version,
return 0;
}
-/**
- * Hash the given string to an unsigned long value.
+/** Hash the given string to an unsigned long value.
* This is the standard sdbm hashing algorithm.
* @param str string to hash
* @return the hash value of the given string
@@ -1078,6 +1200,11 @@ unsigned long _alpm_hash_sdbm(const char *str)
return hash;
}
+/** Convert a string to a file offset.
+ * This parses bare positive integers only.
+ * @param line string to convert
+ * @return off_t on success, -1 on error
+ */
off_t _alpm_strtoofft(const char *line)
{
char *end;
@@ -1103,8 +1230,16 @@ off_t _alpm_strtoofft(const char *line)
return (off_t)result;
}
-time_t _alpm_parsedate(const char *line)
+/** Parses a date into an alpm_time_t struct.
+ * @param line date to parse
+ * @return time struct on success, 0 on error
+ */
+alpm_time_t _alpm_parsedate(const char *line)
{
+ char *end;
+ long long result;
+ errno = 0;
+
if(isalpha((unsigned char)line[0])) {
/* initialize to null in case of failure */
struct tm tmp_tm;
@@ -1112,13 +1247,27 @@ time_t _alpm_parsedate(const char *line)
setlocale(LC_TIME, "C");
strptime(line, "%a %b %e %H:%M:%S %Y", &tmp_tm);
setlocale(LC_TIME, "");
- return mktime(&tmp_tm);
+ return (alpm_time_t)mktime(&tmp_tm);
+ }
+
+ result = strtoll(line, &end, 10);
+ if (result == 0 && end == line) {
+ /* line was not a number */
+ errno = EINVAL;
+ return 0;
+ } else if (errno == ERANGE) {
+ /* line does not fit in long long */
+ return 0;
+ } else if (*end) {
+ /* line began with a number but has junk left over at the end */
+ errno = EINVAL;
+ return 0;
}
- return (time_t)atol(line);
+
+ return (alpm_time_t)result;
}
-/**
- * Wrapper around access() which takes a dir and file argument
+/** Wrapper around access() which takes a dir and file argument
* separately and generates an appropriate error message.
* If dir is NULL file will be treated as the whole path.
* @param handle an alpm handle
@@ -1127,7 +1276,6 @@ time_t _alpm_parsedate(const char *line)
* @param amode access mode as described in access()
* @return int value returned by access()
*/
-
int _alpm_access(alpm_handle_t *handle, const char *dir, const char *file, int amode)
{
size_t len = 0;
@@ -1168,8 +1316,25 @@ int _alpm_access(alpm_handle_t *handle, const char *dir, const char *file, int a
return ret;
}
+/** Checks whether a string matches a shell wildcard pattern.
+ * Wrapper around fnmatch.
+ * @param pattern pattern to match aganist
+ * @param string string to check against pattern
+ * @return 0 if string matches pattern, non-zero if they don't match and on
+ * error
+ */
+int _alpm_fnmatch(const void *pattern, const void *string)
+{
+ return fnmatch(pattern, string, 0);
+}
+
#ifndef HAVE_STRNDUP
/* A quick and dirty implementation derived from glibc */
+/** Determines the length of a fixed-size string.
+ * @param s string to be measured
+ * @param max maximum number of characters to search for the string end
+ * @return length of s or max, whichever is smaller
+ */
static size_t strnlen(const char *s, size_t max)
{
register const char *p;
@@ -1177,6 +1342,12 @@ static size_t strnlen(const char *s, size_t max)
return (p - s);
}
+/** Copies a string.
+ * Returned string needs to be freed
+ * @param s string to be copied
+ * @param n maximum number of characters to copy
+ * @return pointer to the new string on success, NULL on error
+ */
char *strndup(const char *s, size_t n)
{
size_t len = strnlen(s, n);
diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h
index 26fa9044..1e192747 100644
--- a/lib/libalpm/util.h
+++ b/lib/libalpm/util.h
@@ -35,11 +35,13 @@
#include <string.h>
#include <stdarg.h>
#include <stddef.h> /* size_t */
-#include <time.h>
+#include <sys/types.h>
#include <sys/stat.h> /* struct stat */
-#include <archive.h> /* struct archive */
#include <math.h> /* fabs */
#include <float.h> /* DBL_EPSILON */
+#include <fcntl.h> /* open, close */
+
+#include <archive.h> /* struct archive */
#ifdef ENABLE_NLS
#include <libintl.h> /* here so it doesn't need to be included elsewhere */
@@ -51,8 +53,8 @@
#define ALLOC_FAIL(s) do { fprintf(stderr, "alloc failure: could not allocate %zd bytes\n", s); } while(0)
-#define MALLOC(p, s, action) do { p = calloc(1, s); if(p == NULL) { ALLOC_FAIL(s); action; } } while(0)
-#define CALLOC(p, l, s, action) do { p = calloc(l, s); if(p == NULL) { ALLOC_FAIL(s); action; } } while(0)
+#define MALLOC(p, s, action) do { p = malloc(s); if(p == NULL) { ALLOC_FAIL(s); action; } } while(0)
+#define CALLOC(p, l, s, action) do { p = calloc(l, s); if(p == NULL) { ALLOC_FAIL(l * s); action; } } while(0)
/* This strdup macro is NULL safe- copying NULL will yield NULL */
#define STRDUP(r, s, action) do { if(s != NULL) { r = strdup(s); if(r == NULL) { ALLOC_FAIL(strlen(s)); action; } } else { r = NULL; } } while(0)
#define STRNDUP(r, s, l, action) do { if(s != NULL) { r = strndup(s, l); if(r == NULL) { ALLOC_FAIL(strlen(s)); action; } } else { r = NULL; } } while(0)
@@ -82,6 +84,13 @@
#define ALPM_BUFFER_SIZE 8192
#endif
+#ifndef O_BINARY
+#define O_BINARY 0
+#endif
+
+#define OPEN(fd, path, flags) do { fd = open(path, flags | O_BINARY); } while(fd == -1 && errno == EINTR)
+#define CLOSE(fd) do { int ret; do { ret = close(fd); } while(ret == -1 && errno == EINTR); } while(0)
+
/**
* Used as a buffer/state holder for _alpm_archive_fgets().
*/
@@ -108,6 +117,9 @@ int _alpm_makepath_mode(const char *path, mode_t mode);
int _alpm_copyfile(const char *src, const char *dest);
char *_alpm_strtrim(char *str);
size_t _alpm_strip_newline(char *str);
+
+int _alpm_open_archive(alpm_handle_t *handle, const char *path,
+ struct stat *buf, struct archive **archive, alpm_errno_t error);
int _alpm_unpack_single(alpm_handle_t *handle, const char *archive,
const char *prefix, const char *filename);
int _alpm_unpack(alpm_handle_t *handle, const char *archive, const char *prefix,
@@ -115,7 +127,7 @@ int _alpm_unpack(alpm_handle_t *handle, const char *archive, const char *prefix,
int _alpm_rmrf(const char *path);
ssize_t _alpm_files_in_directory(alpm_handle_t *handle, const char *path, int full_count);
int _alpm_logaction(alpm_handle_t *handle, const char *fmt, va_list args);
-int _alpm_run_chroot(alpm_handle_t *handle, const char *path, char *const argv[]);
+int _alpm_run_chroot(alpm_handle_t *handle, const char *cmd, char *const argv[]);
int _alpm_ldconfig(alpm_handle_t *handle);
int _alpm_str_cmp(const void *s1, const void *s2);
char *_alpm_filecache_find(alpm_handle_t *handle, const char *filename);
@@ -127,10 +139,11 @@ int _alpm_splitname(const char *target, char **name, char **version,
unsigned long *name_hash);
unsigned long _alpm_hash_sdbm(const char *str);
off_t _alpm_strtoofft(const char *line);
-time_t _alpm_parsedate(const char *line);
+alpm_time_t _alpm_parsedate(const char *line);
int _alpm_raw_cmp(const char *first, const char *second);
int _alpm_raw_ncmp(const char *first, const char *second, size_t max);
int _alpm_access(alpm_handle_t *handle, const char *dir, const char *file, int amode);
+int _alpm_fnmatch(const void *pattern, const void *string);
#ifndef HAVE_STRSEP
char *strsep(char **, const char *);
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 7cf4844d..0fa05dcb 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -1964,6 +1964,7 @@ set -E
[[ -n ${PKGEXT} ]] && _PKGEXT=${PKGEXT}
[[ -n ${SRCEXT} ]] && _SRCEXT=${SRCEXT}
[[ -n ${GPGKEY} ]] && _GPGKEY=${GPGKEY}
+[[ -n ${PACKAGER} ]] && _PACKAGER=${PACKAGER}
# default config is makepkg.conf
MAKEPKG_CONF=${MAKEPKG_CONF:-$confdir/makepkg.conf}
@@ -2046,6 +2047,7 @@ SRCPKGDEST=${SRCPKGDEST:-$startdir} #default to $startdir if undefined
PKGEXT=${_PKGEXT:-$PKGEXT}
SRCEXT=${_SRCEXT:-$SRCEXT}
GPGKEY=${_GPGKEY:-$GPGKEY}
+PACKAGER=${_PACKAGER:-$PACKAGER}
if (( HOLDVER )) && [[ -n $FORCE_VER ]]; then
# The '\\0' is here to prevent gettext from thinking --holdver is an option
diff --git a/scripts/pacman-optimize.sh.in b/scripts/pacman-optimize.sh.in
index 5ff302e2..154f982e 100644
--- a/scripts/pacman-optimize.sh.in
+++ b/scripts/pacman-optimize.sh.in
@@ -113,7 +113,7 @@ fi
# do not let pacman run while we do this
touch "$lockfile"
-workdir=$(mktemp -d /tmp/pacman-optimize.XXXXXXXXXX) ||
+workdir=$(mktemp -d "${TMPDIR:-/tmp}/pacman-optimize.XXXXXXXXXX") ||
die_r "$(gettext "Can not create temp directory for database building.")\n" >&2
# step 1: sum the old db
diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in
index 5e1d7702..8fa3b723 100644
--- a/scripts/repo-add.sh.in
+++ b/scripts/repo-add.sh.in
@@ -195,7 +195,7 @@ create_signature() {
gpg --detach-sign --use-agent ${SIGNWITHKEY} "$dbfile" &>/dev/null || ret=$?
if (( ! ret )); then
- msg2 "$(gettext "Created signature file %s.")" "${dbfile##*/}.sig"
+ msg2 "$(gettext "Created signature file %s.")" "${dbfile##*/.tmp.}.sig"
else
warning "$(gettext "Failed to sign package database.")"
fi
@@ -411,13 +411,8 @@ elephant() {
check_repo_db() {
local repodir
- # ensure the path to the DB exists
- if [[ "$LOCKFILE" == /* ]]; then
- repodir=${LOCKFILE%/*}/
- else
- repodir=$PWD/$LOCKFILE
- repodir=${repodir%/*}/
- fi
+ # ensure the path to the DB exists; $LOCKFILE is always an absolute path
+ repodir=${LOCKFILE%/*}/
if [[ ! -d "$repodir" ]]; then
error "$(gettext "%s does not exist or is not a directory.")" "$repodir"
@@ -566,7 +561,7 @@ if [[ $cmd != "repo-add" && $cmd != "repo-remove" ]]; then
exit 1
fi
-tmpdir=$(mktemp -d /tmp/repo-tools.XXXXXXXXXX) || (\
+tmpdir=$(mktemp -d "${TMPDIR:-/tmp}/repo-tools.XXXXXXXXXX") || (\
error "$(gettext "Cannot create temp directory for database building.")"; \
exit 1)
mkdir $tmpdir/tree
@@ -624,7 +619,11 @@ if [[ -z $REPO_DB_FILE ]]; then
exit 1
fi
-LOCKFILE=$REPO_DB_FILE.lck
+if [[ $REPO_DB_FILE == /* ]]; then
+ LOCKFILE=$REPO_DB_FILE.lck
+else
+ LOCKFILE=$PWD/$REPO_DB_FILE.lck
+fi
verify_repo_extension "$REPO_DB_FILE" >/dev/null
check_repo_db
@@ -641,37 +640,51 @@ if (( success )); then
msg "$(gettext "Creating updated database file '%s'")" "$REPO_DB_FILE"
TAR_OPT=$(verify_repo_extension "$REPO_DB_FILE")
+ # $LOCKFILE is already guaranteed to be absolute so this is safe
+ dirname=${LOCKFILE%/*}
filename=${REPO_DB_FILE##*/}
+ # this ensures we create it on the same filesystem, making moves atomic
+ tempname="$dirname/.tmp.$filename"
pushd "$tmpdir/tree" >/dev/null
if ( shopt -s nullglob; files=(*); (( ${#files[*]} )) ); then
- bsdtar -c${TAR_OPT}f "$tmpdir/$filename" *
+ bsdtar -c${TAR_OPT}f "$tempname" *
else
# we have no packages remaining? zip up some emptyness
warning "$(gettext "No packages remain, creating empty database.")"
- bsdtar -c${TAR_OPT}f "$tmpdir/$filename" -T /dev/null
+ bsdtar -c${TAR_OPT}f "$tempname" -T /dev/null
fi
popd >/dev/null
- create_signature "$tmpdir/$filename"
+ create_signature "$tempname"
- [[ -f $REPO_DB_FILE ]] && mv -f "$REPO_DB_FILE" "${REPO_DB_FILE}.old"
+ # hardlink or move the previous version of the database and signature to .old
+ # extension as a backup measure
+ if [[ -f $REPO_DB_FILE ]]; then
+ ln -f "$REPO_DB_FILE" "$REPO_DB_FILE.old" 2>/dev/null || \
+ mv -f "$REPO_DB_FILE" "$REPO_DB_FILE.old"
+ fi
if [[ -f $REPO_DB_FILE.sig ]]; then
- mv -f "$REPO_DB_FILE.sig" "$REPO_DB_FILE.old.sig"
+ ln -f "$REPO_DB_FILE.sig" "$REPO_DB_FILE.old.sig" 2>/dev/null || \
+ mv -f "$REPO_DB_FILE.sig" "$REPO_DB_FILE.old.sig"
else
rm -f "$REPO_DB_FILE.old.sig"
fi
- [[ -f $tmpdir/$filename ]] && mv "$tmpdir/$filename" "$REPO_DB_FILE"
- [[ -f $tmpdir/$filename.sig ]] && mv "$tmpdir/$filename.sig" "$REPO_DB_FILE.sig"
+
+ # rotate the newly-created database and signature into place
+ mv "$tempname" "$REPO_DB_FILE"
+ if [[ -f $tempname.sig ]]; then
+ mv "$tempname.sig" "$REPO_DB_FILE.sig"
+ fi
+
dblink="${REPO_DB_FILE%.tar*}"
- target=${REPO_DB_FILE##*/}
rm -f "$dblink" "$dblink.sig"
- ln -s "$target" "$dblink" 2>/dev/null || \
- ln "$target" "$dblink" 2>/dev/null || \
+ ln -s "$filename" "$dblink" 2>/dev/null || \
+ ln "$filename" "$dblink" 2>/dev/null || \
cp "$REPO_DB_FILE" "$dblink"
if [[ -f "$REPO_DB_FILE.sig" ]]; then
- ln -s "$target.sig" "$dblink.sig" 2>/dev/null || \
- ln "$target.sig" "$dblink.sig" 2>/dev/null || \
+ ln -s "$filename.sig" "$dblink.sig" 2>/dev/null || \
+ ln "$filename.sig" "$dblink.sig" 2>/dev/null || \
cp "$REPO_DB_FILE.sig" "$dblink.sig"
fi
else
diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index c7c16949..2d989ba9 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -25,6 +25,7 @@
#include <string.h>
#include <sys/time.h>
#include <sys/types.h> /* off_t */
+#include <time.h>
#include <unistd.h>
#include <wchar.h>
#include <limits.h> /* UINT_MAX */
@@ -95,41 +96,41 @@ static void fill_progress(const int bar_percent, const int disp_percent,
}
if(hashlen > 0) {
- printf(" [");
+ fputs(" [", stdout);
for(i = hashlen; i > 0; --i) {
/* if special progress bar enabled */
if(config->chomp) {
if(i > hashlen - hash) {
- printf("-");
+ putchar('-');
} else if(i == hashlen - hash) {
if(lasthash == hash) {
if(mouth) {
- printf("\033[1;33mC\033[m");
+ fputs("\033[1;33mC\033[m", stdout);
} else {
- printf("\033[1;33mc\033[m");
+ fputs("\033[1;33mc\033[m", stdout);
}
} else {
lasthash = hash;
mouth = mouth == 1 ? 0 : 1;
if(mouth) {
- printf("\033[1;33mC\033[m");
+ fputs("\033[1;33mC\033[m", stdout);
} else {
- printf("\033[1;33mc\033[m");
+ fputs("\033[1;33mc\033[m", stdout);
}
}
- } else if(i%3 == 0) {
- printf("\033[0;37mo\033[m");
+ } else if(i % 3 == 0) {
+ fputs("\033[0;37mo\033[m", stdout);
} else {
- printf("\033[0;37m \033[m");
+ fputs("\033[0;37m \033[m", stdout);
}
} /* else regular progress bar */
else if(i > hashlen - hash) {
- printf("#");
+ putchar('#');
} else {
- printf("-");
+ putchar('-');
}
}
- printf("]");
+ putchar(']');
}
/* print display percent after progress bar */
/* 5 = 1 space + 3 digits + 1 % */
@@ -138,9 +139,9 @@ static void fill_progress(const int bar_percent, const int disp_percent,
}
if(bar_percent == 100) {
- printf("\n");
+ putchar('\n');
} else {
- printf("\r");
+ putchar('\r');
}
fflush(stdout);
}
@@ -196,9 +197,9 @@ void cb_event(alpm_event_t event, void *data1, void *data2)
break;
case ALPM_EVENT_UPGRADE_DONE:
alpm_logaction(config->handle, "upgraded %s (%s -> %s)\n",
- (char *)alpm_pkg_get_name(data1),
- (char *)alpm_pkg_get_version(data2),
- (char *)alpm_pkg_get_version(data1));
+ alpm_pkg_get_name(data1),
+ alpm_pkg_get_version(data2),
+ alpm_pkg_get_version(data1));
display_new_optdepends(data2,data1);
break;
case ALPM_EVENT_INTEGRITY_START:
@@ -227,10 +228,10 @@ void cb_event(alpm_event_t event, void *data1, void *data2)
printf(_("failed.\n"));
break;
case ALPM_EVENT_SCRIPTLET_INFO:
- printf("%s", (char *)data1);
+ fputs((const char *)data1, stdout);
break;
case ALPM_EVENT_RETRIEVE_START:
- printf(_(":: Retrieving packages from %s...\n"), (char *)data1);
+ printf(_(":: Retrieving packages ...\n"));
break;
case ALPM_EVENT_DISKSPACE_START:
if(config->noprogressbar) {
@@ -294,7 +295,7 @@ void cb_question(alpm_question_t event, void *data1, void *data2,
break;
case ALPM_QUESTION_REMOVE_PKGS:
{
- alpm_list_t *unresolved = (alpm_list_t *) data1;
+ alpm_list_t *unresolved = data1;
alpm_list_t *namelist = NULL, *i;
size_t count = 0;
for (i = unresolved; i; i = i->next) {
@@ -317,7 +318,7 @@ void cb_question(alpm_question_t event, void *data1, void *data2,
break;
case ALPM_QUESTION_SELECT_PROVIDER:
{
- alpm_list_t *providers = (alpm_list_t *)data1;
+ alpm_list_t *providers = data1;
size_t count = alpm_list_count(providers);
char *depstring = alpm_dep_compute_string((alpm_depend_t *)data2);
printf(_(":: There are %zd providers available for %s:\n"), count,
@@ -340,15 +341,22 @@ void cb_question(alpm_question_t event, void *data1, void *data2,
*response = yesno(_(":: File %s is corrupted (%s).\n"
"Do you want to delete it?"),
(char *)data1,
- alpm_strerror(*(enum _alpm_errno_t *)data2));
+ alpm_strerror(*(alpm_errno_t *)data2));
break;
case ALPM_QUESTION_IMPORT_KEY:
{
alpm_pgpkey_t *key = data1;
char created[12];
- strftime(created, 12, "%Y-%m-%d", localtime(&(key->created)));
- *response = yesno(_(":: Import PGP key %s, \"%s\", created %s?"),
- key->fingerprint, key->uid, created);
+ const char *revoked = "";
+ time_t time = (time_t)key->created;
+ strftime(created, 12, "%Y-%m-%d", localtime(&time));
+
+ if (key->revoked) {
+ revoked = " (revoked)";
+ }
+
+ *response = yesno(_(":: Import PGP key %d%c/%s, \"%s\", created: %s%s?"),
+ key->length, key->pubkey_algo, key->fingerprint, key->uid, created, revoked);
}
break;
}
@@ -493,7 +501,7 @@ void cb_progress(alpm_progress_t event, const char *pkgname, int percent,
alpm_list_t *i = NULL;
on_progress = 0;
for(i = output; i; i = i->next) {
- printf("%s", (char *)i->data);
+ fputs((const char *)i->data, stdout);
}
fflush(stdout);
FREELIST(output);
@@ -713,7 +721,7 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total)
} else if(eta_h < 100) {
printf("%02u:%02u:%02u", eta_h, eta_m, eta_s);
} else {
- printf("--:--");
+ fputs("--:--", stdout);
}
free(fname);
diff --git a/src/pacman/conf.c b/src/pacman/conf.c
index a4d115dd..5328e7cc 100644
--- a/src/pacman/conf.c
+++ b/src/pacman/conf.c
@@ -203,11 +203,14 @@ static int download_with_xfercommand(const char *url, const char *localpath,
cleanup:
/* restore the old cwd if we have it */
if(cwdfd >= 0) {
+ int ret;
if(fchdir(cwdfd) != 0) {
pm_printf(ALPM_LOG_ERROR, _("could not restore working directory (%s)\n"),
strerror(errno));
}
- close(cwdfd);
+ do {
+ ret = close(cwdfd);
+ } while(ret == -1 && errno == EINTR);
}
if(ret == -1) {
@@ -522,7 +525,7 @@ static int _add_mirror(alpm_db_t *db, char *value)
static int setup_libalpm(void)
{
int ret = 0;
- enum _alpm_errno_t err;
+ alpm_errno_t err;
alpm_handle_t *handle;
pm_printf(ALPM_LOG_DEBUG, "setup_libalpm called\n");
@@ -659,7 +662,7 @@ static int finish_section(struct section_t *section, int parse_options)
}
for(i = section->servers; i; i = alpm_list_next(i)) {
- char *value = alpm_list_getdata(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"),
diff --git a/src/pacman/conf.h b/src/pacman/conf.h
index 9e14925a..325fbb64 100644
--- a/src/pacman/conf.h
+++ b/src/pacman/conf.h
@@ -128,7 +128,8 @@ enum {
OP_PRINTFORMAT,
OP_GPGDIR,
OP_RECURSIVE,
- OP_DBONLY
+ OP_DBONLY,
+ OP_FORCE
};
/* clean method */
diff --git a/src/pacman/deptest.c b/src/pacman/deptest.c
index 0055c37e..0bf9cd80 100644
--- a/src/pacman/deptest.c
+++ b/src/pacman/deptest.c
@@ -36,7 +36,7 @@ int pacman_deptest(alpm_list_t *targets)
alpm_db_t *localdb = alpm_option_get_localdb(config->handle);
for(i = targets; i; i = alpm_list_next(i)) {
- char *target = alpm_list_getdata(i);
+ char *target = i->data;
if(!alpm_find_satisfier(alpm_db_get_pkgcache(localdb), target)) {
deps = alpm_list_add(deps, target);
@@ -48,7 +48,7 @@ int pacman_deptest(alpm_list_t *targets)
}
for(i = deps; i; i = alpm_list_next(i)) {
- const char *dep = alpm_list_getdata(i);
+ const char *dep = i->data;
printf("%s\n", dep);
}
diff --git a/src/pacman/package.c b/src/pacman/package.c
index 12f555a1..d4bbf886 100644
--- a/src/pacman/package.c
+++ b/src/pacman/package.c
@@ -26,6 +26,7 @@
#include <unistd.h>
#include <limits.h>
#include <errno.h>
+#include <time.h>
#include <alpm.h>
#include <alpm_list.h>
@@ -46,7 +47,7 @@ static void deplist_display(const char *title,
{
alpm_list_t *i, *text = NULL;
for(i = deps; i; i = alpm_list_next(i)) {
- alpm_depend_t *dep = alpm_list_getdata(i);
+ alpm_depend_t *dep = i->data;
text = alpm_list_add(text, alpm_dep_compute_string(dep));
}
list_display(title, text);
@@ -74,11 +75,11 @@ void dump_pkg_full(alpm_pkg_t *pkg, int extra)
from = alpm_pkg_get_origin(pkg);
/* set variables here, do all output below */
- bdate = alpm_pkg_get_builddate(pkg);
+ bdate = (time_t)alpm_pkg_get_builddate(pkg);
if(bdate) {
strftime(bdatestr, 50, "%c", localtime(&bdate));
}
- idate = alpm_pkg_get_installdate(pkg);
+ idate = (time_t)alpm_pkg_get_installdate(pkg);
if(idate) {
strftime(idatestr, 50, "%c", localtime(&idate));
}
@@ -223,7 +224,7 @@ void dump_pkg_backups(alpm_pkg_t *pkg)
if(alpm_pkg_get_backup(pkg)) {
/* package has backup files, so print them */
for(i = alpm_pkg_get_backup(pkg); i; i = alpm_list_next(i)) {
- const alpm_backup_t *backup = alpm_list_getdata(i);
+ const alpm_backup_t *backup = i->data;
const char *value;
if(!backup->hash) {
continue;
@@ -251,11 +252,16 @@ void dump_pkg_files(alpm_pkg_t *pkg, int quiet)
for(i = 0; i < pkgfiles->count; i++) {
const alpm_file_t *file = pkgfiles->files + i;
+ /* Regular: '<pkgname> <root><filepath>\n'
+ * Quiet : '<root><filepath>\n'
+ */
if(!quiet) {
- printf("%s %s%s\n", pkgname, root, file->name);
- } else {
- printf("%s%s\n", root, file->name);
+ fputs(pkgname, stdout);
+ putchar(' ');
}
+ fputs(root, stdout);
+ fputs(file->name, stdout);
+ putchar('\n');
}
fflush(stdout);
@@ -280,10 +286,10 @@ void dump_pkg_changelog(alpm_pkg_t *pkg)
/* if we hit the end of the file, we need to add a null terminator */
*(buf + ret) = '\0';
}
- printf("%s", buf);
+ fputs(buf, stdout);
}
alpm_pkg_changelog_close(pkg, fp);
- printf("\n");
+ putchar('\n');
}
}
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 326664dd..fa35e8de 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -39,9 +39,6 @@
#include <sys/utsname.h> /* uname */
#include <locale.h> /* setlocale */
#include <errno.h>
-#if defined(PACMAN_DEBUG) && defined(HAVE_MCHECK_H)
-#include <mcheck.h> /* debug tracing (mtrace) */
-#endif
/* alpm */
#include <alpm.h>
@@ -180,7 +177,7 @@ static void usage(int op, const char * const myname)
switch(op) {
case PM_OP_SYNC:
case PM_OP_UPGRADE:
- addlist(_(" -f, --force force install, overwrite conflicting files\n"));
+ addlist(_(" --force force install, overwrite conflicting files\n"));
addlist(_(" --asdeps install packages as non-explicitly installed\n"));
addlist(_(" --asexplicit install packages as explicitly installed\n"));
addlist(_(" --ignore <pkg> ignore a package upgrade (can be used more than once)\n"));
@@ -211,7 +208,7 @@ static void usage(int op, const char * const myname)
}
list = alpm_list_msort(list, alpm_list_count(list), options_cmp);
for (i = list; i; i = alpm_list_next(i)) {
- printf("%s", (char *)alpm_list_getdata(i));
+ fputs((const char *)i->data, stdout);
}
alpm_list_free(list);
#undef addlist
@@ -533,7 +530,7 @@ static int parsearg_upgrade(int opt)
if(parsearg_trans(opt) == 0)
return 0;
switch(opt) {
- case 'f': config->flags |= ALPM_TRANS_FLAG_FORCE; break;
+ case OP_FORCE: config->flags |= ALPM_TRANS_FLAG_FORCE; break;
case OP_ASDEPS: config->flags |= ALPM_TRANS_FLAG_ALLDEPS; break;
case OP_ASEXPLICIT: config->flags |= ALPM_TRANS_FLAG_ALLEXPLICIT; break;
case OP_NEEDED: config->flags |= ALPM_TRANS_FLAG_NEEDED; break;
@@ -599,7 +596,6 @@ static int parseargs(int argc, char *argv[])
{"nodeps", no_argument, 0, 'd'},
{"deps", no_argument, 0, 'd'},
{"explicit", no_argument, 0, 'e'},
- {"force", no_argument, 0, 'f'},
{"groups", no_argument, 0, 'g'},
{"help", no_argument, 0, 'h'},
{"info", no_argument, 0, 'i'},
@@ -625,6 +621,7 @@ static int parseargs(int argc, char *argv[])
{"config", required_argument, 0, OP_CONFIG},
{"ignore", required_argument, 0, OP_IGNORE},
{"debug", optional_argument, 0, OP_DEBUG},
+ {"force", no_argument, 0, OP_FORCE},
{"noprogressbar", no_argument, 0, OP_NOPROGRESSBAR},
{"noscriptlet", no_argument, 0, OP_NOSCRIPTLET},
{"ask", required_argument, 0, OP_ASK},
@@ -769,11 +766,6 @@ int main(int argc, char *argv[])
uid_t myuid = geteuid();
#endif
-#if defined(PACMAN_DEBUG) && defined(HAVE_MCHECK_H)
- /*setenv("MALLOC_TRACE","pacman.mtrace", 0);*/
- mtrace();
-#endif
-
/* Set signal handlers */
/* Set up the structure to specify the new action. */
new_action.sa_handler = handler;
@@ -905,7 +897,7 @@ int main(int argc, char *argv[])
printf("DB Path : %s\n", alpm_option_get_dbpath(config->handle));
printf("Cache Dirs: ");
for(i = alpm_option_get_cachedirs(config->handle); i; i = alpm_list_next(i)) {
- printf("%s ", (char *)alpm_list_getdata(i));
+ printf("%s ", (const char *)i->data);
}
printf("\n");
printf("Lock File : %s\n", alpm_option_get_lockfile(config->handle));
diff --git a/src/pacman/query.c b/src/pacman/query.c
index ab19bab2..4c2ea817 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -143,7 +143,7 @@ static int query_fileowner(alpm_list_t *targets)
alpm_list_t *i;
int found = 0;
- filename = strdup(alpm_list_getdata(t));
+ filename = strdup(t->data);
if(lstat(filename, &buf) == -1) {
/* if it is not a path but a program name, then check in PATH */
@@ -193,7 +193,7 @@ static int query_fileowner(alpm_list_t *targets)
free(dname);
for(i = alpm_db_get_pkgcache(db_local); i && !found; i = alpm_list_next(i)) {
- alpm_pkg_t *info = alpm_list_getdata(i);
+ alpm_pkg_t *info = i->data;
alpm_filelist_t *filelist = alpm_pkg_get_files(info);
size_t j;
@@ -263,28 +263,28 @@ static int query_search(alpm_list_t *targets)
for(i = searchlist; i; i = alpm_list_next(i)) {
alpm_list_t *grp;
- alpm_pkg_t *pkg = alpm_list_getdata(i);
+ alpm_pkg_t *pkg = i->data;
if(!config->quiet) {
printf("local/%s %s", alpm_pkg_get_name(pkg), alpm_pkg_get_version(pkg));
} else {
- printf("%s", alpm_pkg_get_name(pkg));
+ fputs(alpm_pkg_get_name(pkg), stdout);
}
if(!config->quiet) {
if((grp = alpm_pkg_get_groups(pkg)) != NULL) {
alpm_list_t *k;
- printf(" (");
+ fputs(" (", stdout);
for(k = grp; k; k = alpm_list_next(k)) {
- const char *group = alpm_list_getdata(k);
- printf("%s", group);
+ const char *group = k->data;
+ fputs(group, stdout);
if(alpm_list_next(k)) {
/* only print a spacer if there are more groups */
- printf(" ");
+ putchar(' ');
}
}
- printf(")");
+ putchar(')');
}
/* we need a newline and initial indent first */
@@ -304,33 +304,33 @@ static int query_search(alpm_list_t *targets)
static int query_group(alpm_list_t *targets)
{
alpm_list_t *i, *j;
- char *grpname = NULL;
+ const char *grpname = NULL;
int ret = 0;
alpm_db_t *db_local = alpm_option_get_localdb(config->handle);
if(targets == NULL) {
for(j = alpm_db_get_groupcache(db_local); j; j = alpm_list_next(j)) {
- alpm_group_t *grp = alpm_list_getdata(j);
+ alpm_group_t *grp = j->data;
const alpm_list_t *p;
for(p = grp->packages; p; p = alpm_list_next(p)) {
- alpm_pkg_t *pkg = alpm_list_getdata(p);
+ alpm_pkg_t *pkg = p->data;
printf("%s %s\n", grp->name, alpm_pkg_get_name(pkg));
}
}
} else {
for(i = targets; i; i = alpm_list_next(i)) {
alpm_group_t *grp;
- grpname = alpm_list_getdata(i);
+ grpname = i->data;
grp = alpm_db_readgroup(db_local, grpname);
if(grp) {
const alpm_list_t *p;
for(p = grp->packages; p; p = alpm_list_next(p)) {
if(!config->quiet) {
printf("%s %s\n", grpname,
- alpm_pkg_get_name(alpm_list_getdata(p)));
+ alpm_pkg_get_name(p->data));
} else {
- printf("%s\n", alpm_pkg_get_name(alpm_list_getdata(p)));
+ printf("%s\n", alpm_pkg_get_name(p->data));
}
}
} else {
@@ -350,7 +350,7 @@ static int is_foreign(alpm_pkg_t *pkg)
int match = 0;
for(j = sync_dbs; j; j = alpm_list_next(j)) {
- alpm_db_t *db = alpm_list_getdata(j);
+ alpm_db_t *db = j->data;
alpm_pkg_t *findpkg = alpm_db_get_pkg(db, pkgname);
if(findpkg) {
match = 1;
@@ -526,7 +526,7 @@ int pacman_query(alpm_list_t *targets)
}
for(i = alpm_db_get_pkgcache(db_local); i; i = alpm_list_next(i)) {
- pkg = alpm_list_getdata(i);
+ pkg = i->data;
if(filter(pkg)) {
int value = display(pkg);
if(value != 0) {
@@ -552,7 +552,7 @@ int pacman_query(alpm_list_t *targets)
/* operations on named packages in the local DB
* valid: no-op (plain -Q), list, info, check */
for(i = targets; i; i = alpm_list_next(i)) {
- char *strname = alpm_list_getdata(i);
+ const char *strname = i->data;
if(config->op_q_isfile) {
alpm_pkg_load(config->handle, strname, 1, 0, &pkg);
diff --git a/src/pacman/remove.c b/src/pacman/remove.c
index 1cdf5d36..f56c1ec1 100644
--- a/src/pacman/remove.c
+++ b/src/pacman/remove.c
@@ -20,6 +20,7 @@
#include "config.h"
+#include <fnmatch.h>
#include <stdlib.h>
#include <stdio.h>
@@ -31,6 +32,11 @@
#include "util.h"
#include "conf.h"
+static int fnmatch_cmp(const void *pattern, const void *string)
+{
+ return fnmatch(pattern, string, 0);
+}
+
static int remove_target(const char *target)
{
alpm_pkg_t *pkg;
@@ -54,7 +60,7 @@ static int remove_target(const char *target)
return -1;
}
for(p = grp->packages; p; p = alpm_list_next(p)) {
- pkg = alpm_list_getdata(p);
+ pkg = p->data;
if(alpm_remove_pkg(config->handle, pkg) == -1) {
pm_printf(ALPM_LOG_ERROR, "'%s': %s\n", target,
alpm_strerror(alpm_errno(config->handle)));
@@ -89,7 +95,7 @@ int pacman_remove(alpm_list_t *targets)
/* Step 1: add targets to the created transaction */
for(i = targets; i; i = alpm_list_next(i)) {
- char *target = alpm_list_getdata(i);
+ char *target = i->data;
char *targ = strchr(target, '/');
if(targ && strncmp(target, "local", 5) == 0) {
targ++;
@@ -104,19 +110,19 @@ int pacman_remove(alpm_list_t *targets)
/* Step 2: prepare the transaction based on its type, targets and flags */
if(alpm_trans_prepare(config->handle, &data) == -1) {
- enum _alpm_errno_t err = alpm_errno(config->handle);
+ alpm_errno_t err = alpm_errno(config->handle);
pm_printf(ALPM_LOG_ERROR, _("failed to prepare transaction (%s)\n"),
alpm_strerror(err));
switch(err) {
case ALPM_ERR_PKG_INVALID_ARCH:
for(i = data; i; i = alpm_list_next(i)) {
- char *pkg = alpm_list_getdata(i);
+ const char *pkg = i->data;
printf(_(":: package %s does not have a valid architecture\n"), pkg);
}
break;
case ALPM_ERR_UNSATISFIED_DEPS:
for(i = data; i; i = alpm_list_next(i)) {
- alpm_depmissing_t *miss = alpm_list_getdata(i);
+ alpm_depmissing_t *miss = i->data;
char *depstring = alpm_dep_compute_string(miss->depend);
printf(_(":: %s: requires %s\n"), miss->target, depstring);
free(depstring);
@@ -133,8 +139,8 @@ int pacman_remove(alpm_list_t *targets)
/* Search for holdpkg in target list */
int holdpkg = 0;
for(i = alpm_trans_get_remove(config->handle); i; i = alpm_list_next(i)) {
- alpm_pkg_t *pkg = alpm_list_getdata(i);
- if(alpm_list_find_str(config->holdpkg, alpm_pkg_get_name(pkg))) {
+ alpm_pkg_t *pkg = i->data;
+ if(alpm_list_find(config->holdpkg, alpm_pkg_get_name(pkg), fnmatch_cmp)) {
pm_printf(ALPM_LOG_WARNING, _("%s is designated as a HoldPkg.\n"),
alpm_pkg_get_name(pkg));
holdpkg = 1;
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index 2773708c..1003a421 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -95,7 +95,7 @@ static int sync_cleandb(const char *dbpath, int keep_used)
len = strlen(dname);
char *dbname = strndup(dname, len - 3);
for(i = syncdbs; i && !found; i = alpm_list_next(i)) {
- alpm_db_t *db = alpm_list_getdata(i);
+ alpm_db_t *db = i->data;
found = !strcmp(dbname, alpm_db_get_name(db));
}
free(dbname);
@@ -155,7 +155,7 @@ static int sync_cleancache(int level)
int ret = 0;
for(i = cachedirs; i; i = alpm_list_next(i)) {
- printf(_("Cache directory: %s\n"), (char *)alpm_list_getdata(i));
+ printf(_("Cache directory: %s\n"), (const char *)i->data);
}
if(!config->cleanmethod) {
@@ -183,7 +183,7 @@ static int sync_cleancache(int level)
}
for(i = cachedirs; i; i = alpm_list_next(i)) {
- const char *cachedir = alpm_list_getdata(i);
+ const char *cachedir = i->data;
DIR *dir = opendir(cachedir);
struct dirent *ent;
@@ -253,7 +253,7 @@ static int sync_cleancache(int level)
alpm_list_t *j;
/* check if this package is in a sync DB */
for(j = sync_dbs; j && delete; j = alpm_list_next(j)) {
- alpm_db_t *db = alpm_list_getdata(j);
+ alpm_db_t *db = j->data;
pkg = alpm_db_get_pkg(db, local_name);
if(pkg != NULL && alpm_pkg_vercmp(local_version,
alpm_pkg_get_version(pkg)) == 0) {
@@ -288,7 +288,7 @@ static int sync_synctree(int level, alpm_list_t *syncs)
int success = 0, ret;
for(i = syncs; i; i = alpm_list_next(i)) {
- alpm_db_t *db = alpm_list_getdata(i);
+ alpm_db_t *db = i->data;
ret = alpm_db_update((level < 2 ? 0 : 1), db);
if(ret < 0) {
@@ -337,7 +337,7 @@ static int sync_search(alpm_list_t *syncs, alpm_list_t *targets)
alpm_db_t *db_local = alpm_option_get_localdb(config->handle);
for(i = syncs; i; i = alpm_list_next(i)) {
- alpm_db_t *db = alpm_list_getdata(i);
+ alpm_db_t *db = i->data;
/* if we have a targets list, search for packages matching it */
if(targets) {
ret = alpm_db_search(db, targets);
@@ -353,28 +353,28 @@ static int sync_search(alpm_list_t *syncs, alpm_list_t *targets)
}
for(j = ret; j; j = alpm_list_next(j)) {
alpm_list_t *grp;
- alpm_pkg_t *pkg = alpm_list_getdata(j);
+ alpm_pkg_t *pkg = j->data;
if(!config->quiet) {
printf("%s/%s %s", alpm_db_get_name(db), alpm_pkg_get_name(pkg),
alpm_pkg_get_version(pkg));
} else {
- printf("%s", alpm_pkg_get_name(pkg));
+ fputs(alpm_pkg_get_name(pkg), stdout);
}
if(!config->quiet) {
if((grp = alpm_pkg_get_groups(pkg)) != NULL) {
alpm_list_t *k;
- printf(" (");
+ fputs(" (", stdout);
for(k = grp; k; k = alpm_list_next(k)) {
- const char *group = alpm_list_getdata(k);
- printf("%s", group);
+ const char *group = k->data;
+ fputs(group, stdout);
if(alpm_list_next(k)) {
/* only print a spacer if there are more groups */
- printf(" ");
+ putchar(' ');
}
}
- printf(")");
+ putchar(')');
}
print_installed(db_local, pkg);
@@ -400,9 +400,9 @@ static int sync_group(int level, alpm_list_t *syncs, alpm_list_t *targets)
if(targets) {
for(i = targets; i; i = alpm_list_next(i)) {
- const char *grpname = alpm_list_getdata(i);
+ const char *grpname = i->data;
for(j = syncs; j; j = alpm_list_next(j)) {
- alpm_db_t *db = alpm_list_getdata(j);
+ alpm_db_t *db = j->data;
alpm_group_t *grp = alpm_db_readgroup(db, grpname);
if(grp) {
@@ -410,9 +410,9 @@ static int sync_group(int level, alpm_list_t *syncs, alpm_list_t *targets)
for(k = grp->packages; k; k = alpm_list_next(k)) {
if(!config->quiet) {
printf("%s %s\n", grpname,
- alpm_pkg_get_name(alpm_list_getdata(k)));
+ alpm_pkg_get_name(k->data));
} else {
- printf("%s\n", alpm_pkg_get_name(alpm_list_getdata(k)));
+ printf("%s\n", alpm_pkg_get_name(k->data));
}
}
}
@@ -420,15 +420,15 @@ static int sync_group(int level, alpm_list_t *syncs, alpm_list_t *targets)
}
} else {
for(i = syncs; i; i = alpm_list_next(i)) {
- alpm_db_t *db = alpm_list_getdata(i);
+ alpm_db_t *db = i->data;
for(j = alpm_db_get_groupcache(db); j; j = alpm_list_next(j)) {
- alpm_group_t *grp = alpm_list_getdata(j);
+ alpm_group_t *grp = j->data;
if(level > 1) {
for(k = grp->packages; k; k = alpm_list_next(k)) {
printf("%s %s\n", grp->name,
- alpm_pkg_get_name(alpm_list_getdata(k)));
+ alpm_pkg_get_name(k->data));
}
} else {
/* print grp names only, no package names */
@@ -448,7 +448,7 @@ static int sync_info(alpm_list_t *syncs, alpm_list_t *targets)
if(targets) {
for(i = targets; i; i = alpm_list_next(i)) {
- const char *target = alpm_list_getdata(i);
+ const char *target = i->data;
char *name = strdup(target);
char *repo, *pkgstr;
int foundpkg = 0, founddb = 0;
@@ -464,14 +464,14 @@ static int sync_info(alpm_list_t *syncs, alpm_list_t *targets)
}
for(j = syncs; j; j = alpm_list_next(j)) {
- alpm_db_t *db = alpm_list_getdata(j);
+ alpm_db_t *db = j->data;
if(repo && strcmp(repo, alpm_db_get_name(db)) != 0) {
continue;
}
founddb = 1;
for(k = alpm_db_get_pkgcache(db); k; k = alpm_list_next(k)) {
- alpm_pkg_t *pkg = alpm_list_getdata(k);
+ alpm_pkg_t *pkg = k->data;
if(strcmp(alpm_pkg_get_name(pkg), pkgstr) == 0) {
dump_pkg_full(pkg, config->op_s_info > 1);
@@ -495,10 +495,10 @@ static int sync_info(alpm_list_t *syncs, alpm_list_t *targets)
}
} else {
for(i = syncs; i; i = alpm_list_next(i)) {
- alpm_db_t *db = alpm_list_getdata(i);
+ alpm_db_t *db = i->data;
for(j = alpm_db_get_pkgcache(db); j; j = alpm_list_next(j)) {
- alpm_pkg_t *pkg = alpm_list_getdata(j);
+ alpm_pkg_t *pkg = j->data;
dump_pkg_full(pkg, config->op_s_info > 1);
}
}
@@ -514,11 +514,11 @@ static int sync_list(alpm_list_t *syncs, alpm_list_t *targets)
if(targets) {
for(i = targets; i; i = alpm_list_next(i)) {
- const char *repo = alpm_list_getdata(i);
+ const char *repo = i->data;
alpm_db_t *db = NULL;
for(j = syncs; j; j = alpm_list_next(j)) {
- alpm_db_t *d = alpm_list_getdata(j);
+ alpm_db_t *d = j->data;
if(strcmp(repo, alpm_db_get_name(d)) == 0) {
db = d;
@@ -540,10 +540,10 @@ static int sync_list(alpm_list_t *syncs, alpm_list_t *targets)
}
for(i = ls; i; i = alpm_list_next(i)) {
- alpm_db_t *db = alpm_list_getdata(i);
+ alpm_db_t *db = i->data;
for(j = alpm_db_get_pkgcache(db); j; j = alpm_list_next(j)) {
- alpm_pkg_t *pkg = alpm_list_getdata(j);
+ alpm_pkg_t *pkg = j->data;
if(!config->quiet) {
printf("%s %s %s", alpm_db_get_name(db), alpm_pkg_get_name(pkg),
@@ -569,7 +569,7 @@ static alpm_list_t *syncfirst(void) {
alpm_list_t *syncdbs = alpm_option_get_syncdbs(config->handle);
for(i = config->syncfirst; i; i = alpm_list_next(i)) {
- char *pkgname = alpm_list_getdata(i);
+ const char *pkgname = i->data;
alpm_pkg_t *pkg = alpm_db_get_pkg(db_local, pkgname);
if(pkg == NULL) {
continue;
@@ -600,7 +600,7 @@ static int process_pkg(alpm_pkg_t *pkg)
int ret = alpm_add_pkg(config->handle, pkg);
if(ret == -1) {
- enum _alpm_errno_t err = alpm_errno(config->handle);
+ alpm_errno_t err = alpm_errno(config->handle);
if(err == ALPM_ERR_TRANS_DUP_TARGET
|| err == ALPM_ERR_PKG_IGNORED) {
/* just skip duplicate or ignored targets */
@@ -647,7 +647,7 @@ static int process_group(alpm_list_t *dbs, const char *group)
for(i = pkgs; i; i = alpm_list_next(i)) {
if(array[n++] == 0)
continue;
- alpm_pkg_t *pkg = alpm_list_getdata(i);
+ alpm_pkg_t *pkg = i->data;
if(process_pkg(pkg) == 1) {
ret = 1;
@@ -658,7 +658,7 @@ static int process_group(alpm_list_t *dbs, const char *group)
free(array);
} else {
for(i = pkgs; i; i = alpm_list_next(i)) {
- alpm_pkg_t *pkg = alpm_list_getdata(i);
+ alpm_pkg_t *pkg = i->data;
if(process_pkg(pkg) == 1) {
ret = 1;
@@ -739,7 +739,7 @@ static int sync_trans(alpm_list_t *targets)
/* process targets */
for(i = targets; i; i = alpm_list_next(i)) {
- char *targ = alpm_list_getdata(i);
+ const char *targ = i->data;
if(process_target(targ) == 1) {
trans_release();
return 1;
@@ -766,19 +766,19 @@ int sync_prepare_execute(void)
/* Step 2: "compute" the transaction based on targets and flags */
if(alpm_trans_prepare(config->handle, &data) == -1) {
- enum _alpm_errno_t err = alpm_errno(config->handle);
+ alpm_errno_t err = alpm_errno(config->handle);
pm_printf(ALPM_LOG_ERROR, _("failed to prepare transaction (%s)\n"),
alpm_strerror(err));
switch(err) {
case ALPM_ERR_PKG_INVALID_ARCH:
for(i = data; i; i = alpm_list_next(i)) {
- char *pkg = alpm_list_getdata(i);
+ const char *pkg = i->data;
printf(_(":: package %s does not have a valid architecture\n"), pkg);
}
break;
case ALPM_ERR_UNSATISFIED_DEPS:
for(i = data; i; i = alpm_list_next(i)) {
- alpm_depmissing_t *miss = alpm_list_getdata(i);
+ alpm_depmissing_t *miss = i->data;
char *depstring = alpm_dep_compute_string(miss->depend);
printf(_(":: %s: requires %s\n"), miss->target, depstring);
free(depstring);
@@ -786,7 +786,7 @@ int sync_prepare_execute(void)
break;
case ALPM_ERR_CONFLICTING_DEPS:
for(i = data; i; i = alpm_list_next(i)) {
- alpm_conflict_t *conflict = alpm_list_getdata(i);
+ alpm_conflict_t *conflict = i->data;
/* only print reason if it contains new information */
if(conflict->reason->mod == ALPM_DEP_MOD_ANY) {
printf(_(":: %s and %s are in conflict\n"),
@@ -835,13 +835,13 @@ int sync_prepare_execute(void)
}
if(alpm_trans_commit(config->handle, &data) == -1) {
- enum _alpm_errno_t err = alpm_errno(config->handle);
+ alpm_errno_t err = alpm_errno(config->handle);
pm_printf(ALPM_LOG_ERROR, _("failed to commit transaction (%s)\n"),
alpm_strerror(err));
switch(err) {
case ALPM_ERR_FILE_CONFLICTS:
for(i = data; i; i = alpm_list_next(i)) {
- alpm_fileconflict_t *conflict = alpm_list_getdata(i);
+ alpm_fileconflict_t *conflict = i->data;
switch(conflict->type) {
case ALPM_FILECONFLICT_TARGET:
printf(_("%s exists in both '%s' and '%s'\n"),
@@ -859,7 +859,7 @@ int sync_prepare_execute(void)
case ALPM_ERR_PKG_INVALID_SIG:
case ALPM_ERR_DLT_INVALID:
for(i = data; i; i = alpm_list_next(i)) {
- const char *filename = alpm_list_getdata(i);
+ const char *filename = i->data;
printf(_("%s is invalid or corrupted\n"), filename);
}
break;
diff --git a/src/pacman/upgrade.c b/src/pacman/upgrade.c
index 880aa4c6..0ca6fec8 100644
--- a/src/pacman/upgrade.c
+++ b/src/pacman/upgrade.c
@@ -73,7 +73,7 @@ int pacman_upgrade(alpm_list_t *targets)
printf(_("loading packages...\n"));
/* add targets to the created transaction */
for(i = targets; i; i = alpm_list_next(i)) {
- char *targ = alpm_list_getdata(i);
+ const char *targ = i->data;
alpm_pkg_t *pkg;
if(alpm_pkg_load(config->handle, targ, 1, level, &pkg) != 0) {
diff --git a/src/pacman/util.c b/src/pacman/util.c
index b9ee8c9c..c0dcb9f2 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -23,7 +23,7 @@
#include <sys/types.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
-#include <sys/time.h>
+#include <time.h>
#include <stdio.h>
#include <stdlib.h>
@@ -65,7 +65,7 @@ int trans_init(alpm_transflag_t flags, int check_valid)
void trans_init_error(void)
{
- enum _alpm_errno_t err = alpm_errno(config->handle);
+ alpm_errno_t err = alpm_errno(config->handle);
pm_printf(ALPM_LOG_ERROR, _("failed to init transaction (%s)\n"),
alpm_strerror(err));
if(err == ALPM_ERR_HANDLE_LOCK) {
@@ -266,7 +266,7 @@ void indentprint(const char *str, size_t indent)
/* if we're not a tty, or our tty is not wide enough that wrapping even makes
* sense, print without indenting */
if(cols == 0 || indent > cols) {
- printf("%s", str);
+ fputs(str, stdout);
return;
}
@@ -400,7 +400,7 @@ char *strreplace(const char *str, const char *needle, const char *replace)
p = str;
newp = newstr;
for(i = list; i; i = alpm_list_next(i)) {
- q = alpm_list_getdata(i);
+ q = i->data;
if(q > p) {
/* add chars between this occurence and last occurence, if any */
memcpy(newp, p, (size_t)(q - p));
@@ -487,77 +487,120 @@ void string_display(const char *title, const char *string)
printf("\n");
}
-static void table_print_line(const alpm_list_t *line,
- size_t colcount, size_t *widths)
+static void table_print_line(const alpm_list_t *line, short col_padding,
+ size_t colcount, size_t *widths, int *has_data)
{
- size_t i;
+ size_t i, lastcol = 0;
+ int need_padding = 0;
const alpm_list_t *curcell;
+ for(i = colcount; i > 0; i--) {
+ if(has_data[i - 1]) {
+ lastcol = i - 1;
+ break;
+ }
+ }
+
for(i = 0, curcell = line; curcell && i < colcount;
i++, curcell = alpm_list_next(curcell)) {
- const char *value = curcell->data;
- size_t len = string_length(value);
+ const char *value;
+ int cell_padding;
+
+ if(!has_data[i]) {
+ continue;
+ }
+
+ value = curcell->data;
/* silly printf requires padding size to be an int */
- int padding = (int)widths[i] - (int)len;
- if(padding < 0) {
- padding = 0;
+ cell_padding = (int)widths[i] - (int)string_length(value);
+ if(cell_padding < 0) {
+ cell_padding = 0;
+ }
+ if(need_padding) {
+ printf("%*s", col_padding, "");
}
/* left-align all but the last column */
- if(i + 1 < colcount) {
- printf("%s%*s", value, padding, "");
+ if(i != lastcol) {
+ printf("%s%*s", value, cell_padding, "");
} else {
- printf("%*s%s", padding, "", value);
+ printf("%*s%s", cell_padding, "", value);
}
+ need_padding = 1;
}
printf("\n");
}
-/* find the max string width of each column */
+
+
+/**
+ * Find the max string width of each column. Also determines whether values
+ * exist in the column and sets the value in has_data accordingly.
+ * @param header a list of header strings
+ * @param rows a list of lists of rows as strings
+ * @param padding the amount of padding between columns
+ * @param totalcols the total number of columns in the header and each row
+ * @param widths a pointer to store width data
+ * @param has_data a pointer to store whether column has data
+ *
+ * @return the total width of the table; 0 on failure
+ */
static size_t table_calc_widths(const alpm_list_t *header,
- const alpm_list_t *rows, size_t totalcols, size_t **widths)
+ const alpm_list_t *rows, short padding, size_t totalcols,
+ size_t **widths, int **has_data)
{
const alpm_list_t *i;
- const unsigned short padding = 2;
- size_t curcol, totalwidth = 0;
+ size_t curcol, totalwidth = 0, usefulcols = 0;
size_t *colwidths;
+ int *coldata;
if(totalcols <= 0) {
return 0;
}
colwidths = malloc(totalcols * sizeof(size_t));
- if(!colwidths) {
+ coldata = calloc(totalcols, sizeof(int));
+ if(!colwidths || !coldata) {
return 0;
}
/* header determines column count and initial values of longest_strs */
for(i = header, curcol = 0; i; i = alpm_list_next(i), curcol++) {
- colwidths[curcol] = string_length(alpm_list_getdata(i));
+ colwidths[curcol] = string_length(i->data);
+ /* note: header does not determine whether column has data */
}
/* now find the longest string in each column */
for(i = rows; i; i = alpm_list_next(i)) {
/* grab first column of each row and iterate through columns */
- const alpm_list_t *j = alpm_list_getdata(i);
+ const alpm_list_t *j = i->data;
for(curcol = 0; j; j = alpm_list_next(j), curcol++) {
- char *str = alpm_list_getdata(j);
+ const char *str = j->data;
size_t str_len = string_length(str);
if(str_len > colwidths[curcol]) {
colwidths[curcol] = str_len;
}
+ if(str_len > 0) {
+ coldata[curcol] = 1;
+ }
}
}
for(i = header, curcol = 0; i; i = alpm_list_next(i), curcol++) {
- /* pad everything but the last column */
- if(curcol + 1 < totalcols) {
- colwidths[curcol] += padding;
+ /* only include columns that have data */
+ if(coldata[curcol]) {
+ usefulcols++;
+ totalwidth += colwidths[curcol];
}
- totalwidth += colwidths[curcol];
+ }
+
+ /* add padding between columns */
+ if(usefulcols > 0) {
+ totalwidth += padding * (usefulcols - 1);
}
*widths = colwidths;
+ *has_data = coldata;
return totalwidth;
}
@@ -574,22 +617,25 @@ static size_t table_calc_widths(const alpm_list_t *header,
int table_display(const char *title, const alpm_list_t *header,
const alpm_list_t *rows)
{
+ const unsigned short padding = 2;
const alpm_list_t *i;
size_t *widths = NULL, totalcols, totalwidth;
+ int *has_data = NULL;
if(rows == NULL || header == NULL) {
return 0;
}
totalcols = alpm_list_count(header);
- totalwidth = table_calc_widths(header, rows, totalcols, &widths);
+ totalwidth = table_calc_widths(header, rows, padding, totalcols,
+ &widths, &has_data);
/* return -1 if terminal is not wide enough */
if(totalwidth > getcols()) {
pm_printf(ALPM_LOG_WARNING,
_("insufficient columns available for table display\n"));
return -1;
}
- if(!totalwidth || !widths) {
+ if(!totalwidth || !widths || !has_data) {
return -1;
}
@@ -597,14 +643,15 @@ int table_display(const char *title, const alpm_list_t *header,
printf("%s\n\n", title);
}
- table_print_line(header, totalcols, widths);
+ table_print_line(header, padding, totalcols, widths, has_data);
printf("\n");
for(i = rows; i; i = alpm_list_next(i)) {
- table_print_line(alpm_list_getdata(i), totalcols, widths);
+ table_print_line(i->data, padding, totalcols, widths, has_data);
}
free(widths);
+ free(has_data);
return 0;
}
@@ -623,11 +670,11 @@ void list_display(const char *title, const alpm_list_t *list)
} else {
const unsigned short maxcols = getcols();
size_t cols = len;
- const char *str = alpm_list_getdata(list);
- printf("%s", str);
+ const char *str = list->data;
+ fputs(str, stdout);
cols += string_length(str);
for(i = alpm_list_next(list); i; i = alpm_list_next(i)) {
- str = alpm_list_getdata(i);
+ str = i->data;
size_t s = string_length(str);
/* wrap only if we have enough usable column space */
if(maxcols > len && cols + s + 2 >= maxcols) {
@@ -642,10 +689,10 @@ void list_display(const char *title, const alpm_list_t *list)
printf(" ");
cols += 2;
}
- printf("%s", str);
+ fputs(str, stdout);
cols += s;
}
- printf("\n");
+ putchar('\n');
}
}
@@ -663,7 +710,7 @@ void list_display_linebreak(const char *title, const alpm_list_t *list)
} else {
const alpm_list_t *i;
/* Print the first element */
- indentprint((const char *) alpm_list_getdata(list), len);
+ indentprint((const char *)list->data, len);
printf("\n");
/* Print the rest */
for(i = alpm_list_next(list); i; i = alpm_list_next(i)) {
@@ -671,7 +718,7 @@ void list_display_linebreak(const char *title, const alpm_list_t *list)
for(j = 1; j <= len; j++) {
printf(" ");
}
- indentprint((const char *) alpm_list_getdata(i), len);
+ indentprint((const char *)i->data, len);
printf("\n");
}
}
@@ -786,7 +833,12 @@ static alpm_list_t *create_verbose_row(pm_target_t *target, int dl_size)
/* a row consists of the package name, */
if(target->install) {
- pm_asprintf(&str, "%s", alpm_pkg_get_name(target->install));
+ const alpm_db_t *db = alpm_pkg_get_db(target->install);
+ if(db) {
+ pm_asprintf(&str, "%s/%s", alpm_db_get_name(db), alpm_pkg_get_name(target->install));
+ } else {
+ pm_asprintf(&str, "%s", alpm_pkg_get_name(target->install));
+ }
} else {
pm_asprintf(&str, "%s", alpm_pkg_get_name(target->remove));
}
@@ -838,7 +890,7 @@ static void _display_targets(alpm_list_t *targets, int verbose)
/* gather package info */
for(i = targets; i; i = alpm_list_next(i)) {
- pm_target_t *target = alpm_list_getdata(i);
+ pm_target_t *target = i->data;
if(target->install) {
dlsize += alpm_pkg_download_size(target->install);
@@ -882,7 +934,7 @@ static void _display_targets(alpm_list_t *targets, int verbose)
/* rows is a list of lists of strings, free inner lists here */
for(i = rows; i; i = alpm_list_next(i)) {
- alpm_list_t *lp = alpm_list_getdata(i);
+ alpm_list_t *lp = i->data;
FREELIST(lp);
}
alpm_list_free(rows);
@@ -939,7 +991,7 @@ void display_targets(void)
alpm_db_t *db_local = alpm_option_get_localdb(config->handle);
for(i = alpm_trans_get_add(config->handle); i; i = alpm_list_next(i)) {
- alpm_pkg_t *pkg = alpm_list_getdata(i);
+ alpm_pkg_t *pkg = i->data;
pm_target_t *targ = calloc(1, sizeof(pm_target_t));
if(!targ) return;
targ->install = pkg;
@@ -950,7 +1002,7 @@ void display_targets(void)
targets = alpm_list_add(targets, targ);
}
for(i = alpm_trans_get_remove(config->handle); i; i = alpm_list_next(i)) {
- alpm_pkg_t *pkg = alpm_list_getdata(i);
+ alpm_pkg_t *pkg = i->data;
pm_target_t *targ = calloc(1, sizeof(pm_target_t));
if(!targ) return;
targ->remove = pkg;
@@ -985,7 +1037,7 @@ static char *pkg_get_location(alpm_pkg_t *pkg)
case PM_OP_SYNC:
servers = alpm_db_get_servers(alpm_pkg_get_db(pkg));
if(servers) {
- pm_asprintf(&string, "%s/%s", alpm_list_getdata(servers),
+ pm_asprintf(&string, "%s/%s", servers->data,
alpm_pkg_get_filename(pkg));
return string;
}
@@ -1040,7 +1092,7 @@ void print_packages(const alpm_list_t *packages)
config->print_format = strdup("%l");
}
for(i = packages; i; i = alpm_list_next(i)) {
- alpm_pkg_t *pkg = alpm_list_getdata(i);
+ alpm_pkg_t *pkg = i->data;
char *string = strdup(config->print_format);
char *temp = string;
/* %n : pkgname */
@@ -1133,7 +1185,7 @@ void select_display(const alpm_list_t *pkglist)
const char *dbname = NULL;
for (i = pkglist; i; i = i->next) {
- alpm_pkg_t *pkg = alpm_list_getdata(i);
+ alpm_pkg_t *pkg = i->data;
alpm_db_t *db = alpm_pkg_get_db(pkg);
if(!dbname)
diff --git a/src/util/cleanupdelta.c b/src/util/cleanupdelta.c
index 6553e6f6..d6bd0e86 100644
--- a/src/util/cleanupdelta.c
+++ b/src/util/cleanupdelta.c
@@ -56,10 +56,10 @@ static void checkpkgs(alpm_list_t *pkglist)
{
alpm_list_t *i, *j;
for(i = pkglist; i; i = alpm_list_next(i)) {
- alpm_pkg_t *pkg = alpm_list_getdata(i);
+ alpm_pkg_t *pkg = i->data;
alpm_list_t *unused = alpm_pkg_unused_deltas(pkg);
for(j = unused; j; j = alpm_list_next(j)) {
- char *delta = alpm_list_getdata(j);
+ const char *delta = j->data;
printf("%s\n", delta);
}
alpm_list_free(unused);
@@ -72,7 +72,7 @@ static void checkdbs(alpm_list_t *dbnames) {
const alpm_siglevel_t level = ALPM_SIG_DATABASE | ALPM_SIG_DATABASE_OPTIONAL;
for(i = dbnames; i; i = alpm_list_next(i)) {
- const char *dbname = alpm_list_getdata(i);
+ const char *dbname = i->data;
db = alpm_db_register_sync(handle, dbname, level);
if(db == NULL) {
fprintf(stderr, "error: could not register sync database '%s' (%s)\n",
@@ -94,7 +94,7 @@ static void usage(void) {
int main(int argc, char *argv[])
{
const char *dbpath = DBPATH;
- enum _alpm_errno_t err;
+ alpm_errno_t err;
int a = 1;
alpm_list_t *dbnames = NULL;
diff --git a/src/util/pactree.c b/src/util/pactree.c
index 997ba466..f95c5e89 100644
--- a/src/util/pactree.c
+++ b/src/util/pactree.c
@@ -363,7 +363,7 @@ static alpm_pkg_t *get_pkg_from_dbs(alpm_list_t *dbs, const char *needle) {
alpm_pkg_t *ret;
for(i = dbs; i; i = alpm_list_next(i)) {
- ret = alpm_db_get_pkg(alpm_list_getdata(i), needle);
+ ret = alpm_db_get_pkg(i->data, needle);
if(ret) {
return ret;
}
@@ -386,7 +386,7 @@ static void walk_reverse_deps(alpm_list_t *dblist, alpm_pkg_t *pkg, int depth)
required_by = alpm_pkg_compute_requiredby(pkg);
for(i = required_by; i; i = alpm_list_next(i)) {
- const char *pkgname = alpm_list_getdata(i);
+ const char *pkgname = i->data;
if(alpm_list_find_str(walked, pkgname)) {
/* if we've already seen this package, don't print in "unique" output
@@ -417,7 +417,7 @@ static void walk_deps(alpm_list_t *dblist, alpm_pkg_t *pkg, int depth)
walked = alpm_list_add(walked, (void *)alpm_pkg_get_name(pkg));
for(i = alpm_pkg_get_depends(pkg); i; i = alpm_list_next(i)) {
- alpm_depend_t *depend = alpm_list_getdata(i);
+ alpm_depend_t *depend = i->data;
alpm_pkg_t *provider = alpm_find_dbs_satisfier(handle, dblist, depend->name);
if(provider) {
@@ -443,7 +443,7 @@ static void walk_deps(alpm_list_t *dblist, alpm_pkg_t *pkg, int depth)
int main(int argc, char *argv[])
{
int freelist = 0, ret = 0;
- enum _alpm_errno_t err;
+ alpm_errno_t err;
const char *target_name;
alpm_pkg_t *pkg;
alpm_list_t *dblist = NULL;
diff --git a/src/util/testdb.c b/src/util/testdb.c
index d85687a4..b15bbe5e 100644
--- a/src/util/testdb.c
+++ b/src/util/testdb.c
@@ -101,7 +101,7 @@ static int checkdeps(alpm_list_t *pkglist)
/* check dependencies */
data = alpm_checkdeps(handle, pkglist, NULL, pkglist, 0);
for(i = data; i; i = alpm_list_next(i)) {
- alpm_depmissing_t *miss = alpm_list_getdata(i);
+ alpm_depmissing_t *miss = i->data;
char *depstring = alpm_dep_compute_string(miss->depend);
printf("missing dependency for %s : %s\n", miss->target,
depstring);
@@ -119,7 +119,7 @@ static int checkconflicts(alpm_list_t *pkglist)
/* check conflicts */
data = alpm_checkconflicts(handle, pkglist);
for(i = data; i; i = i->next) {
- alpm_conflict_t *conflict = alpm_list_getdata(i);
+ alpm_conflict_t *conflict = i->data;
printf("%s conflicts with %s\n",
conflict->package1, conflict->package2);
ret++;
@@ -154,7 +154,7 @@ static int check_syncdbs(alpm_list_t *dbnames)
const alpm_siglevel_t level = ALPM_SIG_DATABASE | ALPM_SIG_DATABASE_OPTIONAL;
for(i = dbnames; i; i = alpm_list_next(i)) {
- char *dbname = alpm_list_getdata(i);
+ const char *dbname = i->data;
db = alpm_db_register_sync(handle, dbname, level);
if(db == NULL) {
fprintf(stderr, "error: could not register sync database (%s)\n",
@@ -185,7 +185,7 @@ static void usage(void)
int main(int argc, char *argv[])
{
int ret = 0;
- enum _alpm_errno_t err;
+ alpm_errno_t err;
const char *dbpath = DBPATH;
int a = 1;
alpm_list_t *dbnames = NULL;
diff --git a/src/util/testpkg.c b/src/util/testpkg.c
index 90758e16..6385e417 100644
--- a/src/util/testpkg.c
+++ b/src/util/testpkg.c
@@ -41,7 +41,7 @@ int main(int argc, char *argv[])
{
int retval = 1; /* default = false */
alpm_handle_t *handle;
- enum _alpm_errno_t err;
+ alpm_errno_t err;
alpm_pkg_t *pkg = NULL;
const alpm_siglevel_t level = ALPM_SIG_PACKAGE | ALPM_SIG_PACKAGE_OPTIONAL;
diff --git a/test/pacman/tests/ignore008.py b/test/pacman/tests/ignore008.py
new file mode 100644
index 00000000..12416ad9
--- /dev/null
+++ b/test/pacman/tests/ignore008.py
@@ -0,0 +1,29 @@
+self.description = "Sync with relevant ignored fnmatched packages"
+
+package1 = pmpkg("foopkg", "1.0-1")
+self.addpkg2db("local", package1)
+
+package2 = pmpkg("barpkg", "2.0-1")
+self.addpkg2db("local", package2)
+
+package3 = pmpkg("bazpkg", "3.0-1")
+self.addpkg2db("local", package3)
+
+
+package1up = pmpkg("foopkg", "2.0-1")
+self.addpkg2db("sync", package1up)
+
+package2up = pmpkg("barpkg", "3.0-1")
+self.addpkg2db("sync", package2up)
+
+package3up = pmpkg("bazpkg", "4.0-1")
+self.addpkg2db("sync", package3up)
+
+self.option["IgnorePkg"] = ["foo*", "ba?pkg"]
+self.args = "-Su"
+
+
+self.addrule("PACMAN_RETCODE=0")
+self.addrule("PKG_VERSION=foopkg|1.0-1")
+self.addrule("PKG_VERSION=barpkg|2.0-1")
+self.addrule("PKG_VERSION=bazpkg|3.0-1")
diff --git a/test/pacman/tests/remove031.py b/test/pacman/tests/remove031.py
new file mode 100644
index 00000000..0ea09c87
--- /dev/null
+++ b/test/pacman/tests/remove031.py
@@ -0,0 +1,11 @@
+self.description = "Remove a package in HoldPkg"
+
+p1 = pmpkg("foopkg")
+self.addpkg2db("local", p1)
+
+self.option["HoldPkg"] = ["???pkg"]
+
+self.args = "-R %s" % p1.name
+
+self.addrule("PACMAN_RETCODE=1")
+self.addrule("PKG_EXIST=foopkg")
diff --git a/test/pacman/tests/sync139.py b/test/pacman/tests/sync139.py
new file mode 100644
index 00000000..0b0526d8
--- /dev/null
+++ b/test/pacman/tests/sync139.py
@@ -0,0 +1,23 @@
+self.description = "Sysupgrade of packages in fnmatch'd IgnoreGroup"
+
+sp1 = pmpkg("pkg1", "1.0-2")
+sp1.groups = ["grp"]
+sp2 = pmpkg("pkg2", "1.0-2")
+sp2.groups = ["grp2"]
+
+for p in sp1, sp2:
+ self.addpkg2db("sync", p)
+
+lp1 = pmpkg("pkg1", "1.0-1")
+lp2 = pmpkg("pkg2", "1.0-1")
+
+for p in lp1, lp2:
+ self.addpkg2db("local", p)
+
+self.option["IgnoreGroup"] = ["grp"]
+
+self.args = "-Su"
+
+self.addrule("PACMAN_RETCODE=0")
+self.addrule("PKG_VERSION=pkg1|1.0-1")
+self.addrule("PKG_VERSION=pkg2|1.0-2")
diff --git a/test/pacman/tests/sync502.py b/test/pacman/tests/sync502.py
new file mode 100644
index 00000000..5cc42c9f
--- /dev/null
+++ b/test/pacman/tests/sync502.py
@@ -0,0 +1,17 @@
+self.description = "Install a package from a sync db with fnmatch'ed NoExtract"
+
+sp = pmpkg("dummy")
+sp.files = ["bin/dummy",
+ "usr/share/man/man8",
+ "usr/share/man/man1/dummy.1"]
+self.addpkg2db("sync", sp)
+
+self.option["NoExtract"] = ["usr/share/man/*"]
+
+self.args = "-S %s" % sp.name
+
+self.addrule("PACMAN_RETCODE=0")
+self.addrule("PKG_EXIST=dummy")
+self.addrule("FILE_EXIST=bin/dummy")
+self.addrule("!FILE_EXIST=usr/share/man/man8")
+self.addrule("!FILE_EXIST=usr/share/man/man1/dummy.1")
diff --git a/test/pacman/tests/sync503.py b/test/pacman/tests/sync503.py
new file mode 100644
index 00000000..9d24f00d
--- /dev/null
+++ b/test/pacman/tests/sync503.py
@@ -0,0 +1,18 @@
+self.description = "Upgrade a package, with a fnmatch in NoUpgrade"
+
+sp = pmpkg("dummy", "1.0-2")
+sp.files = ["etc/dummy.conf"]
+self.addpkg2db("sync", sp)
+
+lp = pmpkg("dummy")
+lp.files = ["etc/dummy.conf"]
+self.addpkg2db("local", lp)
+
+self.option["NoUpgrade"] = ["etc/dummy.*"]
+
+self.args = "-S %s" % sp.name
+
+self.addrule("PKG_VERSION=dummy|1.0-2")
+self.addrule("!FILE_MODIFIED=etc/dummy.conf")
+self.addrule("FILE_PACNEW=etc/dummy.conf")
+self.addrule("!FILE_PACSAVE=etc/dummy.conf")
diff --git a/test/pacman/tests/upgrade012.py b/test/pacman/tests/upgrade012.py
index dba8dc18..4d9f0cd1 100644
--- a/test/pacman/tests/upgrade012.py
+++ b/test/pacman/tests/upgrade012.py
@@ -6,7 +6,7 @@ self.addpkg(p)
self.filesystem = ["bin/dummy"]
-self.args = "-Uf %s" % p.filename()
+self.args = "-U --force %s" % p.filename()
self.addrule("PACMAN_RETCODE=0")
self.addrule("PKG_EXIST=dummy")
diff --git a/test/pacman/tests/upgrade014.py b/test/pacman/tests/upgrade014.py
index 1632dd36..93c2fe2b 100644
--- a/test/pacman/tests/upgrade014.py
+++ b/test/pacman/tests/upgrade014.py
@@ -13,7 +13,7 @@ p2.files = ["bin/foobar",
for p in p1, p2:
self.addpkg(p)
-self.args = "-Uf %s" % " ".join([p.filename() for p in p1, p2])
+self.args = "-U --force %s" % " ".join([p.filename() for p in p1, p2])
self.addrule("PACMAN_RETCODE=0")
for p in p1, p2:
diff --git a/test/pacman/tests/upgrade015.py b/test/pacman/tests/upgrade015.py
index 22f7c36b..ea6046cb 100644
--- a/test/pacman/tests/upgrade015.py
+++ b/test/pacman/tests/upgrade015.py
@@ -6,7 +6,7 @@ self.addpkg(p)
self.filesystem = ["etc/dummy.conf"]
-self.args = "-Uf %s" % p.filename()
+self.args = "-U --force %s" % p.filename()
self.addrule("PACMAN_RETCODE=0")
self.addrule("PKG_EXIST=dummy")
diff --git a/test/pacman/tests/upgrade016.py b/test/pacman/tests/upgrade016.py
index dd31c9ab..b6b3f3ae 100644
--- a/test/pacman/tests/upgrade016.py
+++ b/test/pacman/tests/upgrade016.py
@@ -7,7 +7,7 @@ self.addpkg(p)
self.filesystem = ["etc/dummy.conf"]
-self.args = "-Uf %s" % p.filename()
+self.args = "-U --force %s" % p.filename()
self.addrule("PACMAN_RETCODE=0")
self.addrule("PKG_EXIST=dummy")
diff --git a/test/pacman/tests/upgrade046.py b/test/pacman/tests/upgrade046.py
index 12390647..a02a7132 100644
--- a/test/pacman/tests/upgrade046.py
+++ b/test/pacman/tests/upgrade046.py
@@ -20,7 +20,7 @@ p2.files = ["bin/foobar"]
for p in p1, p2:
self.addpkg(p)
-self.args = "-Uf %s" % " ".join([p.filename() for p in p1, p2])
+self.args = "-U --force %s" % " ".join([p.filename() for p in p1, p2])
self.addrule("PACMAN_RETCODE=0")
for p in p1, p2: