summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README1
-rw-r--r--doc/Makefile.am4
-rw-r--r--doc/PKGBUILD.5.txt2
-rw-r--r--doc/pacman.8.txt9
-rw-r--r--doc/pacman.conf.5.txt17
-rw-r--r--etc/makepkg.conf.in2
-rw-r--r--etc/pacman.conf.in5
-rw-r--r--lib/libalpm/add.c216
-rw-r--r--lib/libalpm/add.h4
-rw-r--r--lib/libalpm/alpm.h29
-rw-r--r--lib/libalpm/be_files.c3
-rw-r--r--lib/libalpm/conflict.c26
-rw-r--r--lib/libalpm/conflict.h3
-rw-r--r--lib/libalpm/deps.c2
-rw-r--r--lib/libalpm/dload.c53
-rw-r--r--lib/libalpm/error.c2
-rw-r--r--lib/libalpm/handle.c12
-rw-r--r--lib/libalpm/handle.h2
-rw-r--r--lib/libalpm/package.c18
-rw-r--r--lib/libalpm/remove.c212
-rw-r--r--lib/libalpm/remove.h5
-rw-r--r--lib/libalpm/sync.c340
-rw-r--r--lib/libalpm/sync.h3
-rw-r--r--lib/libalpm/trans.c308
-rw-r--r--lib/libalpm/trans.h9
-rw-r--r--lib/libalpm/util.c45
-rw-r--r--lib/libalpm/util.h1
-rw-r--r--pactest/tests/depconflict110.py8
-rw-r--r--pactest/tests/ignore002.py2
-rw-r--r--pactest/tests/ignore003.py2
-rw-r--r--pactest/tests/ignore004.py2
-rw-r--r--pactest/tests/ignore005.py2
-rw-r--r--pactest/tests/provision020.py2
-rw-r--r--pactest/tests/provision022.py2
-rw-r--r--pactest/tests/sync042.py6
-rw-r--r--pactest/tests/sync043.py6
-rw-r--r--pactest/tests/sync044.py2
-rw-r--r--pactest/tests/sync1004.py2
-rw-r--r--pactest/tests/sync1008.py2
-rw-r--r--pactest/tests/sync150.py25
-rw-r--r--pactest/tests/sync300.py2
-rw-r--r--pactest/tests/sync890.py2
-rw-r--r--pactest/tests/sync892.py2
-rw-r--r--pactest/tests/sync893.py2
-rw-r--r--pactest/tests/sync895.py2
-rw-r--r--pactest/tests/sync896.py2
-rw-r--r--pactest/tests/sync897.py2
-rw-r--r--pactest/tests/sync899.py2
-rw-r--r--pactest/tests/sync900.py2
-rw-r--r--pactest/tests/sync901.py2
-rw-r--r--pactest/tests/sync992.py2
-rw-r--r--pactest/tests/sync999.py2
-rw-r--r--pactest/tests/upgrade051.py4
-rw-r--r--pactest/tests/upgrade080.py16
-rw-r--r--pactest/tests/upgrade081.py16
-rw-r--r--pactest/tests/upgrade082.py19
-rw-r--r--pactest/tests/upgrade083.py19
-rw-r--r--pactest/tests/upgrade084.py16
-rw-r--r--pactest/tests/upgrade090.py28
-rw-r--r--scripts/makepkg.sh.in149
-rw-r--r--scripts/rankmirrors.py.in2
-rw-r--r--src/pacman/callback.c26
-rw-r--r--src/pacman/conf.h2
-rw-r--r--src/pacman/pacman.c115
-rw-r--r--src/pacman/remove.c61
-rw-r--r--src/pacman/sync.c137
-rw-r--r--src/pacman/upgrade.c82
-rw-r--r--src/pacman/util.c165
-rw-r--r--src/pacman/util.h3
69 files changed, 1137 insertions, 1143 deletions
diff --git a/README b/README
index 48dc274f..b9eb399a 100644
--- a/README
+++ b/README
@@ -57,7 +57,6 @@ library is initialized.
* dbpath: The toplevel database directory (Default: /var/lib/pacman)
* logfile: The base path to pacman's log file (Default: /var/log/pacman.log)
* usesyslog: Log to syslog instead of `logfile` for file-base logging.
-* nopassiveftp: Do not use passive FTP commands for ftp connections.
The following options also have `alpm_option_{add,remove}_*` functions, as the
values are list structures.
diff --git a/doc/Makefile.am b/doc/Makefile.am
index 4703b63a..6261d926 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -84,12 +84,12 @@ ASCIIDOC_OPTS = \
-a pacman_version="$(REAL_PACKAGE_VERSION)" \
-a pacman_date="`date +%Y-%m-%d`" \
-a sysconfdir=$(sysconfdir)
+
A2X_OPTS = \
--no-xmllint \
-d manpage \
-f manpage \
- --xsltproc-opts='-param man.endnotes.list.enabled 0' \
- --xsltproc-opts='-param man.endnotes.are.numbered 0'
+ --xsltproc-opts='-param man.endnotes.list.enabled 0 -param man.endnotes.are.numbered 0'
# These rules are due to the includes and files of the asciidoc text
$(ASCIIDOC_MANS): asciidoc.conf footer.txt
diff --git a/doc/PKGBUILD.5.txt b/doc/PKGBUILD.5.txt
index 83cebcdb..e6f6edf5 100644
--- a/doc/PKGBUILD.5.txt
+++ b/doc/PKGBUILD.5.txt
@@ -145,7 +145,7 @@ name. The syntax is: `source=('filename::url')`.
base functionality, but may be necessary to make full use of the contents
of this package. optdepends are currently for informational purposes only
and are not utilized by pacman during dependency resolution. The format
- should be similar to the following:
+ for specifying optdepends is:
optdepends=('fakeroot: for makepkg usage as normal user')
diff --git a/doc/pacman.8.txt b/doc/pacman.8.txt
index b288a592..7f92ec71 100644
--- a/doc/pacman.8.txt
+++ b/doc/pacman.8.txt
@@ -82,7 +82,8 @@ to determine which packages need upgrading. This behavior operates as follows:
"bash>=3.2"`.
*-U, \--upgrade*::
- Upgrade or add package(s) to the system. Either a URL or file path can be
+ Upgrade or add package(s) to the system and install the required
+ dependencies from sync repos. Either a URL or file path can be
specified. This is a ``remove-then-add'' process. See <<HCF,Handling Config
Files>> for an explanation on how pacman takes care of config files.
@@ -166,6 +167,8 @@ Options
If an install scriptlet exists, do not execute it. Do not use this
unless you know what you are doing.
+*\--arch* <'arch'>::
+ Specify an alternate architecture.
Query Options[[QO]]
-------------------
@@ -330,7 +333,9 @@ linkman:pacman.conf[5].
necessary. Pass this option twice to enable package downgrade; in this
case pacman will select sync packages whose version does not match with
the local version. This can be useful when the user switches from a testing
- repo to a stable one.
+ repo to a stable one. Additional targets can also be specified manually, so
+ that '-Su foo' will do a system upgrade and install/upgrade the foo package in
+ the same operation.
*-w, \--downloadonly*::
Retrieve all packages from the server, but do not install/upgrade
diff --git a/doc/pacman.conf.5.txt b/doc/pacman.conf.5.txt
index a1c1f2a6..640e62bb 100644
--- a/doc/pacman.conf.5.txt
+++ b/doc/pacman.conf.5.txt
@@ -97,6 +97,14 @@ Options
Include another config file. This file can include repositories or
general configuration options.
+*Architecture =* auto | i686 | x86_64 | ...::
+ If set, pacman will only allow installation of packages of the given
+ architecture (e.g. 'i686', 'x86_64', etc). The special value 'auto' will
+ use the system architecture, provided by in ``uname -m''. If unset, no
+ architecture checks are made. *NOTE*: packages with the special
+ architecture 'any' can always be installed, as they are meant to be
+ architecture independent.
+
*XferCommand =* /path/to/command %u::
If set, an external program will be used to download all remote files.
All instances of `%u` will be replaced with the download URL. If present,
@@ -108,9 +116,6 @@ Options
http/ftp support, or need the more advanced proxy support that comes with
utilities like wget.
-*NoPassiveFtp*::
- Disables passive ftp connections when downloading packages. (aka Active Mode)
-
*NoUpgrade =* file ...::
All files listed with a `NoUpgrade` directive will never be touched during
a package install/upgrade, and the new files will be installed with a
@@ -176,10 +181,12 @@ Include = /etc/pacman.d/mirrorlist
During parsing, pacman will define the `$repo` variable to the name of the
current section. This is often utilized in files specified using the 'Include'
-directive so all repositories can use the same mirrorfile.
+directive so all repositories can use the same mirrorfile. pacman also defines
+the `$arch` variable to the value of `Architecture`, so the same mirrorfile can
+even be used for different architectures.
--------
-Server = ftp://ftp.archlinux.org/$repo/os/arch
+Server = ftp://ftp.archlinux.org/$repo/os/$arch
--------
The order of repositories in the configuration files matters; repositories
diff --git a/etc/makepkg.conf.in b/etc/makepkg.conf.in
index 1368ff1f..3a3a4154 100644
--- a/etc/makepkg.conf.in
+++ b/etc/makepkg.conf.in
@@ -26,7 +26,7 @@ DLAGENTS=('ftp::/usr/bin/wget -c --passive-ftp -t 3 --waitretry=3 -O %o %u'
CARCH="@CARCH@"
CHOST="@CHOST@"
-#-- Exclusive: will only run on @CARCHFLAGS@
+#-- Exclusive: will only run on @CARCH@
# -march (or -mcpu) builds exclusively for an architecture
# -mtune optimizes for an architecture, but builds for whole processor family
CFLAGS="@CARCHFLAGS@-mtune=generic -O2 -pipe"
diff --git a/etc/pacman.conf.in b/etc/pacman.conf.in
index 30bfc321..fc841b70 100644
--- a/etc/pacman.conf.in
+++ b/etc/pacman.conf.in
@@ -19,6 +19,7 @@ SyncFirst = pacman
#XferCommand = /usr/bin/wget --passive-ftp -c -O %o %u
#XferCommand = /usr/bin/curl %u > %o
#CleanMethod = KeepInstalled
+Architecture = auto
# Pacman won't upgrade packages listed in IgnorePkg and members of IgnoreGroup
#IgnorePkg =
@@ -28,7 +29,6 @@ SyncFirst = pacman
#NoExtract =
# Misc options (all disabled by default)
-#NoPassiveFtp
#UseSyslog
#ShowSize
#UseDelta
@@ -42,6 +42,7 @@ SyncFirst = pacman
# - repositories listed first will take precedence when packages
# have identical names, regardless of version number
# - URLs will have $repo replaced by the name of the current repo
+# - URLs will have $arch replaced by the name of the architecture
#
# Repository entries are of the format:
# [repo-name]
@@ -57,7 +58,7 @@ SyncFirst = pacman
# servers immediately after the header and they will be used before the
# default mirrors.
#[core]
-#Server = ftp://ftp.example.com/foobar/$repo/os/i686/
+#Server = ftp://ftp.example.com/foobar/$repo/os/$arch/
# The file referenced here should contain a list of 'Server = ' lines.
#Include = @sysconfdir@/pacman.d/mirrorlist
diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
index 1b228b2d..268ecd7d 100644
--- a/lib/libalpm/add.c
+++ b/lib/libalpm/add.c
@@ -50,21 +50,30 @@
#include "remove.h"
#include "handle.h"
-int _alpm_add_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name)
+/** Add a file target to the transaction.
+ * @param target the name of the file target to add
+ * @return 0 on success, -1 on error (pm_errno is set accordingly)
+ */
+int SYMEXPORT alpm_add_target(char *target)
{
pmpkg_t *pkg = NULL;
const char *pkgname, *pkgver;
alpm_list_t *i;
+ pmtrans_t *trans;
ALPM_LOG_FUNC;
+ /* Sanity checks */
+ ASSERT(target != NULL && strlen(target) != 0, RET_ERR(PM_ERR_WRONG_ARGS, -1));
+ ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ trans = handle->trans;
+ ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
+ ASSERT(trans->state == STATE_INITIALIZED, RET_ERR(PM_ERR_TRANS_NOT_INITIALIZED, -1));
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
- ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
- ASSERT(name != NULL && strlen(name) != 0, RET_ERR(PM_ERR_WRONG_ARGS, -1));
- _alpm_log(PM_LOG_DEBUG, "loading target '%s'\n", name);
+ _alpm_log(PM_LOG_DEBUG, "loading target '%s'\n", target);
- if(alpm_pkg_load(name, 1, &pkg) != 0) {
+ if(alpm_pkg_load(target, 1, &pkg) != 0) {
goto error;
}
pkgname = alpm_pkg_get_name(pkg);
@@ -72,17 +81,19 @@ int _alpm_add_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name)
/* check if an older version of said package is already in transaction
* packages. if so, replace it in the list */
- for(i = trans->packages; i; i = i->next) {
+ for(i = trans->add; i; i = i->next) {
pmpkg_t *transpkg = i->data;
if(strcmp(transpkg->name, pkgname) == 0) {
if(alpm_pkg_vercmp(transpkg->version, pkgver) < 0) {
- _alpm_log(PM_LOG_WARNING, _("replacing older version %s-%s by %s in target list\n"),
- transpkg->name, transpkg->version, pkgver);
+ _alpm_log(PM_LOG_WARNING,
+ _("replacing older version %s-%s by %s in target list\n"),
+ transpkg->name, transpkg->version, pkgver);
_alpm_pkg_free(i->data);
i->data = pkg;
} else {
- _alpm_log(PM_LOG_WARNING, _("skipping %s-%s because newer version %s is in the target list\n"),
- pkgname, pkgver, transpkg->version);
+ _alpm_log(PM_LOG_WARNING,
+ _("skipping %s-%s because newer version %s is in the target list\n"),
+ pkgname, pkgver, transpkg->version);
_alpm_pkg_free(pkg);
}
return(0);
@@ -90,7 +101,7 @@ int _alpm_add_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name)
}
/* add the package to the transaction */
- trans->packages = alpm_list_add(trans->packages, pkg);
+ trans->add = alpm_list_add(trans->add, pkg);
return(0);
@@ -99,176 +110,6 @@ error:
return(-1);
}
-int _alpm_add_prepare(pmtrans_t *trans, pmdb_t *db, alpm_list_t **data)
-{
- alpm_list_t *lp = NULL;
-
- ALPM_LOG_FUNC;
-
- ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
- ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
-
- /* Check dependencies
- */
- if(!(trans->flags & PM_TRANS_FLAG_NODEPS)) {
- EVENT(trans, PM_TRANS_EVT_CHECKDEPS_START, NULL, NULL);
-
- /* look for unsatisfied dependencies */
- _alpm_log(PM_LOG_DEBUG, "looking for unsatisfied dependencies\n");
- lp = alpm_checkdeps(_alpm_db_get_pkgcache(db), 1, NULL, trans->packages);
- if(lp != NULL) {
- if(data) {
- *data = lp;
- } else {
- alpm_list_free_inner(lp, (alpm_list_fn_free)_alpm_depmiss_free);
- alpm_list_free(lp);
- }
- RET_ERR(PM_ERR_UNSATISFIED_DEPS, -1);
- }
-
- /* no unsatisfied deps, so look for conflicts */
- _alpm_log(PM_LOG_DEBUG, "looking for conflicts\n");
- alpm_list_t *inner = _alpm_innerconflicts(trans->packages);
- alpm_list_t *outer = _alpm_outerconflicts(db, trans->packages);
- lp = alpm_list_join(inner, outer);
-
- /* TODO : factorize the conflict resolving code from sync.c to use it here (FS#3492) */
-
- if(lp != NULL) {
- if(data) {
- *data = lp;
- } else {
- alpm_list_free_inner(lp, (alpm_list_fn_free)_alpm_conflict_free);
- alpm_list_free(lp);
- }
- if(inner) {
- _alpm_log(PM_LOG_ERROR, _("conflicting packages were found in the target list\n"));
- _alpm_log(PM_LOG_ERROR, _("you cannot install two conflicting packages at the same time\n"));
- }
- if(outer) {
- _alpm_log(PM_LOG_ERROR, _("replacing packages with -U is not supported yet\n"));
- _alpm_log(PM_LOG_ERROR, _("you can replace packages manually using -Rd and -U\n"));
- }
- RET_ERR(PM_ERR_CONFLICTING_DEPS, -1);
- }
-
- /* re-order w.r.t. dependencies */
- _alpm_log(PM_LOG_DEBUG, "sorting by dependencies\n");
- lp = _alpm_sortbydeps(trans->packages, 0);
- /* free the old alltargs */
- alpm_list_free(trans->packages);
- trans->packages = lp;
-
- EVENT(trans, PM_TRANS_EVT_CHECKDEPS_DONE, NULL, NULL);
- }
-
- /* Check for file conflicts */
- if(!(trans->flags & PM_TRANS_FLAG_FORCE)) {
- EVENT(trans, PM_TRANS_EVT_FILECONFLICTS_START, NULL, NULL);
-
- _alpm_log(PM_LOG_DEBUG, "looking for file conflicts\n");
- lp = _alpm_db_find_fileconflicts(db, trans, trans->packages, NULL);
- if(lp != NULL) {
- if(data) {
- *data = lp;
- } else {
- alpm_list_free_inner(lp, (alpm_list_fn_free)_alpm_fileconflict_free);
- alpm_list_free(lp);
- }
- RET_ERR(PM_ERR_FILE_CONFLICTS, -1);
- }
-
- EVENT(trans, PM_TRANS_EVT_FILECONFLICTS_DONE, NULL, NULL);
- }
-
- return(0);
-}
-
-static int upgrade_remove(pmpkg_t *oldpkg, pmpkg_t *newpkg, pmtrans_t *trans, pmdb_t *db) {
- /* this is kinda odd. If the old package exists, at this point we make a
- * NEW transaction, unrelated to handle->trans, and instantiate a "remove"
- * with the type PM_TRANS_TYPE_REMOVEUPGRADE. TODO: kill this weird
- * behavior. */
- pmtrans_t *tr = _alpm_trans_new();
-
- ALPM_LOG_FUNC;
-
- _alpm_log(PM_LOG_DEBUG, "removing old package first (%s-%s)\n",
- oldpkg->name, oldpkg->version);
-
- if(!tr) {
- RET_ERR(PM_ERR_TRANS_ABORT, -1);
- }
-
- if(_alpm_trans_init(tr, PM_TRANS_TYPE_REMOVEUPGRADE, trans->flags,
- NULL, NULL, NULL) == -1) {
- _alpm_trans_free(tr);
- tr = NULL;
- RET_ERR(PM_ERR_TRANS_ABORT, -1);
- }
-
- if(_alpm_remove_loadtarget(tr, db, newpkg->name) == -1) {
- _alpm_trans_free(tr);
- tr = NULL;
- RET_ERR(PM_ERR_TRANS_ABORT, -1);
- }
-
- /* copy the remove skiplist over */
- tr->skip_remove = alpm_list_strdup(trans->skip_remove);
- const alpm_list_t *b;
-
- /* Add files in the NEW backup array to the NoUpgrade array
- * so this removal operation doesn't kill them */
- alpm_list_t *old_noupgrade = alpm_list_strdup(handle->noupgrade);
- /* old package backup list */
- alpm_list_t *filelist = alpm_pkg_get_files(newpkg);
- for(b = alpm_pkg_get_backup(newpkg); b; b = b->next) {
- char *backup = _alpm_backup_file(b->data);
- /* safety check (fix the upgrade026 pactest) */
- if(!alpm_list_find_str(filelist, backup)) {
- FREE(backup);
- continue;
- }
- _alpm_log(PM_LOG_DEBUG, "adding %s to the NoUpgrade array temporarily\n",
- backup);
- handle->noupgrade = alpm_list_add(handle->noupgrade,
- backup);
- }
-
- /* TODO: we could also add files in the OLD backup array, but this would
- * change the backup handling behavior, and break several pactests, and we
- * can't do this just before 3.1 release.
- * The unlink_file function in remove.c would also need to be reviewed. */
-#if 0
- /* new package backup list */
- for(b = alpm_pkg_get_backup(oldpkg); b; b = b->next) {
- char *backup = _alpm_backup_file(b->data);
- /* make sure we don't add duplicate entries */
- if(!alpm_list_find_ptr(handle->noupgrade, backup)) {
- _alpm_log(PM_LOG_DEBUG, "adding %s to the NoUpgrade array temporarily\n",
- backup);
- handle->noupgrade = alpm_list_add(handle->noupgrade,
- backup);
- }
- }
-#endif
-
- int ret = _alpm_remove_commit(tr, db);
-
- _alpm_trans_free(tr);
- tr = NULL;
-
- /* restore our "NoUpgrade" list to previous state */
- FREELIST(handle->noupgrade);
- handle->noupgrade = old_noupgrade;
-
- if(ret == -1) {
- RET_ERR(PM_ERR_TRANS_ABORT, -1);
- }
-
- return(0);
-}
-
static int extract_single_file(struct archive *archive,
struct archive_entry *entry, pmpkg_t *newpkg, pmpkg_t *oldpkg,
pmtrans_t *trans, pmdb_t *db)
@@ -691,8 +532,9 @@ static int commit_single_pkg(pmpkg_t *newpkg, int pkg_current, int pkg_count,
if(oldpkg) {
/* set up fake remove transaction */
- int ret = upgrade_remove(oldpkg, newpkg, trans, db);
- if(ret != 0) {
+ if(_alpm_upgraderemove_package(oldpkg, newpkg, trans) == -1) {
+ pm_errno = PM_ERR_TRANS_ABORT;
+ ret = -1;
goto cleanup;
}
}
@@ -858,7 +700,7 @@ cleanup:
return(ret);
}
-int _alpm_add_commit(pmtrans_t *trans, pmdb_t *db)
+int _alpm_upgrade_packages(pmtrans_t *trans, pmdb_t *db)
{
int pkg_count, pkg_current;
alpm_list_t *targ;
@@ -868,15 +710,15 @@ int _alpm_add_commit(pmtrans_t *trans, pmdb_t *db)
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
- if(trans->packages == NULL) {
+ if(trans->add == NULL) {
return(0);
}
- pkg_count = alpm_list_count(trans->packages);
+ pkg_count = alpm_list_count(trans->add);
pkg_current = 1;
/* loop through our package list adding/upgrading one at a time */
- for(targ = trans->packages; targ; targ = targ->next) {
+ for(targ = trans->add; targ; targ = targ->next) {
if(handle->trans->state == STATE_INTERRUPTED) {
return(0);
}
diff --git a/lib/libalpm/add.h b/lib/libalpm/add.h
index 6983de9e..b0467507 100644
--- a/lib/libalpm/add.h
+++ b/lib/libalpm/add.h
@@ -24,9 +24,7 @@
#include "alpm_list.h"
#include "trans.h"
-int _alpm_add_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name);
-int _alpm_add_prepare(pmtrans_t *trans, pmdb_t *db, alpm_list_t **data);
-int _alpm_add_commit(pmtrans_t *trans, pmdb_t *db);
+int _alpm_upgrade_packages(pmtrans_t *trans, pmdb_t *db);
#endif /* _ALPM_ADD_H */
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index ce8c6919..e9fadca2 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -151,8 +151,9 @@ void alpm_option_add_ignoregrp(const char *grp);
void alpm_option_set_ignoregrps(alpm_list_t *ignoregrps);
int alpm_option_remove_ignoregrp(const char *grp);
-unsigned short alpm_option_get_nopassiveftp();
-void alpm_option_set_nopassiveftp(unsigned short nopasv);
+const char *alpm_option_get_arch();
+void alpm_option_set_arch(const char *arch);
+
void alpm_option_set_usedelta(unsigned short usedelta);
pmdb_t *alpm_option_get_localdb();
@@ -224,7 +225,6 @@ alpm_list_t *alpm_pkg_get_deltas(pmpkg_t *pkg);
alpm_list_t *alpm_pkg_get_replaces(pmpkg_t *pkg);
alpm_list_t *alpm_pkg_get_files(pmpkg_t *pkg);
alpm_list_t *alpm_pkg_get_backup(pmpkg_t *pkg);
-alpm_list_t *alpm_pkg_get_removes(pmpkg_t *pkg);
pmdb_t *alpm_pkg_get_db(pmpkg_t *pkg);
void *alpm_pkg_changelog_open(pmpkg_t *pkg);
size_t alpm_pkg_changelog_read(void *ptr, size_t size,
@@ -262,13 +262,6 @@ pmpkg_t *alpm_sync_newversion(pmpkg_t *pkg, alpm_list_t *dbs_sync);
* Transactions
*/
-/* Types */
-typedef enum _pmtranstype_t {
- PM_TRANS_TYPE_UPGRADE = 1,
- PM_TRANS_TYPE_REMOVE,
- PM_TRANS_TYPE_REMOVEUPGRADE,
- PM_TRANS_TYPE_SYNC
-} pmtranstype_t;
/* Flags */
typedef enum _pmtransflag_t {
@@ -402,19 +395,23 @@ typedef void (*alpm_trans_cb_conv)(pmtransconv_t, void *, void *,
/* Transaction Progress callback */
typedef void (*alpm_trans_cb_progress)(pmtransprog_t, const char *, int, int, int);
-pmtranstype_t alpm_trans_get_type();
unsigned int alpm_trans_get_flags();
-alpm_list_t * alpm_trans_get_pkgs();
-int alpm_trans_init(pmtranstype_t type, pmtransflag_t flags,
+alpm_list_t * alpm_trans_get_add();
+alpm_list_t * alpm_trans_get_remove();
+int alpm_trans_init(pmtransflag_t flags,
alpm_trans_cb_event cb_event, alpm_trans_cb_conv conv,
alpm_trans_cb_progress cb_progress);
-int alpm_trans_sysupgrade(int enable_downgrade);
-int alpm_trans_addtarget(char *target);
int alpm_trans_prepare(alpm_list_t **data);
int alpm_trans_commit(alpm_list_t **data);
int alpm_trans_interrupt(void);
int alpm_trans_release(void);
+int alpm_sync_sysupgrade(int enable_downgrade);
+int alpm_sync_target(char *target);
+int alpm_sync_dbtarget(char *db, char *target);
+int alpm_add_target(char *target);
+int alpm_remove_target(char *target);
+
/*
* Dependencies and conflicts
*/
@@ -441,6 +438,7 @@ alpm_list_t *alpm_checkconflicts(alpm_list_t *pkglist);
const char *alpm_conflict_get_package1(pmconflict_t *conflict);
const char *alpm_conflict_get_package2(pmconflict_t *conflict);
+const char *alpm_conflict_get_reason(pmconflict_t *conflict);
pmdepmod_t alpm_dep_get_mod(const pmdepend_t *dep);
const char *alpm_dep_get_name(const pmdepend_t *dep);
@@ -509,6 +507,7 @@ enum _pmerrno_t {
PM_ERR_PKG_OPEN,
PM_ERR_PKG_CANT_REMOVE,
PM_ERR_PKG_INVALID_NAME,
+ PM_ERR_PKG_INVALID_ARCH,
PM_ERR_PKG_REPO_NOT_FOUND,
/* Deltas */
PM_ERR_DLT_INVALID,
diff --git a/lib/libalpm/be_files.c b/lib/libalpm/be_files.c
index 9bb7b3dc..03a14637 100644
--- a/lib/libalpm/be_files.c
+++ b/lib/libalpm/be_files.c
@@ -148,7 +148,7 @@ static int checkdbdir(pmdb_t *db)
* pmdb_t *db;
* int result;
* db = alpm_list_getdata(alpm_option_get_syncdbs());
- * if(alpm_trans_init(PM_TRANS_TYPE_SYNC, 0, NULL, NULL, NULL) == 0) {
+ * if(alpm_trans_init(0, NULL, NULL, NULL) == 0) {
* result = alpm_db_update(0, db);
* alpm_trans_release();
*
@@ -191,7 +191,6 @@ int SYMEXPORT alpm_db_update(int force, pmdb_t *db)
*/
ASSERT(handle->trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
ASSERT(handle->trans->state == STATE_INITIALIZED, RET_ERR(PM_ERR_TRANS_NOT_INITIALIZED, -1));
- ASSERT(handle->trans->type == PM_TRANS_TYPE_SYNC, RET_ERR(PM_ERR_TRANS_TYPE, -1));
if(!alpm_list_find_ptr(handle->dbs_sync, db)) {
RET_ERR(PM_ERR_DB_NOT_FOUND, -1);
diff --git a/lib/libalpm/conflict.c b/lib/libalpm/conflict.c
index 07ef73cf..e934c01e 100644
--- a/lib/libalpm/conflict.c
+++ b/lib/libalpm/conflict.c
@@ -41,7 +41,7 @@
#include "cache.h"
#include "deps.h"
-pmconflict_t *_alpm_conflict_new(const char *package1, const char *package2)
+pmconflict_t *_alpm_conflict_new(const char *package1, const char *package2, const char *reason)
{
pmconflict_t *conflict;
@@ -51,6 +51,7 @@ pmconflict_t *_alpm_conflict_new(const char *package1, const char *package2)
STRDUP(conflict->package1, package1, RET_ERR(PM_ERR_MEMORY, NULL));
STRDUP(conflict->package2, package2, RET_ERR(PM_ERR_MEMORY, NULL));
+ STRDUP(conflict->reason, reason, RET_ERR(PM_ERR_MEMORY, NULL));
return(conflict);
}
@@ -59,6 +60,7 @@ void _alpm_conflict_free(pmconflict_t *conflict)
{
FREE(conflict->package2);
FREE(conflict->package1);
+ FREE(conflict->reason);
FREE(conflict);
}
@@ -69,6 +71,7 @@ pmconflict_t *_alpm_conflict_dup(const pmconflict_t *conflict)
STRDUP(newconflict->package1, conflict->package1, RET_ERR(PM_ERR_MEMORY, NULL));
STRDUP(newconflict->package2, conflict->package2, RET_ERR(PM_ERR_MEMORY, NULL));
+ STRDUP(newconflict->reason, conflict->reason, RET_ERR(PM_ERR_MEMORY, NULL));
return(newconflict);
}
@@ -122,9 +125,9 @@ static int does_conflict(pmpkg_t *pkg1, const char *conflict, pmpkg_t *pkg2)
* @param pkg2 package causing conflict
*/
static void add_conflict(alpm_list_t **baddeps, const char *pkg1,
- const char *pkg2)
+ const char *pkg2, const char *reason)
{
- pmconflict_t *conflict = _alpm_conflict_new(pkg1, pkg2);
+ pmconflict_t *conflict = _alpm_conflict_new(pkg1, pkg2, reason);
if(conflict && !_alpm_conflict_isin(conflict, *baddeps)) {
*baddeps = alpm_list_add(*baddeps, conflict);
} else {
@@ -168,9 +171,9 @@ static void check_conflict(alpm_list_t *list1, alpm_list_t *list2,
if(does_conflict(pkg1, conflict, pkg2)) {
if(order >= 0) {
- add_conflict(baddeps, pkg1name, pkg2name);
+ add_conflict(baddeps, pkg1name, pkg2name, conflict);
} else {
- add_conflict(baddeps, pkg2name, pkg1name);
+ add_conflict(baddeps, pkg2name, pkg1name, conflict);
}
}
}
@@ -513,7 +516,7 @@ alpm_list_t *_alpm_db_find_fileconflicts(pmdb_t *db, pmtrans_t *trans,
/* skip removal of file, but not add. this will prevent a second
* package from removing the file when it was already installed
* by its new owner (whether the file is in backup array or not */
- trans->skip_remove = alpm_list_add(trans->skip_remove, strdup(path));
+ trans->skip_remove = alpm_list_add(trans->skip_remove, strdup(filestr));
_alpm_log(PM_LOG_DEBUG, "file changed packages, adding to remove skiplist: %s\n", filestr);
resolved_conflict = 1;
}
@@ -578,6 +581,17 @@ const char SYMEXPORT *alpm_conflict_get_package2(pmconflict_t *conflict)
return conflict->package2;
}
+const char SYMEXPORT *alpm_conflict_get_reason(pmconflict_t *conflict)
+{
+ ALPM_LOG_FUNC;
+
+ /* Sanity checks */
+ ASSERT(handle != NULL, return(NULL));
+ ASSERT(conflict != NULL, return(NULL));
+
+ return conflict->reason;
+}
+
const char SYMEXPORT *alpm_fileconflict_get_target(pmfileconflict_t *conflict)
{
ALPM_LOG_FUNC;
diff --git a/lib/libalpm/conflict.h b/lib/libalpm/conflict.h
index 149c728e..73a6e959 100644
--- a/lib/libalpm/conflict.h
+++ b/lib/libalpm/conflict.h
@@ -27,6 +27,7 @@
struct __pmconflict_t {
char *package1;
char *package2;
+ char *reason;
};
struct __pmfileconflict_t {
@@ -36,7 +37,7 @@ struct __pmfileconflict_t {
char *ctarget;
};
-pmconflict_t *_alpm_conflict_new(const char *package1, const char *package2);
+pmconflict_t *_alpm_conflict_new(const char *package1, const char *package2, const char *reason);
pmconflict_t *_alpm_conflict_dup(const pmconflict_t *conflict);
void _alpm_conflict_free(pmconflict_t *conflict);
int _alpm_conflict_isin(pmconflict_t *needle, alpm_list_t *haystack);
diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c
index 02a4c7b6..46699ac6 100644
--- a/lib/libalpm/deps.c
+++ b/lib/libalpm/deps.c
@@ -605,7 +605,7 @@ int _alpm_resolvedeps(pmdb_t *local, alpm_list_t *dbs_sync, pmpkg_t *pkg,
ALPM_LOG_FUNC;
- if(local == NULL || dbs_sync == NULL) {
+ if(local == NULL) {
return(-1);
}
diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c
index 4695731a..f8fb09fe 100644
--- a/lib/libalpm/dload.c
+++ b/lib/libalpm/dload.c
@@ -76,30 +76,6 @@ static char *get_tempfile(const char *path, const char *filename) {
return(tempfile);
}
-/* Build a 'struct url' from an url. */
-static struct url *url_for_string(const char *url)
-{
- struct url *ret = NULL;
- ret = fetchParseURL(url);
- if(!ret) {
- _alpm_log(PM_LOG_ERROR, _("url '%s' is invalid\n"), url);
- RET_ERR(PM_ERR_SERVER_BAD_URL, NULL);
- }
-
- /* if no URL scheme specified, assume HTTP */
- if(strlen(ret->scheme) == 0) {
- _alpm_log(PM_LOG_WARNING, _("url scheme not specified, assuming HTTP\n"));
- strcpy(ret->scheme, SCHEME_HTTP);
- }
- /* add a user & password for anonymous FTP */
- if(strcmp(ret->scheme,SCHEME_FTP) == 0 && strlen(ret->user) == 0) {
- strcpy(ret->user, "anonymous");
- strcpy(ret->pwd, "libalpm@guest");
- }
-
- return(ret);
-}
-
static int download_internal(const char *url, const char *localpath,
time_t mtimeold, time_t *mtimenew) {
fetchIO *dlf = NULL;
@@ -110,17 +86,20 @@ static int download_internal(const char *url, const char *localpath,
size_t dl_thisfile = 0, nread = 0;
char *tempfile, *destfile, *filename;
struct sigaction new_action, old_action;
- struct url *fileurl = url_for_string(url);
+ struct url *fileurl;
char buffer[PM_DLBUF_LEN];
- if(!fileurl) {
- return(-1);
- }
-
filename = get_filename(url);
if(!filename) {
return(-1);
}
+
+ fileurl = fetchParseURL(url);
+ if(!fileurl) {
+ _alpm_log(PM_LOG_ERROR, _("url '%s' is invalid\n"), url);
+ RET_ERR(PM_ERR_SERVER_BAD_URL, -1);
+ }
+
destfile = get_destfile(localpath, filename);
tempfile = get_tempfile(localpath, filename);
@@ -161,7 +140,7 @@ static int download_internal(const char *url, const char *localpath,
sigaction(SIGPIPE, NULL, &old_action);
sigaction(SIGPIPE, &new_action, NULL);
- dlf = fetchXGet(fileurl, &ust, (handle->nopassiveftp ? "i" : "pi"));
+ dlf = fetchXGet(fileurl, &ust, "i");
if(fetchLastErrCode == FETCH_UNCHANGED) {
_alpm_log(PM_LOG_DEBUG, "mtimes are identical, skipping %s\n", filename);
@@ -214,14 +193,12 @@ static int download_internal(const char *url, const char *localpath,
while((nread = fetchIO_read(dlf, buffer, PM_DLBUF_LEN)) > 0) {
size_t nwritten = 0;
- while(nwritten < nread) {
- nwritten += fwrite(buffer, 1, (nread - nwritten), localf);
- if(ferror(localf)) {
- _alpm_log(PM_LOG_ERROR, _("error writing to file '%s': %s\n"),
- destfile, strerror(errno));
- ret = -1;
- goto cleanup;
- }
+ nwritten = fwrite(buffer, 1, nread, localf);
+ if((nwritten != nread) || ferror(localf)) {
+ _alpm_log(PM_LOG_ERROR, _("error writing to file '%s': %s\n"),
+ destfile, strerror(errno));
+ ret = -1;
+ goto cleanup;
}
dl_thisfile += nread;
diff --git a/lib/libalpm/error.c b/lib/libalpm/error.c
index 81aaa8b1..6ff1d675 100644
--- a/lib/libalpm/error.c
+++ b/lib/libalpm/error.c
@@ -117,6 +117,8 @@ const char SYMEXPORT *alpm_strerror(int err)
return _("cannot remove all files for package");
case PM_ERR_PKG_INVALID_NAME:
return _("package filename is not valid");
+ case PM_ERR_PKG_INVALID_ARCH:
+ return _("package architecture is not valid");
case PM_ERR_PKG_REPO_NOT_FOUND:
return _("no such repository");
/* Deltas */
diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c
index d1a35ad9..012d4121 100644
--- a/lib/libalpm/handle.c
+++ b/lib/libalpm/handle.c
@@ -79,6 +79,7 @@ void _alpm_handle_free(pmhandle_t *handle)
FREELIST(handle->cachedirs);
FREE(handle->logfile);
FREE(handle->lockfile);
+ FREE(handle->arch);
FREELIST(handle->dbs_sync);
FREELIST(handle->noupgrade);
FREELIST(handle->noextract);
@@ -213,13 +214,13 @@ alpm_list_t SYMEXPORT *alpm_option_get_ignoregrps()
return handle->ignoregrp;
}
-unsigned short SYMEXPORT alpm_option_get_nopassiveftp()
+const char SYMEXPORT *alpm_option_get_arch()
{
if (handle == NULL) {
pm_errno = PM_ERR_HANDLE_NULL;
- return -1;
+ return NULL;
}
- return handle->nopassiveftp;
+ return handle->arch;
}
pmdb_t SYMEXPORT *alpm_option_get_localdb()
@@ -529,9 +530,10 @@ int SYMEXPORT alpm_option_remove_ignoregrp(const char *grp)
return(0);
}
-void SYMEXPORT alpm_option_set_nopassiveftp(unsigned short nopasv)
+void SYMEXPORT alpm_option_set_arch(const char *arch)
{
- handle->nopassiveftp = nopasv;
+ if(handle->arch) FREE(handle->arch);
+ if(arch) handle->arch = strdup(arch);
}
void SYMEXPORT alpm_option_set_usedelta(unsigned short usedelta)
diff --git a/lib/libalpm/handle.h b/lib/libalpm/handle.h
index c7c262cf..a1eb1cde 100644
--- a/lib/libalpm/handle.h
+++ b/lib/libalpm/handle.h
@@ -58,7 +58,7 @@ typedef struct _pmhandle_t {
/* options */
unsigned short usesyslog; /* Use syslog instead of logfile? */ /* TODO move to frontend */
- unsigned short nopassiveftp; /* Don't use PASV ftp connections */
+ char *arch; /* Architecture of packages we should allow */
unsigned short usedelta; /* Download deltas if possible */
} pmhandle_t;
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index 002b1c89..de171661 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -423,13 +423,6 @@ alpm_list_t SYMEXPORT *alpm_pkg_get_backup(pmpkg_t *pkg)
return pkg->backup;
}
-alpm_list_t SYMEXPORT *alpm_pkg_get_removes(pmpkg_t *pkg)
-{
- ASSERT(pkg != NULL, return(NULL));
-
- return(pkg->removes);
-}
-
pmdb_t SYMEXPORT *alpm_pkg_get_db(pmpkg_t *pkg)
{
/* Sanity checks */
@@ -858,7 +851,11 @@ void _alpm_pkg_free(pmpkg_t *pkg)
FREE(pkg);
}
-/* Free transaction specific fields */
+/* This function should be used when removing a target from upgrade/sync target list
+ * Case 1: If pkg is a loaded package file (PKG_FROM_FILE), it will be freed.
+ * Case 2: If pkg is a pkgcache entry (PKG_FROM_CACHE), it won't be freed,
+ * only the transaction specific fields of pkg will be freed.
+ */
void _alpm_pkg_free_trans(pmpkg_t *pkg)
{
ALPM_LOG_FUNC;
@@ -867,6 +864,11 @@ void _alpm_pkg_free_trans(pmpkg_t *pkg)
return;
}
+ if(pkg->origin == PKG_FROM_FILE) {
+ _alpm_pkg_free(pkg);
+ return;
+ }
+
alpm_list_free(pkg->removes);
pkg->removes = NULL;
}
diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c
index aa6a5cc7..af2ce943 100644
--- a/lib/libalpm/remove.c
+++ b/lib/libalpm/remove.c
@@ -47,35 +47,45 @@
#include "handle.h"
#include "alpm.h"
-int _alpm_remove_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name)
+int SYMEXPORT alpm_remove_target(char *target)
{
pmpkg_t *info;
- const char *targ;
+ pmtrans_t *trans;
+ pmdb_t *db_local;
+ alpm_list_t *p;
ALPM_LOG_FUNC;
- ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
+ /* Sanity checks */
+ ASSERT(target != NULL && strlen(target) != 0, RET_ERR(PM_ERR_WRONG_ARGS, -1));
+ ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ trans = handle->trans;
+ db_local = handle->db_local;
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
- ASSERT(name != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
+ ASSERT(trans->state == STATE_INITIALIZED, RET_ERR(PM_ERR_TRANS_NOT_INITIALIZED, -1));
+ ASSERT(db_local != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
- targ = strchr(name, '/');
- if(targ && strncmp(name, "local", 5) == 0) {
- targ++;
- } else {
- targ = name;
- }
- if(_alpm_pkg_find(trans->packages, targ)) {
+ if(_alpm_pkg_find(trans->remove, target)) {
RET_ERR(PM_ERR_TRANS_DUP_TARGET, -1);
}
- if((info = _alpm_db_get_pkgfromcache(db, targ)) == NULL) {
- _alpm_log(PM_LOG_DEBUG, "could not find %s in database\n", targ);
- RET_ERR(PM_ERR_PKG_NOT_FOUND, -1);
+ if((info = _alpm_db_get_pkgfromcache(db_local, target)) != NULL) {
+ _alpm_log(PM_LOG_DEBUG, "adding %s in the targets list\n", info->name);
+ trans->remove = alpm_list_add(trans->remove, _alpm_pkg_dup(info));
+ return(0);
}
- _alpm_log(PM_LOG_DEBUG, "adding %s in the targets list\n", info->name);
- trans->packages = alpm_list_add(trans->packages, _alpm_pkg_dup(info));
+ _alpm_log(PM_LOG_DEBUG, "could not find %s in database\n", target);
+ pmgrp_t *grp = alpm_db_readgrp(db_local, target);
+ if(grp == NULL) {
+ RET_ERR(PM_ERR_PKG_NOT_FOUND, -1);
+ }
+ for(p = alpm_grp_get_pkgs(grp); p; p = alpm_list_next(p)) {
+ pmpkg_t *pkg = alpm_list_getdata(p);
+ _alpm_log(PM_LOG_DEBUG, "adding %s in the targets list\n", pkg->name);
+ trans->remove = alpm_list_add(trans->remove, _alpm_pkg_dup(pkg));
+ }
return(0);
}
@@ -91,10 +101,10 @@ static void remove_prepare_cascade(pmtrans_t *trans, pmdb_t *db,
pmdepmissing_t *miss = (pmdepmissing_t *)i->data;
pmpkg_t *info = _alpm_db_get_pkgfromcache(db, miss->target);
if(info) {
- if(!_alpm_pkg_find(trans->packages, alpm_pkg_get_name(info))) {
+ if(!_alpm_pkg_find(trans->remove, alpm_pkg_get_name(info))) {
_alpm_log(PM_LOG_DEBUG, "pulling %s in the targets list\n",
alpm_pkg_get_name(info));
- trans->packages = alpm_list_add(trans->packages, _alpm_pkg_dup(info));
+ trans->remove = alpm_list_add(trans->remove, _alpm_pkg_dup(info));
}
} else {
_alpm_log(PM_LOG_ERROR, _("could not find %s in database -- skipping\n"),
@@ -103,7 +113,7 @@ static void remove_prepare_cascade(pmtrans_t *trans, pmdb_t *db,
}
alpm_list_free_inner(lp, (alpm_list_fn_free)_alpm_depmiss_free);
alpm_list_free(lp);
- lp = alpm_checkdeps(_alpm_db_get_pkgcache(db), 1, trans->packages, NULL);
+ lp = alpm_checkdeps(_alpm_db_get_pkgcache(db), 1, trans->remove, NULL);
}
}
@@ -118,11 +128,11 @@ static void remove_prepare_keep_needed(pmtrans_t *trans, pmdb_t *db,
for(i = lp; i; i = i->next) {
pmdepmissing_t *miss = (pmdepmissing_t *)i->data;
void *vpkg;
- pmpkg_t *pkg = _alpm_pkg_find(trans->packages, miss->causingpkg);
+ pmpkg_t *pkg = _alpm_pkg_find(trans->remove, miss->causingpkg);
if(pkg == NULL) {
continue;
}
- trans->packages = alpm_list_remove(trans->packages, pkg, _alpm_pkg_cmp,
+ trans->remove = alpm_list_remove(trans->remove, pkg, _alpm_pkg_cmp,
&vpkg);
pkg = vpkg;
if(pkg) {
@@ -133,7 +143,7 @@ static void remove_prepare_keep_needed(pmtrans_t *trans, pmdb_t *db,
}
alpm_list_free_inner(lp, (alpm_list_fn_free)_alpm_depmiss_free);
alpm_list_free(lp);
- lp = alpm_checkdeps(_alpm_db_get_pkgcache(db), 1, trans->packages, NULL);
+ lp = alpm_checkdeps(_alpm_db_get_pkgcache(db), 1, trans->remove, NULL);
}
}
@@ -146,21 +156,16 @@ int _alpm_remove_prepare(pmtrans_t *trans, pmdb_t *db, alpm_list_t **data)
ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
- /* skip all checks if we are doing this removal as part of an upgrade */
- if(trans->type == PM_TRANS_TYPE_REMOVEUPGRADE) {
- return(0);
- }
-
if((trans->flags & PM_TRANS_FLAG_RECURSE) && !(trans->flags & PM_TRANS_FLAG_CASCADE)) {
_alpm_log(PM_LOG_DEBUG, "finding removable dependencies\n");
- _alpm_recursedeps(db, trans->packages, trans->flags & PM_TRANS_FLAG_RECURSEALL);
+ _alpm_recursedeps(db, trans->remove, trans->flags & PM_TRANS_FLAG_RECURSEALL);
}
if(!(trans->flags & PM_TRANS_FLAG_NODEPS)) {
EVENT(trans, PM_TRANS_EVT_CHECKDEPS_START, NULL, NULL);
_alpm_log(PM_LOG_DEBUG, "looking for unsatisfied dependencies\n");
- lp = alpm_checkdeps(_alpm_db_get_pkgcache(db), 1, trans->packages, NULL);
+ lp = alpm_checkdeps(_alpm_db_get_pkgcache(db), 1, trans->remove, NULL);
if(lp != NULL) {
if(trans->flags & PM_TRANS_FLAG_CASCADE) {
@@ -183,15 +188,15 @@ int _alpm_remove_prepare(pmtrans_t *trans, pmdb_t *db, alpm_list_t **data)
/* re-order w.r.t. dependencies */
_alpm_log(PM_LOG_DEBUG, "sorting by dependencies\n");
- lp = _alpm_sortbydeps(trans->packages, 1);
+ lp = _alpm_sortbydeps(trans->remove, 1);
/* free the old alltargs */
- alpm_list_free(trans->packages);
- trans->packages = lp;
+ alpm_list_free(trans->remove);
+ trans->remove = lp;
/* -Rcs == -Rc then -Rs */
if((trans->flags & PM_TRANS_FLAG_CASCADE) && (trans->flags & PM_TRANS_FLAG_RECURSE)) {
_alpm_log(PM_LOG_DEBUG, "finding removable dependencies\n");
- _alpm_recursedeps(db, trans->packages, trans->flags & PM_TRANS_FLAG_RECURSEALL);
+ _alpm_recursedeps(db, trans->remove, trans->flags & PM_TRANS_FLAG_RECURSEALL);
}
if(!(trans->flags & PM_TRANS_FLAG_NODEPS)) {
@@ -201,13 +206,13 @@ int _alpm_remove_prepare(pmtrans_t *trans, pmdb_t *db, alpm_list_t **data)
return(0);
}
-static int can_remove_file(pmtrans_t *trans, const char *path)
+static int can_remove_file(const char *path, alpm_list_t *skip)
{
char file[PATH_MAX+1];
snprintf(file, PATH_MAX, "%s%s", handle->root, path);
- if(alpm_list_find_str(trans->skip_remove, file)) {
+ if(alpm_list_find_str(skip, file)) {
/* return success because we will never actually remove this file */
return(1);
}
@@ -228,7 +233,7 @@ static int can_remove_file(pmtrans_t *trans, const char *path)
/* Helper function for iterating through a package's file and deleting them
* Used by _alpm_remove_commit. */
-static void unlink_file(pmpkg_t *info, char *filename, pmtrans_t *trans)
+static void unlink_file(pmpkg_t *info, char *filename, alpm_list_t *skip_remove, int nosave)
{
struct stat buf;
char file[PATH_MAX+1];
@@ -237,13 +242,13 @@ static void unlink_file(pmpkg_t *info, char *filename, pmtrans_t *trans)
snprintf(file, PATH_MAX, "%s%s", handle->root, filename);
- if(trans->type == PM_TRANS_TYPE_REMOVEUPGRADE) {
- /* check noupgrade */
- if(alpm_list_find_str(handle->noupgrade, filename)) {
- _alpm_log(PM_LOG_DEBUG, "Skipping removal of '%s' due to NoUpgrade\n",
- file);
- return;
- }
+ /* 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, filename)) {
+ _alpm_log(PM_LOG_DEBUG, "%s is in skip_remove, skipping removal\n",
+ file);
+ return;
}
/* we want to do a lstat here, and not a _alpm_lstat.
@@ -263,19 +268,10 @@ static void unlink_file(pmpkg_t *info, char *filename, pmtrans_t *trans)
_alpm_log(PM_LOG_DEBUG, "removing directory %s\n", file);
}
} else {
- /* 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(trans->skip_remove, file)) {
- _alpm_log(PM_LOG_DEBUG, "%s is in trans->skip_remove, skipping removal\n",
- file);
- return;
- }
-
/* if the file needs backup and has been modified, back it up to .pacsave */
char *pkghash = _alpm_needbackup(filename, alpm_pkg_get_backup(info));
if(pkghash) {
- if(trans->flags & PM_TRANS_FLAG_NOSAVE) {
+ if(nosave) {
_alpm_log(PM_LOG_DEBUG, "transaction is set to NOSAVE, not backing up '%s'\n", file);
FREE(pkghash);
} else {
@@ -303,7 +299,69 @@ static void unlink_file(pmpkg_t *info, char *filename, pmtrans_t *trans)
}
}
-int _alpm_remove_commit(pmtrans_t *trans, pmdb_t *db)
+int _alpm_upgraderemove_package(pmpkg_t *oldpkg, pmpkg_t *newpkg, pmtrans_t *trans)
+{
+ alpm_list_t *skip_remove, *b;
+ alpm_list_t *newfiles, *lp;
+ alpm_list_t *files = alpm_pkg_get_files(oldpkg);
+ const char *pkgname = alpm_pkg_get_name(oldpkg);
+
+ ALPM_LOG_FUNC;
+
+ _alpm_log(PM_LOG_DEBUG, "removing old package first (%s-%s)\n",
+ oldpkg->name, oldpkg->version);
+
+ /* copy the remove skiplist over */
+ skip_remove =
+ alpm_list_join(alpm_list_strdup(trans->skip_remove),alpm_list_strdup(handle->noupgrade));
+ /* Add files in the NEW backup array to the skip_remove array
+ * so this removal operation doesn't kill them */
+ /* old package backup list */
+ alpm_list_t *filelist = alpm_pkg_get_files(newpkg);
+ for(b = alpm_pkg_get_backup(newpkg); b; b = b->next) {
+ char *backup = _alpm_backup_file(b->data);
+ /* safety check (fix the upgrade026 pactest) */
+ if(!alpm_list_find_str(filelist, backup)) {
+ FREE(backup);
+ continue;
+ }
+ _alpm_log(PM_LOG_DEBUG, "adding %s to the skip_remove array\n", backup);
+ skip_remove = alpm_list_add(skip_remove, backup);
+ }
+
+ for(lp = files; lp; lp = lp->next) {
+ if(!can_remove_file(lp->data, skip_remove)) {
+ _alpm_log(PM_LOG_DEBUG, "not removing package '%s', can't remove all files\n",
+ pkgname);
+ RET_ERR(PM_ERR_PKG_CANT_REMOVE, -1);
+ }
+ }
+
+ /* iterate through the list backwards, unlinking files */
+ newfiles = alpm_list_reverse(files);
+ for(lp = newfiles; lp; lp = alpm_list_next(lp)) {
+ unlink_file(oldpkg, lp->data, skip_remove, 0);
+ }
+ alpm_list_free(newfiles);
+ FREELIST(skip_remove);
+
+ /* remove the package from the database */
+ _alpm_log(PM_LOG_DEBUG, "updating database\n");
+ _alpm_log(PM_LOG_DEBUG, "removing database entry '%s'\n", pkgname);
+ if(_alpm_db_remove(handle->db_local, oldpkg) == -1) {
+ _alpm_log(PM_LOG_ERROR, _("could not remove database entry %s-%s\n"),
+ pkgname, alpm_pkg_get_version(oldpkg));
+ }
+ /* remove the package from the cache */
+ if(_alpm_db_remove_pkgfromcache(handle->db_local, oldpkg) == -1) {
+ _alpm_log(PM_LOG_ERROR, _("could not remove entry '%s' from cache\n"),
+ pkgname);
+ }
+
+ return(0);
+}
+
+int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db)
{
pmpkg_t *info;
alpm_list_t *targ, *lp;
@@ -314,12 +372,11 @@ int _alpm_remove_commit(pmtrans_t *trans, pmdb_t *db)
ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
- pkg_count = alpm_list_count(trans->packages);
+ pkg_count = alpm_list_count(trans->remove);
- for(targ = trans->packages; targ; targ = targ->next) {
+ for(targ = trans->remove; targ; targ = targ->next) {
int position = 0;
char scriptlet[PATH_MAX];
- alpm_list_t *files;
info = (pmpkg_t*)targ->data;
const char *pkgname = NULL;
@@ -332,23 +389,21 @@ int _alpm_remove_commit(pmtrans_t *trans, pmdb_t *db)
snprintf(scriptlet, PATH_MAX, "%s%s-%s/install", db->path,
pkgname, alpm_pkg_get_version(info));
- if(trans->type != PM_TRANS_TYPE_REMOVEUPGRADE) {
- EVENT(trans, PM_TRANS_EVT_REMOVE_START, info, NULL);
- _alpm_log(PM_LOG_DEBUG, "removing package %s-%s\n",
- pkgname, alpm_pkg_get_version(info));
+ EVENT(trans, PM_TRANS_EVT_REMOVE_START, info, NULL);
+ _alpm_log(PM_LOG_DEBUG, "removing package %s-%s\n",
+ pkgname, alpm_pkg_get_version(info));
- /* run the pre-remove scriptlet if it exists */
- if(alpm_pkg_has_scriptlet(info) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
- _alpm_runscriptlet(handle->root, scriptlet, "pre_remove",
- alpm_pkg_get_version(info), NULL, trans);
- }
+ /* run the pre-remove scriptlet if it exists */
+ if(alpm_pkg_has_scriptlet(info) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
+ _alpm_runscriptlet(handle->root, scriptlet, "pre_remove",
+ alpm_pkg_get_version(info), NULL, trans);
}
- files = alpm_pkg_get_files(info);
if(!(trans->flags & PM_TRANS_FLAG_DBONLY)) {
+ alpm_list_t *files = alpm_pkg_get_files(info);
for(lp = files; lp; lp = lp->next) {
- if(!can_remove_file(trans, lp->data)) {
+ if(!can_remove_file(lp->data, NULL)) {
_alpm_log(PM_LOG_DEBUG, "not removing package '%s', can't remove all files\n",
pkgname);
RET_ERR(PM_ERR_PKG_CANT_REMOVE, -1);
@@ -363,7 +418,7 @@ int _alpm_remove_commit(pmtrans_t *trans, pmdb_t *db)
/* iterate through the list backwards, unlinking files */
newfiles = alpm_list_reverse(files);
for(lp = newfiles; lp; lp = alpm_list_next(lp)) {
- unlink_file(info, lp->data, trans);
+ unlink_file(info, lp->data, NULL, trans->flags & PM_TRANS_FLAG_NOSAVE);
/* update progress bar after each file */
percent = (double)position / (double)filenum;
@@ -379,12 +434,10 @@ int _alpm_remove_commit(pmtrans_t *trans, pmdb_t *db)
PROGRESS(trans, PM_TRANS_PROGRESS_REMOVE_START, pkgname, 100,
pkg_count, (pkg_count - alpm_list_count(targ) + 1));
- if(trans->type != PM_TRANS_TYPE_REMOVEUPGRADE) {
- /* run the post-remove script if it exists */
- if(alpm_pkg_has_scriptlet(info) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
- _alpm_runscriptlet(handle->root, scriptlet, "post_remove",
- alpm_pkg_get_version(info), NULL, trans);
- }
+ /* run the post-remove script if it exists */
+ if(alpm_pkg_has_scriptlet(info) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
+ _alpm_runscriptlet(handle->root, scriptlet, "post_remove",
+ alpm_pkg_get_version(info), NULL, trans);
}
/* remove the package from the database */
@@ -400,16 +453,11 @@ int _alpm_remove_commit(pmtrans_t *trans, pmdb_t *db)
pkgname);
}
- /* call a done event if this isn't an upgrade */
- if(trans->type != PM_TRANS_TYPE_REMOVEUPGRADE) {
- EVENT(trans, PM_TRANS_EVT_REMOVE_DONE, info, NULL);
- }
+ EVENT(trans, PM_TRANS_EVT_REMOVE_DONE, info, NULL);
}
/* run ldconfig if it exists */
- if(trans->type != PM_TRANS_TYPE_REMOVEUPGRADE) {
- _alpm_ldconfig(handle->root);
- }
+ _alpm_ldconfig(handle->root);
return(0);
}
diff --git a/lib/libalpm/remove.h b/lib/libalpm/remove.h
index 716fbf72..fbbaa169 100644
--- a/lib/libalpm/remove.h
+++ b/lib/libalpm/remove.h
@@ -24,9 +24,10 @@
#include "alpm_list.h"
#include "trans.h"
-int _alpm_remove_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name);
int _alpm_remove_prepare(pmtrans_t *trans, pmdb_t *db, alpm_list_t **data);
-int _alpm_remove_commit(pmtrans_t *trans, pmdb_t *db);
+int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db);
+
+int _alpm_upgraderemove_package(pmpkg_t *oldpkg, pmpkg_t *newpkg, pmtrans_t *trans);
#endif /* _ALPM_REMOVE_H */
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 47639248..28e63fd4 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -43,11 +43,13 @@
#include "deps.h"
#include "conflict.h"
#include "trans.h"
+#include "add.h"
#include "util.h"
#include "handle.h"
#include "alpm.h"
#include "dload.h"
#include "delta.h"
+#include "remove.h"
/** Check for new version of pkg in sync repos
* (only the first occurrence is considered in sync)
@@ -80,17 +82,30 @@ pmpkg_t SYMEXPORT *alpm_sync_newversion(pmpkg_t *pkg, alpm_list_t *dbs_sync)
return(NULL);
}
-int _alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync, int enable_downgrade)
+/** Search for packages to upgrade and add them to the transaction.
+ * @return 0 on success, -1 on error (pm_errno is set accordingly)
+ */
+int SYMEXPORT alpm_sync_sysupgrade(int enable_downgrade)
{
alpm_list_t *i, *j, *k;
+ pmtrans_t *trans;
+ pmdb_t *db_local;
+ alpm_list_t *dbs_sync;
ALPM_LOG_FUNC;
+ ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ trans = handle->trans;
+ db_local = handle->db_local;
+ dbs_sync = handle->dbs_sync;
+ ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
+ ASSERT(trans->state == STATE_INITIALIZED, RET_ERR(PM_ERR_TRANS_NOT_INITIALIZED, -1));
+
_alpm_log(PM_LOG_DEBUG, "checking for package upgrades\n");
for(i = _alpm_db_get_pkgcache(db_local); i; i = i->next) {
pmpkg_t *lpkg = i->data;
- if(_alpm_pkg_find(trans->packages, lpkg->name)) {
+ if(_alpm_pkg_find(trans->add, lpkg->name)) {
_alpm_log(PM_LOG_DEBUG, "%s is already in the target list -- skipping\n", lpkg->name);
continue;
}
@@ -113,7 +128,7 @@ int _alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_s
} else {
_alpm_log(PM_LOG_DEBUG, "adding package %s-%s to the transaction targets\n",
spkg->name, spkg->version);
- trans->packages = alpm_list_add(trans->packages, spkg);
+ trans->add = alpm_list_add(trans->add, spkg);
}
} else if(cmp < 0) {
if(enable_downgrade) {
@@ -124,7 +139,7 @@ int _alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_s
} else {
_alpm_log(PM_LOG_WARNING, _("%s: downgrading from version %s to version %s\n"),
lpkg->name, lpkg->version, spkg->version);
- trans->packages = alpm_list_add(trans->packages, spkg);
+ trans->add = alpm_list_add(trans->add, spkg);
}
} else {
_alpm_log(PM_LOG_WARNING, _("%s: local (%s) is newer than %s (%s)\n"),
@@ -152,7 +167,7 @@ int _alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_s
}
/* If spkg is already in the target list, we append lpkg to spkg's removes list */
- pmpkg_t *tpkg = _alpm_pkg_find(trans->packages, spkg->name);
+ pmpkg_t *tpkg = _alpm_pkg_find(trans->add, spkg->name);
if(tpkg) {
/* sanity check, multiple repos can contain spkg->name */
if(tpkg->origin_data.db != sdb) {
@@ -173,7 +188,7 @@ int _alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_s
spkg->removes = alpm_list_add(NULL, lpkg);
_alpm_log(PM_LOG_DEBUG, "adding package %s-%s to the transaction targets\n",
spkg->name, spkg->version);
- trans->packages = alpm_list_add(trans->packages, spkg);
+ trans->add = alpm_list_add(trans->add, spkg);
}
}
}
@@ -187,57 +202,18 @@ int _alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_s
return(0);
}
-int _alpm_sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync, char *name)
+int _alpm_sync_pkg(pmpkg_t *spkg)
{
- char *targline;
- char *targ;
- alpm_list_t *j;
- pmpkg_t *local, *spkg;
- pmdepend_t *dep; /* provisions and dependencies are also allowed */
+ pmtrans_t *trans;
+ pmdb_t *db_local;
+ pmpkg_t *local;
ALPM_LOG_FUNC;
- ASSERT(db_local != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
- ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
- ASSERT(name != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
-
- STRDUP(targline, name, RET_ERR(PM_ERR_MEMORY, -1));
- targ = strchr(targline, '/');
- if(targ) {
- /* we are looking for a package in a specific database */
- alpm_list_t *dbs = NULL;
- *targ = '\0';
- targ++;
- _alpm_log(PM_LOG_DEBUG, "searching for target '%s' in repo '%s'\n", targ, targline);
- for(j = dbs_sync; j; j = j->next) {
- pmdb_t *db = j->data;
- if(strcmp(db->treename, targline) == 0) {
- dbs = alpm_list_add(NULL, db);
- break;
- }
- }
- if(dbs == NULL) {
- _alpm_log(PM_LOG_ERROR, _("repository '%s' not found\n"), targline);
- FREE(targline);
- RET_ERR(PM_ERR_PKG_REPO_NOT_FOUND, -1);
- }
- dep = _alpm_splitdep(targ);
- spkg = _alpm_resolvedep(dep, dbs, NULL, 1);
- _alpm_dep_free(dep);
- alpm_list_free(dbs);
- } else {
- dep = _alpm_splitdep(targline);
- spkg = _alpm_resolvedep(dep, dbs_sync, NULL, 1);
- _alpm_dep_free(dep);
- }
- FREE(targline);
-
- if(spkg == NULL) {
- /* pm_errno is set by _alpm_resolvedep */
- return(-1);
- }
+ trans = handle->trans;
+ db_local = handle->db_local;
- if(_alpm_pkg_find(trans->packages, alpm_pkg_get_name(spkg))) {
+ if(_alpm_pkg_find(trans->add, alpm_pkg_get_name(spkg))) {
RET_ERR(PM_ERR_TRANS_DUP_TARGET, -1);
}
@@ -267,11 +243,109 @@ int _alpm_sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sy
spkg->reason = PM_PKG_REASON_EXPLICIT;
_alpm_log(PM_LOG_DEBUG, "adding package %s-%s to the transaction targets\n",
alpm_pkg_get_name(spkg), alpm_pkg_get_version(spkg));
- trans->packages = alpm_list_add(trans->packages, spkg);
+ trans->add = alpm_list_add(trans->add, spkg);
return(0);
}
+int _alpm_sync_target(alpm_list_t *dbs_sync, char *target)
+{
+ alpm_list_t *i, *j;
+ pmpkg_t *spkg;
+ pmdepend_t *dep; /* provisions and dependencies are also allowed */
+ pmgrp_t *grp;
+ int found = 0;
+
+ ALPM_LOG_FUNC;
+
+ /* Sanity checks */
+ ASSERT(target != NULL && strlen(target) != 0, RET_ERR(PM_ERR_WRONG_ARGS, -1));
+ ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+
+ dep = _alpm_splitdep(target);
+ spkg = _alpm_resolvedep(dep, dbs_sync, NULL, 1);
+ _alpm_dep_free(dep);
+
+ if(spkg != NULL) {
+ return(_alpm_sync_pkg(spkg));
+ }
+
+ _alpm_log(PM_LOG_DEBUG, "%s package not found, searching for group...\n", target);
+ for(i = dbs_sync; i; i = i->next) {
+ pmdb_t *db = i->data;
+ grp = alpm_db_readgrp(db, target);
+ if(grp) {
+ found = 1;
+ for(j = alpm_grp_get_pkgs(grp); j; j = j->next) {
+ pmpkg_t *pkg = j->data;
+ if(_alpm_sync_pkg(pkg) == -1) {
+ if(pm_errno == PM_ERR_TRANS_DUP_TARGET || pm_errno == PM_ERR_PKG_IGNORED) {
+ /* just skip duplicate or ignored targets */
+ continue;
+ } else {
+ return(-1);
+ }
+ }
+ }
+ }
+ }
+
+ if(!found) {
+ RET_ERR(PM_ERR_PKG_NOT_FOUND, -1);
+ }
+
+ return(0);
+}
+
+/** Add a sync target to the transaction.
+ * @param target the name of the sync target to add
+ * @return 0 on success, -1 on error (pm_errno is set accordingly)
+ */
+int SYMEXPORT alpm_sync_dbtarget(char *dbname, char *target)
+{
+ alpm_list_t *i;
+ alpm_list_t *dbs_sync;
+
+ ALPM_LOG_FUNC;
+
+ /* Sanity checks */
+ ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ dbs_sync = handle->dbs_sync;
+
+ /* we are looking for a package in a specific database */
+ alpm_list_t *dbs = NULL;
+ _alpm_log(PM_LOG_DEBUG, "searching for target '%s' in repo '%s'\n", target, dbname);
+ for(i = dbs_sync; i; i = i->next) {
+ pmdb_t *db = i->data;
+ if(strcmp(db->treename, dbname) == 0) {
+ dbs = alpm_list_add(NULL, db);
+ break;
+ }
+ }
+ if(dbs == NULL) {
+ _alpm_log(PM_LOG_ERROR, _("repository '%s' not found\n"), dbname);
+ RET_ERR(PM_ERR_PKG_REPO_NOT_FOUND, -1);
+ }
+ return(_alpm_sync_target(dbs, target));
+}
+
+/** Add a sync target to the transaction.
+ * @param target the name of the sync target to add
+ * @return 0 on success, -1 on error (pm_errno is set accordingly)
+ */
+int SYMEXPORT alpm_sync_target(char *target)
+{
+ alpm_list_t *dbs_sync;
+
+ ALPM_LOG_FUNC;
+
+ /* Sanity checks */
+ ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ dbs_sync = handle->dbs_sync;
+
+ return(_alpm_sync_target(dbs_sync,target));
+}
+
/** Compute the size of the files that will be downloaded to install a
* package.
* @param newpkg the new package to upgrade to
@@ -282,6 +356,11 @@ static int compute_download_size(pmpkg_t *newpkg)
char *fpath;
off_t size = 0;
+ if(newpkg->origin == PKG_FROM_FILE) {
+ newpkg->download_size = 0;
+ return(0);
+ }
+
fname = alpm_pkg_get_filename(newpkg);
ASSERT(fname != NULL, RET_ERR(PM_ERR_PKG_INVALID_NAME, -1));
fpath = _alpm_filecache_find(fname);
@@ -323,8 +402,8 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
alpm_list_t *deps = NULL;
alpm_list_t *preferred = NULL;
alpm_list_t *unresolvable = NULL;
- alpm_list_t *remove = NULL; /* allow checkdeps usage with trans->packages */
alpm_list_t *i, *j;
+ alpm_list_t *remove = NULL;
int ret = 0;
ALPM_LOG_FUNC;
@@ -345,7 +424,7 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
_alpm_log(PM_LOG_DEBUG, "resolving target's dependencies\n");
/* build remove list and preferred list for resolvedeps */
- for(i = trans->packages; i; i = i->next) {
+ for(i = trans->add; i; i = i->next) {
pmpkg_t *spkg = i->data;
for(j = spkg->removes; j; j = j->next) {
remove = alpm_list_add(remove, j->data);
@@ -355,7 +434,7 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
/* Resolve packages in the transaction one at a time, in addtion
building up a list of packages which could not be resolved. */
- for(i = trans->packages; i; i = i->next) {
+ for(i = trans->add; i; i = i->next) {
pmpkg_t *pkg = i->data;
if(_alpm_resolvedeps(db_local, dbs_sync, pkg, preferred,
&resolved, remove, data) == -1) {
@@ -392,21 +471,21 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
}
}
- /* Unresolvable packages will be removed from the target list, so
- we free the transaction specific fields */
- alpm_list_free_inner(unresolvable, (alpm_list_fn_free)_alpm_pkg_free_trans);
-
/* Set DEPEND reason for pulled packages */
for(i = resolved; i; i = i->next) {
pmpkg_t *pkg = i->data;
- if(!_alpm_pkg_find(trans->packages, pkg->name)) {
+ if(!_alpm_pkg_find(trans->add, pkg->name)) {
pkg->reason = PM_PKG_REASON_DEPEND;
}
}
+ /* Unresolvable packages will be removed from the target list, so
+ we free the transaction specific fields */
+ alpm_list_free_inner(unresolvable, (alpm_list_fn_free)_alpm_pkg_free_trans);
+
/* re-order w.r.t. dependencies */
- alpm_list_free(trans->packages);
- trans->packages = _alpm_sortbydeps(resolved, 0);
+ alpm_list_free(trans->add);
+ trans->add = _alpm_sortbydeps(resolved, 0);
alpm_list_free(resolved);
EVENT(trans, PM_TRANS_EVT_RESOLVEDEPS_DONE, NULL, NULL);
@@ -420,15 +499,15 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
/* 1. check for conflicts in the target list */
_alpm_log(PM_LOG_DEBUG, "check targets vs targets\n");
- deps = _alpm_innerconflicts(trans->packages);
+ deps = _alpm_innerconflicts(trans->add);
for(i = deps; i; i = i->next) {
pmconflict_t *conflict = i->data;
pmpkg_t *rsync, *sync, *sync1, *sync2;
/* have we already removed one of the conflicting targets? */
- sync1 = _alpm_pkg_find(trans->packages, conflict->package1);
- sync2 = _alpm_pkg_find(trans->packages, conflict->package2);
+ sync1 = _alpm_pkg_find(trans->add, conflict->package1);
+ sync2 = _alpm_pkg_find(trans->add, conflict->package2);
if(!sync1 || !sync2) {
continue;
}
@@ -468,8 +547,8 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
_alpm_log(PM_LOG_WARNING,
_("removing '%s' from target list because it conflicts with '%s'\n"),
rsync->name, sync->name);
+ trans->add = alpm_list_remove(trans->add, rsync, _alpm_pkg_cmp, NULL);
_alpm_pkg_free_trans(rsync); /* rsync is not transaction target anymore */
- trans->packages = alpm_list_remove(trans->packages, rsync, _alpm_pkg_cmp, NULL);
continue;
}
@@ -479,7 +558,7 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
/* 2. we check for target vs db conflicts (and resolve)*/
_alpm_log(PM_LOG_DEBUG, "check targets vs db and db vs targets\n");
- deps = _alpm_outerconflicts(db_local, trans->packages);
+ deps = _alpm_outerconflicts(db_local, trans->add);
for(i = deps; i; i = i->next) {
pmconflict_t *conflict = i->data;
@@ -487,7 +566,7 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
/* if conflict->package2 (the local package) is not elected for removal,
we ask the user */
int found = 0;
- for(j = trans->packages; j && !found; j = j->next) {
+ for(j = trans->add; j && !found; j = j->next) {
pmpkg_t *spkg = j->data;
if(_alpm_pkg_find(spkg->removes, conflict->package2)) {
found = 1;
@@ -500,11 +579,11 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
_alpm_log(PM_LOG_DEBUG, "package '%s' conflicts with '%s'\n",
conflict->package1, conflict->package2);
- pmpkg_t *sync = _alpm_pkg_find(trans->packages, conflict->package1);
+ pmpkg_t *sync = _alpm_pkg_find(trans->add, conflict->package1);
pmpkg_t *local = _alpm_db_get_pkgfromcache(db_local, conflict->package2);
int doremove = 0;
QUESTION(trans, PM_TRANS_CONV_CONFLICT_PKG, conflict->package1,
- conflict->package2, NULL, &doremove);
+ conflict->package2, conflict->reason, &doremove);
if(doremove) {
/* append to the removes list */
_alpm_log(PM_LOG_DEBUG, "electing '%s' for removal\n", conflict->package2);
@@ -532,16 +611,16 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
if(!(trans->flags & PM_TRANS_FLAG_NODEPS)) {
/* rebuild remove list */
alpm_list_free(remove);
- remove = NULL;
- for(i = trans->packages; i; i = i->next) {
+ trans->remove = NULL;
+ for(i = trans->add; i; i = i->next) {
pmpkg_t *spkg = i->data;
for(j = spkg->removes; j; j = j->next) {
- remove = alpm_list_add(remove, j->data);
+ trans->remove = alpm_list_add(trans->remove, _alpm_pkg_dup(j->data));
}
}
_alpm_log(PM_LOG_DEBUG, "checking dependencies\n");
- deps = alpm_checkdeps(_alpm_db_get_pkgcache(db_local), 1, remove, trans->packages);
+ deps = alpm_checkdeps(_alpm_db_get_pkgcache(db_local), 1, trans->remove, trans->add);
if(deps) {
pm_errno = PM_ERR_UNSATISFIED_DEPS;
ret = -1;
@@ -554,7 +633,7 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
goto cleanup;
}
}
- for(i = trans->packages; i; i = i->next) {
+ for(i = trans->add; i; i = i->next) {
/* update download size field */
pmpkg_t *spkg = i->data;
if(compute_download_size(spkg) != 0) {
@@ -564,7 +643,6 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
}
cleanup:
- alpm_list_free(remove);
alpm_list_free(unresolvable);
return(ret);
@@ -601,7 +679,7 @@ static int apply_deltas(pmtrans_t *trans)
int ret = 0;
const char *cachedir = _alpm_filecache_setup();
- for(i = trans->packages; i; i = i->next) {
+ for(i = trans->add; i; i = i->next) {
pmpkg_t *spkg = i->data;
alpm_list_t *delta_path = spkg->delta_path;
alpm_list_t *dlts = NULL;
@@ -711,7 +789,6 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
{
alpm_list_t *i, *j, *files = NULL;
alpm_list_t *deltas = NULL;
- pmtrans_t *tr_remove = NULL, *tr_upgrade = NULL;
int replaces = 0;
int errors = 0;
const char *cachedir = NULL;
@@ -730,7 +807,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
if(handle->totaldlcb) {
off_t total_size = (off_t)0;
/* sum up the download size for each package and store total */
- for(i = trans->packages; i; i = i->next) {
+ for(i = trans->add; i; i = i->next) {
pmpkg_t *spkg = i->data;
total_size += spkg->download_size;
}
@@ -741,11 +818,10 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
for(i = handle->dbs_sync; i; i = i->next) {
pmdb_t *current = i->data;
- for(j = trans->packages; j; j = j->next) {
+ for(j = trans->add; j; j = j->next) {
pmpkg_t *spkg = j->data;
- pmdb_t *dbs = spkg->origin_data.db;
- if(current == dbs) {
+ if(spkg->origin == PKG_FROM_CACHE && current == spkg->origin_data.db) {
const char *fname = NULL;
fname = alpm_pkg_get_filename(spkg);
@@ -835,15 +911,36 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
EVENT(trans, PM_TRANS_EVT_INTEGRITY_START, NULL, NULL);
errors = 0;
- for(i = trans->packages; i; i = i->next) {
+ for(i = trans->add; i; i = i->next) {
pmpkg_t *spkg = i->data;
+ if(spkg->origin == PKG_FROM_FILE) {
+ continue; /* pkg_load() has been already called, this package is valid */
+ }
+
const char *filename = alpm_pkg_get_filename(spkg);
const char *md5sum = alpm_pkg_get_md5sum(spkg);
if(test_md5sum(trans, filename, md5sum) != 0) {
errors++;
*data = alpm_list_add(*data, strdup(filename));
+ continue;
+ }
+ /* load the package file and replace pkgcache entry with it in the target list */
+ /* TODO: alpm_pkg_get_db() will not work on this target anymore */
+ _alpm_log(PM_LOG_DEBUG, "replacing pkgcache entry with package file for target %s\n", spkg->name);
+ char *filepath = _alpm_filecache_find(filename);
+ pmpkg_t *pkgfile;
+ if(alpm_pkg_load(filepath, 1, &pkgfile) != 0) {
+ _alpm_pkg_free(pkgfile);
+ errors++;
+ *data = alpm_list_add(*data, strdup(filename));
+ FREE(filepath);
+ continue;
}
+ FREE(filepath);
+ pkgfile->reason = spkg->reason; /* copy over install reason */
+ i->data = pkgfile;
+ _alpm_pkg_free_trans(spkg); /* spkg has been removed from the target list */
}
if(errors) {
pm_errno = PM_ERR_PKG_INVALID;
@@ -856,71 +953,15 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
trans->state = STATE_COMMITING;
- /* Create remove and upgrade transactions */
- tr_remove = _alpm_trans_new();
- if(tr_remove == NULL) {
- _alpm_log(PM_LOG_ERROR, _("could not create removal transaction\n"));
- goto error;
- }
- tr_upgrade = _alpm_trans_new();
- if(tr_upgrade == NULL) {
- _alpm_log(PM_LOG_ERROR, _("could not create transaction\n"));
- goto error;
- }
-
- if(_alpm_trans_init(tr_remove, PM_TRANS_TYPE_REMOVE, PM_TRANS_FLAG_NODEPS, NULL, NULL, NULL) == -1) {
- _alpm_log(PM_LOG_ERROR, _("could not initialize the removal transaction\n"));
- goto error;
- }
- if(_alpm_trans_init(tr_upgrade, PM_TRANS_TYPE_UPGRADE, trans->flags, trans->cb_event, trans->cb_conv, trans->cb_progress) == -1) {
- _alpm_log(PM_LOG_ERROR, _("could not initialize transaction\n"));
- goto error;
- }
-
- /* adding targets */
- for(i = trans->packages; i; i = i->next) {
- pmpkg_t *spkg = i->data;
- alpm_list_t *j;
- /* remove transaction */
- for(j = spkg->removes; j; j = j->next) {
- pmpkg_t *pkg = j->data;
- if(!_alpm_pkg_find(tr_remove->packages, pkg->name)) {
- if(_alpm_trans_addtarget(tr_remove, pkg->name) == -1) {
- goto error;
- }
- replaces++;
- }
- }
- /* upgrade transaction */
- const char *fname;
- char *fpath;
-
- fname = alpm_pkg_get_filename(spkg);
- if(fname == NULL) {
- goto error;
- }
- /* Loop through the cache dirs until we find a matching file */
- fpath = _alpm_filecache_find(fname);
-
- if(_alpm_trans_addtarget(tr_upgrade, fpath) == -1) {
- FREE(fpath);
- goto error;
- }
- FREE(fpath);
-
- /* using alpm_list_last() is ok because addtarget() adds the new target at the
- * end of the tr->packages list */
- pmpkg_t *ipkg = alpm_list_last(tr_upgrade->packages)->data;
- ipkg->reason = spkg->reason;
- }
+ replaces = alpm_list_count(trans->remove);
/* fileconflict check */
if(!(trans->flags & PM_TRANS_FLAG_FORCE)) {
EVENT(trans, PM_TRANS_EVT_FILECONFLICTS_START, NULL, NULL);
_alpm_log(PM_LOG_DEBUG, "looking for file conflicts\n");
- alpm_list_t *conflict = _alpm_db_find_fileconflicts(db_local, tr_upgrade,
- tr_upgrade->packages, tr_remove->packages);
+ alpm_list_t *conflict = _alpm_db_find_fileconflicts(db_local, trans,
+ trans->add, trans->remove);
if(conflict) {
pm_errno = PM_ERR_FILE_CONFLICTS;
if(data) {
@@ -938,14 +979,8 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
/* remove conflicting and to-be-replaced packages */
if(replaces) {
_alpm_log(PM_LOG_DEBUG, "removing conflicting and to-be-replaced packages\n");
- if(_alpm_trans_prepare(tr_remove, data) == -1) {
- _alpm_log(PM_LOG_ERROR, _("could not prepare removal transaction\n"));
- goto error;
- }
/* we want the frontend to be aware of commit details */
- tr_remove->cb_event = trans->cb_event;
- tr_remove->cb_progress = trans->cb_progress;
- if(_alpm_trans_commit(tr_remove, NULL) == -1) {
+ if(_alpm_remove_packages(trans, handle->db_local) == -1) {
_alpm_log(PM_LOG_ERROR, _("could not commit removal transaction\n"));
goto error;
}
@@ -953,8 +988,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
/* install targets */
_alpm_log(PM_LOG_DEBUG, "installing packages\n");
- /* add_prepare is not needed */
- if(_alpm_trans_commit(tr_upgrade, NULL) == -1) {
+ if(_alpm_upgrade_packages(trans, handle->db_local) == -1) {
_alpm_log(PM_LOG_ERROR, _("could not commit transaction\n"));
goto error;
}
@@ -963,8 +997,6 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
error:
FREELIST(files);
alpm_list_free(deltas);
- _alpm_trans_free(tr_remove);
- _alpm_trans_free(tr_upgrade);
return(ret);
}
diff --git a/lib/libalpm/sync.h b/lib/libalpm/sync.h
index c2905a45..b432b69e 100644
--- a/lib/libalpm/sync.h
+++ b/lib/libalpm/sync.h
@@ -24,9 +24,6 @@
#include "alpm.h"
-int _alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync, int enable_downgrade);
-
-int _alpm_sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync, char *name);
int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync, alpm_list_t **data);
int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data);
diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c
index 6e847e64..c99f5964 100644
--- a/lib/libalpm/trans.c
+++ b/lib/libalpm/trans.c
@@ -52,17 +52,18 @@
*/
/** Initialize the transaction.
- * @param type type of the transaction
* @param flags flags of the transaction (like nodeps, etc)
* @param event event callback function pointer
* @param conv question callback function pointer
* @param progress progress callback function pointer
* @return 0 on success, -1 on error (pm_errno is set accordingly)
*/
-int SYMEXPORT alpm_trans_init(pmtranstype_t type, pmtransflag_t flags,
+int SYMEXPORT alpm_trans_init(pmtransflag_t flags,
alpm_trans_cb_event event, alpm_trans_cb_conv conv,
alpm_trans_cb_progress progress)
{
+ pmtrans_t *trans;
+
ALPM_LOG_FUNC;
/* Sanity checks */
@@ -78,38 +79,53 @@ int SYMEXPORT alpm_trans_init(pmtranstype_t type, pmtransflag_t flags,
}
}
- handle->trans = _alpm_trans_new();
- if(handle->trans == NULL) {
+ trans = _alpm_trans_new();
+ if(trans == NULL) {
RET_ERR(PM_ERR_MEMORY, -1);
}
- return(_alpm_trans_init(handle->trans, type, flags, event, conv, progress));
-}
-
-/** Search for packages to upgrade and add them to the transaction.
- * @return 0 on success, -1 on error (pm_errno is set accordingly)
- */
-int SYMEXPORT alpm_trans_sysupgrade(int enable_downgrade)
-{
- pmtrans_t *trans;
+ trans->flags = flags;
+ trans->cb_event = event;
+ trans->cb_conv = conv;
+ trans->cb_progress = progress;
+ trans->state = STATE_INITIALIZED;
- ALPM_LOG_FUNC;
+ handle->trans = trans;
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
+ return(0);
+}
- trans = handle->trans;
- ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
- ASSERT(trans->state == STATE_INITIALIZED, RET_ERR(PM_ERR_TRANS_NOT_INITIALIZED, -1));
- ASSERT(trans->type == PM_TRANS_TYPE_SYNC, RET_ERR(PM_ERR_TRANS_TYPE, -1));
+static alpm_list_t *check_arch(alpm_list_t *pkgs)
+{
+ alpm_list_t *i;
+ alpm_list_t *invalid = NULL;
- return(_alpm_sync_sysupgrade(trans, handle->db_local, handle->dbs_sync, enable_downgrade));
+ const char *arch = alpm_option_get_arch();
+ if(!arch) {
+ return(NULL);
+ }
+ for(i = pkgs; i; i = i->next) {
+ pmpkg_t *pkg = i->data;
+ const char *pkgarch = alpm_pkg_get_arch(pkg);
+ if(strcmp(pkgarch,arch) && strcmp(pkgarch,"any")) {
+ char *string;
+ const char *pkgname = alpm_pkg_get_name(pkg);
+ const char *pkgver = alpm_pkg_get_version(pkg);
+ size_t len = strlen(pkgname) + strlen(pkgver) + strlen(pkgarch) + 3;
+ MALLOC(string, len, RET_ERR(PM_ERR_MEMORY, invalid));
+ sprintf(string, "%s-%s-%s", pkgname, pkgver, pkgarch);
+ invalid = alpm_list_add(invalid, string);
+ }
+ }
+ return(invalid);
}
-/** Add a target to the transaction.
- * @param target the name of the target to add
+/** Prepare a transaction.
+ * @param data the address of an alpm_list where detailed description
+ * of an error can be dumped (ie. list of conflicting files)
* @return 0 on success, -1 on error (pm_errno is set accordingly)
*/
-int SYMEXPORT alpm_trans_addtarget(char *target)
+int SYMEXPORT alpm_trans_prepare(alpm_list_t **data)
{
pmtrans_t *trans;
@@ -117,32 +133,41 @@ int SYMEXPORT alpm_trans_addtarget(char *target)
/* Sanity checks */
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
- ASSERT(target != NULL && strlen(target) != 0, RET_ERR(PM_ERR_WRONG_ARGS, -1));
+ ASSERT(data != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
trans = handle->trans;
+
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
ASSERT(trans->state == STATE_INITIALIZED, RET_ERR(PM_ERR_TRANS_NOT_INITIALIZED, -1));
- return(_alpm_trans_addtarget(trans, target));
-}
+ /* If there's nothing to do, return without complaining */
+ if(trans->add == NULL && trans->remove == NULL) {
+ return(0);
+ }
-/** Prepare a transaction.
- * @param data the address of an alpm_list where detailed description
- * of an error can be dumped (ie. list of conflicting files)
- * @return 0 on success, -1 on error (pm_errno is set accordingly)
- */
-int SYMEXPORT alpm_trans_prepare(alpm_list_t **data)
-{
- ALPM_LOG_FUNC;
+ alpm_list_t *invalid = check_arch(trans->add);
+ if(invalid) {
+ if(data) {
+ *data = invalid;
+ }
+ RET_ERR(PM_ERR_PKG_INVALID_ARCH, -1);
+ }
- /* Sanity checks */
- ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
- ASSERT(data != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
+ if(trans->add == NULL) {
+ if(_alpm_remove_prepare(trans, handle->db_local, data) == -1) {
+ /* pm_errno is set by _alpm_remove_prepare() */
+ return(-1);
+ }
+ } else {
+ if(_alpm_sync_prepare(trans, handle->db_local, handle->dbs_sync, data) == -1) {
+ /* pm_errno is set by _alpm_sync_prepare() */
+ return(-1);
+ }
+ }
- ASSERT(handle->trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
- ASSERT(handle->trans->state == STATE_INITIALIZED, RET_ERR(PM_ERR_TRANS_NOT_INITIALIZED, -1));
+ trans->state = STATE_PREPARED;
- return(_alpm_trans_prepare(handle->trans, data));
+ return(0);
}
/** Commit a transaction.
@@ -152,17 +177,42 @@ int SYMEXPORT alpm_trans_prepare(alpm_list_t **data)
*/
int SYMEXPORT alpm_trans_commit(alpm_list_t **data)
{
+ pmtrans_t *trans;
+
ALPM_LOG_FUNC;
/* Sanity checks */
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
- ASSERT(handle->trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
- ASSERT(handle->trans->state == STATE_PREPARED, RET_ERR(PM_ERR_TRANS_NOT_PREPARED, -1));
+ trans = handle->trans;
- ASSERT(!(handle->trans->flags & PM_TRANS_FLAG_NOLOCK), RET_ERR(PM_ERR_TRANS_NOT_LOCKED, -1));
+ ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
+ ASSERT(trans->state == STATE_PREPARED, RET_ERR(PM_ERR_TRANS_NOT_PREPARED, -1));
+
+ ASSERT(!(trans->flags & PM_TRANS_FLAG_NOLOCK), RET_ERR(PM_ERR_TRANS_NOT_LOCKED, -1));
+
+ /* If there's nothing to do, return without complaining */
+ if(trans->add == NULL && trans->remove == NULL) {
+ return(0);
+ }
+
+ trans->state = STATE_COMMITING;
+
+ if(trans->add == NULL) {
+ if(_alpm_remove_packages(trans, handle->db_local) == -1) {
+ /* pm_errno is set by _alpm_remove_commit() */
+ return(-1);
+ }
+ } else {
+ if(_alpm_sync_commit(trans, handle->db_local, data) == -1) {
+ /* pm_errno is set by _alpm_sync_commit() */
+ return(-1);
+ }
+ }
- return(_alpm_trans_commit(handle->trans, data));
+ trans->state = STATE_COMMITED;
+
+ return(0);
}
/** Interrupt a transaction.
@@ -247,12 +297,10 @@ void _alpm_trans_free(pmtrans_t *trans)
return;
}
- if(trans->type == PM_TRANS_TYPE_SYNC) {
- alpm_list_free_inner(trans->packages, (alpm_list_fn_free)_alpm_pkg_free_trans);
- } else {
- alpm_list_free_inner(trans->packages, (alpm_list_fn_free)_alpm_pkg_free);
- }
- alpm_list_free(trans->packages);
+ alpm_list_free_inner(trans->add, (alpm_list_fn_free)_alpm_pkg_free_trans);
+ alpm_list_free(trans->add);
+ alpm_list_free_inner(trans->remove, (alpm_list_fn_free)_alpm_pkg_free);
+ alpm_list_free(trans->remove);
FREELIST(trans->skip_add);
FREELIST(trans->skip_remove);
@@ -260,150 +308,6 @@ void _alpm_trans_free(pmtrans_t *trans)
FREE(trans);
}
-int _alpm_trans_init(pmtrans_t *trans, pmtranstype_t type, pmtransflag_t flags,
- alpm_trans_cb_event event, alpm_trans_cb_conv conv,
- alpm_trans_cb_progress progress)
-{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
-
- trans->type = type;
- trans->flags = flags;
- trans->cb_event = event;
- trans->cb_conv = conv;
- trans->cb_progress = progress;
- trans->state = STATE_INITIALIZED;
-
- return(0);
-}
-
-/** Add a target to the transaction.
- * @param trans the current transaction
- * @param target the name of the target to add
- * @return 0 on success, -1 on error (pm_errno is set accordingly)
- */
-int _alpm_trans_addtarget(pmtrans_t *trans, char *target)
-{
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
- ASSERT(target != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
-
- switch(trans->type) {
- case PM_TRANS_TYPE_UPGRADE:
- if(_alpm_add_loadtarget(trans, handle->db_local, target) == -1) {
- /* pm_errno is set by _alpm_add_loadtarget() */
- return(-1);
- }
- break;
- case PM_TRANS_TYPE_REMOVE:
- case PM_TRANS_TYPE_REMOVEUPGRADE:
- if(_alpm_remove_loadtarget(trans, handle->db_local, target) == -1) {
- /* pm_errno is set by _alpm_remove_loadtarget() */
- return(-1);
- }
- break;
- case PM_TRANS_TYPE_SYNC:
- if(_alpm_sync_addtarget(trans, handle->db_local, handle->dbs_sync, target) == -1) {
- /* pm_errno is set by _alpm_sync_loadtarget() */
- return(-1);
- }
- break;
- }
-
- return(0);
-}
-
-int _alpm_trans_prepare(pmtrans_t *trans, alpm_list_t **data)
-{
- if(data) {
- *data = NULL;
- }
-
- ALPM_LOG_FUNC;
-
- /* Sanity checks */
- ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
-
- /* If there's nothing to do, return without complaining */
- if(trans->packages == NULL) {
- return(0);
- }
-
- switch(trans->type) {
- case PM_TRANS_TYPE_UPGRADE:
- if(_alpm_add_prepare(trans, handle->db_local, data) == -1) {
- /* pm_errno is set by _alpm_add_prepare() */
- return(-1);
- }
- break;
- case PM_TRANS_TYPE_REMOVE:
- case PM_TRANS_TYPE_REMOVEUPGRADE:
- if(_alpm_remove_prepare(trans, handle->db_local, data) == -1) {
- /* pm_errno is set by _alpm_remove_prepare() */
- return(-1);
- }
- break;
- case PM_TRANS_TYPE_SYNC:
- if(_alpm_sync_prepare(trans, handle->db_local, handle->dbs_sync, data) == -1) {
- /* pm_errno is set by _alpm_sync_prepare() */
- return(-1);
- }
- break;
- }
-
- trans->state = STATE_PREPARED;
-
- return(0);
-}
-
-int _alpm_trans_commit(pmtrans_t *trans, alpm_list_t **data)
-{
- ALPM_LOG_FUNC;
-
- if(data!=NULL)
- *data = NULL;
-
- /* Sanity checks */
- ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
-
- /* If there's nothing to do, return without complaining */
- if(trans->packages == NULL) {
- return(0);
- }
-
- trans->state = STATE_COMMITING;
-
- switch(trans->type) {
- case PM_TRANS_TYPE_UPGRADE:
- if(_alpm_add_commit(trans, handle->db_local) == -1) {
- /* pm_errno is set by _alpm_add_commit() */
- return(-1);
- }
- break;
- case PM_TRANS_TYPE_REMOVE:
- case PM_TRANS_TYPE_REMOVEUPGRADE:
- if(_alpm_remove_commit(trans, handle->db_local) == -1) {
- /* pm_errno is set by _alpm_remove_commit() */
- return(-1);
- }
- break;
- case PM_TRANS_TYPE_SYNC:
- if(_alpm_sync_commit(trans, handle->db_local, data) == -1) {
- /* pm_errno is set by _alpm_sync_commit() */
- return(-1);
- }
- break;
- }
-
- trans->state = STATE_COMMITED;
-
- return(0);
-}
-
/* A cheap grep for text files, returns 1 if a substring
* was found in the text file fn, 0 if it wasn't
*/
@@ -503,30 +407,30 @@ cleanup:
return(retval);
}
-pmtranstype_t SYMEXPORT alpm_trans_get_type()
+unsigned int SYMEXPORT alpm_trans_get_flags()
{
/* Sanity checks */
ASSERT(handle != NULL, return(-1));
ASSERT(handle->trans != NULL, return(-1));
- return handle->trans->type;
+ return handle->trans->flags;
}
-unsigned int SYMEXPORT alpm_trans_get_flags()
+alpm_list_t SYMEXPORT * alpm_trans_get_add()
{
/* Sanity checks */
- ASSERT(handle != NULL, return(-1));
- ASSERT(handle->trans != NULL, return(-1));
+ ASSERT(handle != NULL, return(NULL));
+ ASSERT(handle->trans != NULL, return(NULL));
- return handle->trans->flags;
+ return handle->trans->add;
}
-alpm_list_t SYMEXPORT * alpm_trans_get_pkgs()
+alpm_list_t SYMEXPORT * alpm_trans_get_remove()
{
/* Sanity checks */
ASSERT(handle != NULL, return(NULL));
ASSERT(handle->trans != NULL, return(NULL));
- return handle->trans->packages;
+ return handle->trans->remove;
}
/* vim: set ts=2 sw=2 noet: */
diff --git a/lib/libalpm/trans.h b/lib/libalpm/trans.h
index 0537bc72..ca1e141a 100644
--- a/lib/libalpm/trans.h
+++ b/lib/libalpm/trans.h
@@ -37,10 +37,10 @@ typedef enum _pmtransstate_t {
/* Transaction */
struct __pmtrans_t {
- pmtranstype_t type;
pmtransflag_t flags;
pmtransstate_t state;
- alpm_list_t *packages; /* list of (pmpkg_t *) */
+ alpm_list_t *add; /* list of (pmpkg_t *) */
+ alpm_list_t *remove; /* list of (pmpkg_t *) */
alpm_list_t *skip_add; /* list of (char *) */
alpm_list_t *skip_remove; /* list of (char *) */
alpm_trans_cb_event cb_event;
@@ -69,12 +69,9 @@ do { \
pmtrans_t *_alpm_trans_new(void);
void _alpm_trans_free(pmtrans_t *trans);
-int _alpm_trans_init(pmtrans_t *trans, pmtranstype_t type, pmtransflag_t flags,
+int _alpm_trans_init(pmtrans_t *trans, pmtransflag_t flags,
alpm_trans_cb_event event, alpm_trans_cb_conv conv,
alpm_trans_cb_progress progress);
-int _alpm_trans_addtarget(pmtrans_t *trans, char *target);
-int _alpm_trans_prepare(pmtrans_t *trans, alpm_list_t **data);
-int _alpm_trans_commit(pmtrans_t *trans, alpm_list_t **data);
int _alpm_runscriptlet(const char *root, const char *installfn,
const char *script, const char *ver,
const char *oldver, pmtrans_t *trans);
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index 082c095b..f78d193a 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -196,51 +196,6 @@ char *_alpm_strtrim(char *str)
return(str);
}
-/* Helper function for _alpm_strreplace */
-static void _strnadd(char **str, const char *append, unsigned int count)
-{
- if(*str) {
- *str = realloc(*str, strlen(*str) + count + 1);
- } else {
- *str = calloc(count + 1, sizeof(char));
- }
-
- strncat(*str, append, count);
-}
-
-/* Replace all occurances of 'needle' with 'replace' in 'str', returning
- * a new string (must be free'd) */
-char *_alpm_strreplace(const char *str, const char *needle, const char *replace)
-{
- const char *p, *q;
- p = q = str;
-
- char *newstr = NULL;
- unsigned int needlesz = strlen(needle),
- replacesz = strlen(replace);
-
- while (1) {
- q = strstr(p, needle);
- if(!q) { /* not found */
- if(*p) {
- /* add the rest of 'p' */
- _strnadd(&newstr, p, strlen(p));
- }
- break;
- } else { /* found match */
- if(q > p){
- /* add chars between this occurance and last occurance, if any */
- _strnadd(&newstr, p, q - p);
- }
- _strnadd(&newstr, replace, replacesz);
- p = q + needlesz;
- }
- }
-
- return newstr;
-}
-
-
/* Create a lock file */
int _alpm_lckmk()
{
diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h
index 4bc8b92f..ccf169d3 100644
--- a/lib/libalpm/util.h
+++ b/lib/libalpm/util.h
@@ -60,7 +60,6 @@ int _alpm_makepath(const char *path);
int _alpm_makepath_mode(const char *path, mode_t mode);
int _alpm_copyfile(const char *src, const char *dest);
char *_alpm_strtrim(char *str);
-char *_alpm_strreplace(const char *str, const char *needle, const char *replace);
int _alpm_lckmk();
int _alpm_lckrm();
int _alpm_unpack(const char *archive, const char *prefix, const char *fn);
diff --git a/pactest/tests/depconflict110.py b/pactest/tests/depconflict110.py
index fd56fa89..82e17d0b 100644
--- a/pactest/tests/depconflict110.py
+++ b/pactest/tests/depconflict110.py
@@ -7,7 +7,7 @@ self.addpkg(p);
lp = pmpkg("pkg2", "1.0-1")
self.addpkg2db("local", lp)
-self.args = "-U %s" % p.filename()
-self.addrule("PACMAN_RETCODE=1")
-self.addrule("!PKG_EXIST=pkg1")
-self.addrule("PKG_EXIST=pkg2")
+self.args = "-U %s --ask=4" % p.filename()
+self.addrule("PACMAN_RETCODE=0")
+self.addrule("PKG_EXIST=pkg1")
+self.addrule("!PKG_EXIST=pkg2")
diff --git a/pactest/tests/ignore002.py b/pactest/tests/ignore002.py
index b2c5593a..9b09e8f7 100644
--- a/pactest/tests/ignore002.py
+++ b/pactest/tests/ignore002.py
@@ -28,7 +28,7 @@ self.addpkg2db("sync", package4up)
self.option["IgnorePkg"] = ["package2"]
self.args = "-Su"
-self.addrule("PACMAN_RETCODE=0")
+self.addrule("PACMAN_RETCODE=1")
self.addrule("PKG_VERSION=package1|1.0-1")
self.addrule("PKG_VERSION=package2|1.0-1")
self.addrule("PKG_VERSION=package3|1.0-1")
diff --git a/pactest/tests/ignore003.py b/pactest/tests/ignore003.py
index 02b3c91c..8768a6ef 100644
--- a/pactest/tests/ignore003.py
+++ b/pactest/tests/ignore003.py
@@ -28,7 +28,7 @@ self.addpkg2db("sync", package4up)
self.option["IgnorePkg"] = ["package2"]
self.args = "-Su"
-self.addrule("PACMAN_RETCODE=0")
+self.addrule("PACMAN_RETCODE=1")
self.addrule("PKG_VERSION=package1|1.0-1")
self.addrule("PKG_VERSION=package2|1.0-1")
self.addrule("PKG_VERSION=package3|1.0-1")
diff --git a/pactest/tests/ignore004.py b/pactest/tests/ignore004.py
index fff12f62..e6af48bd 100644
--- a/pactest/tests/ignore004.py
+++ b/pactest/tests/ignore004.py
@@ -38,7 +38,7 @@ self.addpkg2db("sync", packageA5up)
self.option["IgnorePkg"] = ["packageA3"]
self.args = "-S packageA1"
-self.addrule("PACMAN_RETCODE=0")
+self.addrule("PACMAN_RETCODE=1")
self.addrule("PKG_VERSION=packageA1|1.0-1")
self.addrule("PKG_VERSION=packageA2|1.0-1")
self.addrule("PKG_VERSION=packageA3|1.0-1")
diff --git a/pactest/tests/ignore005.py b/pactest/tests/ignore005.py
index 1957ea4f..274e44c3 100644
--- a/pactest/tests/ignore005.py
+++ b/pactest/tests/ignore005.py
@@ -36,7 +36,7 @@ self.addpkg2db("sync", packageA5up)
self.option["IgnorePkg"] = ["packageA3"]
-self.args = "-S packageA1 packageA2"
+self.args = "-S packageA1 packageA2 --ask=32"
self.addrule("PACMAN_RETCODE=0")
self.addrule("PKG_VERSION=packageA1|1.0-1")
diff --git a/pactest/tests/provision020.py b/pactest/tests/provision020.py
index c9c0ac36..7cb0a01b 100644
--- a/pactest/tests/provision020.py
+++ b/pactest/tests/provision020.py
@@ -10,6 +10,6 @@ self.addpkg2db("local", lp)
self.args = "-S %s" % p.name
-self.addrule("PACMAN_RETCODE=0")
+self.addrule("PACMAN_RETCODE=1")
self.addrule("!PKG_EXIST=pkg1")
self.addrule("PKG_EXIST=pkg2")
diff --git a/pactest/tests/provision022.py b/pactest/tests/provision022.py
index 190a8b66..4883d428 100644
--- a/pactest/tests/provision022.py
+++ b/pactest/tests/provision022.py
@@ -10,6 +10,6 @@ self.addpkg2db("local", lp)
self.args = "-S %s" % p.name
-self.addrule("PACMAN_RETCODE=0")
+self.addrule("PACMAN_RETCODE=1")
self.addrule("!PKG_EXIST=pkg1")
self.addrule("PKG_EXIST=pkg2")
diff --git a/pactest/tests/sync042.py b/pactest/tests/sync042.py
index 0aa7e37b..7c3498d3 100644
--- a/pactest/tests/sync042.py
+++ b/pactest/tests/sync042.py
@@ -9,6 +9,6 @@ self.addpkg2db("local", lp);
self.args = "-S %s" % sp.name
-self.addrule("PACMAN_RETCODE=0")
-self.addrule("PKG_EXIST=pkg1")
-self.addrule("!PKG_EXIST=pkg2")
+self.addrule("PACMAN_RETCODE=1")
+self.addrule("!PKG_EXIST=pkg1")
+self.addrule("PKG_EXIST=pkg2")
diff --git a/pactest/tests/sync043.py b/pactest/tests/sync043.py
index 1302bf04..8461e9f9 100644
--- a/pactest/tests/sync043.py
+++ b/pactest/tests/sync043.py
@@ -7,10 +7,10 @@ self.addpkg2db("sync", sp);
lp1 = pmpkg("pkg2")
self.addpkg2db("local", lp1);
-lp1 = pmpkg("pkg3")
-self.addpkg2db("local", lp1);
+lp2 = pmpkg("pkg3")
+self.addpkg2db("local", lp2);
-self.args = "-S %s" % sp.name
+self.args = "-S %s --ask=4" % sp.name
self.addrule("PACMAN_RETCODE=0")
self.addrule("PKG_EXIST=pkg1")
diff --git a/pactest/tests/sync044.py b/pactest/tests/sync044.py
index c4ff1549..0c8fd2e9 100644
--- a/pactest/tests/sync044.py
+++ b/pactest/tests/sync044.py
@@ -11,7 +11,7 @@ sp3 = pmpkg("pkg3")
sp3.conflicts = ["pkg1"]
self.addpkg2db("sync", sp3);
-self.args = "-S pkg2"
+self.args = "-S pkg2 --ask=4"
self.addrule("PACMAN_RETCODE=0")
self.addrule("!PKG_EXIST=pkg1")
diff --git a/pactest/tests/sync1004.py b/pactest/tests/sync1004.py
index f87bbe9b..a9cee49c 100644
--- a/pactest/tests/sync1004.py
+++ b/pactest/tests/sync1004.py
@@ -11,7 +11,7 @@ self.addpkg2db("sync", sp2)
lp = pmpkg("depend")
self.addpkg2db("local", lp)
-self.args = "-S pkg1 pkg2"
+self.args = "-S pkg1 pkg2 --ask=4"
self.addrule("PACMAN_RETCODE=1")
self.addrule("PKG_EXIST=depend")
diff --git a/pactest/tests/sync1008.py b/pactest/tests/sync1008.py
index 90c61dfb..a6064597 100644
--- a/pactest/tests/sync1008.py
+++ b/pactest/tests/sync1008.py
@@ -14,6 +14,6 @@ self.addpkg2db("sync1", sp3)
self.args = "-S pkg"
-self.addrule("PACMAN_RETCODE=0")
+self.addrule("PACMAN_RETCODE=1")
self.addrule("!PKG_EXIST=pkg")
self.addrule("!PKG_EXIST=cpkg")
diff --git a/pactest/tests/sync150.py b/pactest/tests/sync150.py
new file mode 100644
index 00000000..b62bd984
--- /dev/null
+++ b/pactest/tests/sync150.py
@@ -0,0 +1,25 @@
+self.description = "-Su foo"
+
+sp1 = pmpkg("pkg1", "1.0-2")
+sp1.depends = ["pkg2"]
+
+sp2 = pmpkg("pkg2")
+sp2.depends = ["pkg3"]
+
+sp3 = pmpkg("pkg3")
+
+sp4 = pmpkg("pkg4")
+
+for p in sp1, sp2, sp3, sp4:
+ self.addpkg2db("sync", p)
+
+lp1 = pmpkg("pkg1")
+self.addpkg2db("local", lp1)
+
+self.args = "-Su %s" % sp4.name
+
+self.addrule("PACMAN_RETCODE=0")
+self.addrule("PKG_VERSION=pkg1|1.0-2")
+for p in sp2, sp3:
+ self.addrule("PKG_REASON=%s|1" % p.name)
+self.addrule("PKG_REASON=%s|0" % sp4.name)
diff --git a/pactest/tests/sync300.py b/pactest/tests/sync300.py
index 36d6758a..31b520a8 100644
--- a/pactest/tests/sync300.py
+++ b/pactest/tests/sync300.py
@@ -9,6 +9,6 @@ self.addpkg2db("sync", sp2)
self.args = "-S %s" % sp1.name
-self.addrule("PACMAN_RETCODE=0")
+self.addrule("PACMAN_RETCODE=1")
self.addrule("!PKG_EXIST=pkg1")
self.addrule("!PKG_EXIST=pkg2")
diff --git a/pactest/tests/sync890.py b/pactest/tests/sync890.py
index 75947e9a..e8380b79 100644
--- a/pactest/tests/sync890.py
+++ b/pactest/tests/sync890.py
@@ -12,7 +12,7 @@ lp2.conflicts = ["pkg3"]
for p in lp1, lp2:
self.addpkg2db("local", p)
-self.args = "-S %s" % sp.name
+self.args = "-S %s --ask=4" % sp.name
self.addrule("PACMAN_RETCODE=0")
self.addrule("PKG_EXIST=pkg1")
diff --git a/pactest/tests/sync892.py b/pactest/tests/sync892.py
index 04cc79c5..dfd889ea 100644
--- a/pactest/tests/sync892.py
+++ b/pactest/tests/sync892.py
@@ -16,7 +16,7 @@ lp2.conflicts = ["pkg3"]
for p in lp1, lp2:
self.addpkg2db("local", p)
-self.args = "-S %s" % " ".join([p.name for p in sp1, sp2])
+self.args = "-S %s --ask=4" % " ".join([p.name for p in sp1, sp2])
self.addrule("PACMAN_RETCODE=0")
self.addrule("!PKG_EXIST=pkg1")
diff --git a/pactest/tests/sync893.py b/pactest/tests/sync893.py
index 1c8494a3..e96bb7b6 100644
--- a/pactest/tests/sync893.py
+++ b/pactest/tests/sync893.py
@@ -13,7 +13,7 @@ self.addpkg2db("local", lp1)
lp2 = pmpkg("pkg2")
self.addpkg2db("local", lp2)
-self.args = "-S %s" % " ".join([p.name for p in sp1, sp2])
+self.args = "-S %s --ask=4" % " ".join([p.name for p in sp1, sp2])
self.addrule("PACMAN_RETCODE=1")
self.addrule("PKG_EXIST=pkg1")
diff --git a/pactest/tests/sync895.py b/pactest/tests/sync895.py
index 1b348c19..fd987864 100644
--- a/pactest/tests/sync895.py
+++ b/pactest/tests/sync895.py
@@ -12,7 +12,7 @@ lp2 = pmpkg("pkg2")
lp2.depends = ["foo"]
self.addpkg2db("local", lp2)
-self.args = "-S %s" % sp.name
+self.args = "-S %s --ask=4" % sp.name
self.addrule("PACMAN_RETCODE=1")
self.addrule("PKG_EXIST=pkg1")
diff --git a/pactest/tests/sync896.py b/pactest/tests/sync896.py
index a89b5c70..492bd7b4 100644
--- a/pactest/tests/sync896.py
+++ b/pactest/tests/sync896.py
@@ -13,7 +13,7 @@ lp2 = pmpkg("pkg2")
lp2.depends = ["foo"]
self.addpkg2db("local", lp2)
-self.args = "-S %s" % sp.name
+self.args = "-S %s --ask=4" % sp.name
self.addrule("PACMAN_RETCODE=0")
self.addrule("!PKG_EXIST=pkg1")
diff --git a/pactest/tests/sync897.py b/pactest/tests/sync897.py
index f7bd3d71..8a1c5a7c 100644
--- a/pactest/tests/sync897.py
+++ b/pactest/tests/sync897.py
@@ -16,7 +16,7 @@ self.addpkg2db("local", lp2)
lp3 = pmpkg("pkg3")
self.addpkg2db("local", lp3)
-self.args = "-Su"
+self.args = "-Su --ask=4"
self.addrule("PACMAN_RETCODE=1")
self.addrule("PKG_EXIST=pkg1")
diff --git a/pactest/tests/sync899.py b/pactest/tests/sync899.py
index a561ae63..fd308050 100644
--- a/pactest/tests/sync899.py
+++ b/pactest/tests/sync899.py
@@ -11,7 +11,7 @@ self.addpkg2db("local", lp1)
lp2 = pmpkg("pkg2")
self.addpkg2db("local", lp2)
-self.args = "-Su"
+self.args = "-Su --ask=4"
self.addrule("PACMAN_RETCODE=0")
self.addrule("PKG_EXIST=pkg1")
diff --git a/pactest/tests/sync900.py b/pactest/tests/sync900.py
index 16dfee12..744fad03 100644
--- a/pactest/tests/sync900.py
+++ b/pactest/tests/sync900.py
@@ -16,7 +16,7 @@ lp2 = pmpkg("pkg2")
lp2.depends = ["foo"]
self.addpkg2db("local", lp2)
-self.args = "-S %s" % sp.name
+self.args = "-S %s --ask=4" % sp.name
self.addrule("PACMAN_RETCODE=0")
self.addrule("!PKG_EXIST=foo")
diff --git a/pactest/tests/sync901.py b/pactest/tests/sync901.py
index bb420b79..f5834533 100644
--- a/pactest/tests/sync901.py
+++ b/pactest/tests/sync901.py
@@ -16,7 +16,7 @@ lp2 = pmpkg("pkg2")
lp2.depends = ["foo"]
self.addpkg2db("local", lp2)
-self.args = "-S %s" % sp.name
+self.args = "-S %s --ask=4" % sp.name
self.addrule("PACMAN_RETCODE=0")
self.addrule("PKG_EXIST=foo")
diff --git a/pactest/tests/sync992.py b/pactest/tests/sync992.py
index a7ad1110..63faaaba 100644
--- a/pactest/tests/sync992.py
+++ b/pactest/tests/sync992.py
@@ -15,7 +15,7 @@ for p in sp1, sp2, sp3:
lp1 = pmpkg("pkg2", "0.1-1")
self.addpkg2db("local", lp1)
-self.args = "-S %s" % " ".join([p.name for p in sp1, sp2])
+self.args = "-S %s --ask=4" % " ".join([p.name for p in sp1, sp2])
self.addrule("PACMAN_RETCODE=0")
self.addrule("PKG_EXIST=pkg1")
diff --git a/pactest/tests/sync999.py b/pactest/tests/sync999.py
index 69089fa1..89447cad 100644
--- a/pactest/tests/sync999.py
+++ b/pactest/tests/sync999.py
@@ -14,7 +14,7 @@ self.addpkg2db("local", lp1)
lp2 = pmpkg("pkg2")
self.addpkg2db("local", lp2)
-self.args = "-Su"
+self.args = "-Su --ask=4"
self.addrule("PACMAN_RETCODE=0")
self.addrule("PKG_EXIST=pkg1")
diff --git a/pactest/tests/upgrade051.py b/pactest/tests/upgrade051.py
index 4346c24d..1d173218 100644
--- a/pactest/tests/upgrade051.py
+++ b/pactest/tests/upgrade051.py
@@ -8,10 +8,8 @@ p.conflicts = ["pkg1"]
p.provides = ["pkg1"]
self.addpkg(p)
-self.args = "-U %s" % p.filename()
+self.args = "-U %s --ask=4" % p.filename()
self.addrule("PACMAN_RETCODE=0")
self.addrule("!PKG_EXIST=pkg1")
self.addrule("PKG_EXIST=pkg2")
-
-self.expectfailure = True
diff --git a/pactest/tests/upgrade080.py b/pactest/tests/upgrade080.py
new file mode 100644
index 00000000..9ddbd708
--- /dev/null
+++ b/pactest/tests/upgrade080.py
@@ -0,0 +1,16 @@
+self.description = "Install a package (correct architecture)"
+
+p = pmpkg("dummy")
+p.files = ["bin/dummy",
+ "usr/man/man1/dummy.1"]
+p.arch = 'testarch'
+self.addpkg(p)
+
+self.option["Architecture"] = ['testarch']
+
+self.args = "-U %s" % p.filename()
+
+self.addrule("PACMAN_RETCODE=0")
+self.addrule("PKG_EXIST=dummy")
+for f in p.files:
+ self.addrule("FILE_EXIST=%s" % f)
diff --git a/pactest/tests/upgrade081.py b/pactest/tests/upgrade081.py
new file mode 100644
index 00000000..99e22311
--- /dev/null
+++ b/pactest/tests/upgrade081.py
@@ -0,0 +1,16 @@
+self.description = "Install a package (wrong architecture)"
+
+p = pmpkg("dummy")
+p.files = ["bin/dummy",
+ "usr/man/man1/dummy.1"]
+p.arch = 'testarch'
+self.addpkg(p)
+
+self.option["Architecture"] = ['nottestarch']
+
+self.args = "-U %s" % p.filename()
+
+self.addrule("PACMAN_RETCODE=1")
+self.addrule("!PKG_EXIST=dummy")
+for f in p.files:
+ self.addrule("!FILE_EXIST=%s" % f)
diff --git a/pactest/tests/upgrade082.py b/pactest/tests/upgrade082.py
new file mode 100644
index 00000000..0bdbdf71
--- /dev/null
+++ b/pactest/tests/upgrade082.py
@@ -0,0 +1,19 @@
+self.description = "Install a package (correct architecture, auto)"
+
+import os
+machine = os.uname()[4]
+
+p = pmpkg("dummy")
+p.files = ["bin/dummy",
+ "usr/man/man1/dummy.1"]
+p.arch = machine
+self.addpkg(p)
+
+self.option["Architecture"] = ['auto']
+
+self.args = "-U %s" % p.filename()
+
+self.addrule("PACMAN_RETCODE=0")
+self.addrule("PKG_EXIST=dummy")
+for f in p.files:
+ self.addrule("FILE_EXIST=%s" % f)
diff --git a/pactest/tests/upgrade083.py b/pactest/tests/upgrade083.py
new file mode 100644
index 00000000..097ae02c
--- /dev/null
+++ b/pactest/tests/upgrade083.py
@@ -0,0 +1,19 @@
+self.description = "Install a package (wrong architecture, auto)"
+
+import os
+machine = os.uname()[4]
+
+p = pmpkg("dummy")
+p.files = ["bin/dummy",
+ "usr/man/man1/dummy.1"]
+p.arch = machine + 'wrong'
+self.addpkg(p)
+
+self.option["Architecture"] = ['auto']
+
+self.args = "-U %s" % p.filename()
+
+self.addrule("PACMAN_RETCODE=1")
+self.addrule("!PKG_EXIST=dummy")
+for f in p.files:
+ self.addrule("!FILE_EXIST=%s" % f)
diff --git a/pactest/tests/upgrade084.py b/pactest/tests/upgrade084.py
new file mode 100644
index 00000000..8268e3ff
--- /dev/null
+++ b/pactest/tests/upgrade084.py
@@ -0,0 +1,16 @@
+self.description = "Install a package ('any' architecture)"
+
+p = pmpkg("dummy")
+p.files = ["bin/dummy",
+ "usr/man/man1/dummy.1"]
+p.arch = 'any'
+self.addpkg(p)
+
+self.option["Architecture"] = ['auto']
+
+self.args = "-U %s" % p.filename()
+
+self.addrule("PACMAN_RETCODE=0")
+self.addrule("PKG_EXIST=dummy")
+for f in p.files:
+ self.addrule("FILE_EXIST=%s" % f)
diff --git a/pactest/tests/upgrade090.py b/pactest/tests/upgrade090.py
new file mode 100644
index 00000000..26e531c9
--- /dev/null
+++ b/pactest/tests/upgrade090.py
@@ -0,0 +1,28 @@
+self.description = "-U syncdeps test"
+
+p1 = pmpkg("pkg1", "1.0-2")
+p1.files = ["bin/pkg1"]
+
+p2 = pmpkg("pkg2", "1.0-2")
+p2.depends = ["dep"]
+
+p3 = pmpkg("pkg3", "1.0-2")
+p3.depends = ["unres"]
+
+for p in p1, p2, p3:
+ self.addpkg(p)
+
+sp = pmpkg("dep")
+sp.files = ["bin/dep"]
+self.addpkg2db("sync", sp)
+
+self.args = "-U %s --ask=32" % " ".join([p.filename() for p in p1, p2, p3])
+
+self.addrule("PACMAN_RETCODE=0")
+for p in p1, p2, sp:
+ self.addrule("PKG_EXIST=%s" % p.name)
+ for f in p.files:
+ self.addrule("FILE_EXIST=%s" % f)
+self.addrule("PKG_VERSION=pkg1|1.0-2")
+self.addrule("PKG_VERSION=pkg2|1.0-2")
+self.addrule("!PKG_EXIST=pkg3")
diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 99e19b4f..3e918e69 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -175,6 +175,7 @@ clean_up() {
##
# Signal Traps
##
+set -E
trap 'clean_up' 0
trap 'trap_exit "$(gettext "TERM signal caught. Exiting...")"' TERM HUP QUIT
trap 'trap_exit "$(gettext "Aborted by user! Exiting...")"' INT
@@ -355,7 +356,7 @@ check_deps() {
fi
}
-handledeps() {
+handle_deps() {
local R_DEPS_SATISFIED=0
local R_DEPS_MISSING=1
@@ -403,7 +404,7 @@ resolve_deps() {
return $R_DEPS_SATISFIED
fi
- if handledeps $deplist; then
+ if handle_deps $deplist; then
pkgdeps="$pkgdeps $deplist"
# check deps again to make sure they were resolved
deplist="$(check_deps $*)"
@@ -693,72 +694,23 @@ extract_sources() {
fi
}
-run_build() {
- # use distcc if it is requested (check buildenv and PKGBUILD opts)
- if [ "$(check_buildenv distcc)" = "y" -a "$(check_option distcc)" != "n" ]; then
- [ -d /usr/lib/distcc/bin ] && export PATH="/usr/lib/distcc/bin:$PATH"
- export DISTCC_HOSTS
- elif [ "$(check_option distcc)" = "n" ]; then
- # if it is not wanted, clear the makeflags too
- MAKEFLAGS=""
- fi
-
- # use ccache if it is requested (check buildenv and PKGBUILD opts)
- if [ "$(check_buildenv ccache)" = "y" -a "$(check_option ccache)" != "n" ]; then
- [ -d /usr/lib/ccache/bin ] && export PATH="/usr/lib/ccache/bin:$PATH"
- fi
-
- # clear user-specified makeflags if requested
- if [ "$(check_option makeflags)" = "n" ]; then
- MAKEFLAGS=""
- fi
-
- msg "$(gettext "Starting build()...")"
- cd "$srcdir"
-
- # ensure all necessary build variables are exported
- export CFLAGS CXXFLAGS MAKEFLAGS LDFLAGS CHOST
- # save our shell options so build() can't override what we need
- local shellopts=$(shopt -p)
-
- local ret=0
- if [ "$LOGGING" -eq 1 ]; then
- BUILDLOG="${startdir}/${pkgbase}-${pkgver}-${pkgrel}-${CARCH}-build.log"
- if [ -f "$BUILDLOG" ]; then
- local i=1
- while true; do
- if [ -f "$BUILDLOG.$i" ]; then
- i=$(($i +1))
- else
- break
- fi
- done
- mv "$BUILDLOG" "$BUILDLOG.$i"
- fi
-
- build 2>&1 | tee "$BUILDLOG"; ret=${PIPESTATUS[0]}
- else
- build 2>&1 || ret=$?
+error_function() {
+ if [ -p "$logpipe" ]; then
+ rm "$logpipe"
fi
- # reset our shell options
- eval "$shellopts"
-
- if [ $ret -gt 0 ]; then
- error "$(gettext "Build Failed.")"
+ # first exit all subshells, then print the error
+ if [ $BASH_SUBSHELL -eq 0 ]; then
plain "$(gettext "Aborting...")"
remove_deps
- exit 2 # $E_BUILD_FAILED
fi
+ exit 2 # $E_BUILD_FAILED
}
-run_package() {
+run_function() {
if [ -z "$1" ]; then
- pkgfunc="package"
- nameofpkg="$pkgname"
- else
- pkgfunc="package_$1"
- nameofpkg="$1"
+ return 1
fi
+ pkgfunc="$1"
# clear user-specified makeflags if requested
if [ "$(check_option makeflags)" = "n" ]; then
@@ -770,10 +722,12 @@ run_package() {
# ensure all necessary build variables are exported
export CFLAGS CXXFLAGS LDFLAGS MAKEFLAGS CHOST
+ # save our shell options so pkgfunc() can't override what we need
+ local shellopts=$(shopt -p)
local ret=0
if [ "$LOGGING" -eq 1 ]; then
- BUILDLOG="${startdir}/${nameofpkg}-${pkgver}-${pkgrel}-${CARCH}-package.log"
+ BUILDLOG="${startdir}/${pkgname}-${pkgver}-${pkgrel}-${CARCH}-$pkgfunc.log"
if [ -f "$BUILDLOG" ]; then
local i=1
while true; do
@@ -792,20 +746,49 @@ run_package() {
exec 3>&1
tee "$BUILDLOG" < "$logpipe" &
exec 1>"$logpipe" 2>"$logpipe"
- $pkgfunc 2>&1 || ret=$?
+ restoretrap=$(trap -p ERR)
+ trap 'error_function' ERR
+ $pkgfunc 2>&1
+ eval $restoretrap
sync
exec 1>&3 2>&3 3>&-
rm "$logpipe"
else
- $pkgfunc 2>&1 || ret=$?
+ restoretrap=$(trap -p ERR)
+ trap 'error_function' ERR
+ $pkgfunc 2>&1
+ eval $restoretrap
fi
+ # reset our shell options
+ eval "$shellopts"
+}
- if [ $ret -gt 0 ]; then
- error "$(gettext "Packaging Failed.")"
- plain "$(gettext "Aborting...")"
- remove_deps
- exit 2 # $E_BUILD_FAILED
+run_build() {
+ # use distcc if it is requested (check buildenv and PKGBUILD opts)
+ if [ "$(check_buildenv distcc)" = "y" -a "$(check_option distcc)" != "n" ]; then
+ [ -d /usr/lib/distcc/bin ] && export PATH="/usr/lib/distcc/bin:$PATH"
+ export DISTCC_HOSTS
+ elif [ "$(check_option distcc)" = "n" ]; then
+ # if it is not wanted, clear the makeflags too
+ MAKEFLAGS=""
fi
+
+ # use ccache if it is requested (check buildenv and PKGBUILD opts)
+ if [ "$(check_buildenv ccache)" = "y" -a "$(check_option ccache)" != "n" ]; then
+ [ -d /usr/lib/ccache/bin ] && export PATH="/usr/lib/ccache/bin:$PATH"
+ fi
+
+ run_function "build"
+}
+
+run_package() {
+ if [ -z "$1" ]; then
+ pkgfunc="package"
+ else
+ pkgfunc="package_$1"
+ fi
+
+ run_function "$pkgfunc"
}
tidy_install() {
@@ -966,6 +949,18 @@ write_pkginfo() {
fi
}
+check_package() {
+ cd "$pkgdir"
+
+ # check existence of backup files
+ local file
+ for file in "${backup[@]}"; do
+ if [ ! -f "$file" ]; then
+ warning "$(gettext "Invalid backup entry : %s")" "$file"
+ fi
+ done
+}
+
create_package() {
if [ ! -d "$pkgdir" ]; then
error "$(gettext "Missing pkg/ directory.")"
@@ -973,6 +968,8 @@ create_package() {
exit 1 # $E_MISSING_PKGDIR
fi
+ check_package
+
cd "$pkgdir"
msg "$(gettext "Creating package...")"
@@ -1175,6 +1172,22 @@ check_sanity() {
fi
done
+ local file
+ for file in "${backup[@]}"; do
+ if [ "${file:0:1}" = "/" ]; then
+ error "$(gettext "Invalid backup entry : %s")" "$file"
+ return 1
+ fi
+ done
+
+ local optdepend
+ for optdepend in "${optdepends[@]}"; do
+ pkg=${optdepend%%:*}
+ if [[ ! $pkg =~ ^[[:alnum:]\>\<\=\.\+\_\-]*$ ]]; then
+ error "$(gettext "Invalid syntax for optdepend : '%s'")" "$optdepend"
+ fi
+ done
+
if [ "$install" -a ! -f "$install" ]; then
error "$(gettext "Install scriptlet (%s) does not exist.")" "$install"
return 1
diff --git a/scripts/rankmirrors.py.in b/scripts/rankmirrors.py.in
index 4b253b67..6bfa6612 100644
--- a/scripts/rankmirrors.py.in
+++ b/scripts/rankmirrors.py.in
@@ -156,6 +156,8 @@ if __name__ == "__main__":
# if the $repo var is used in the url, replace it by core
tempUrl = Template(serverUrl).safe_substitute(repo='core')
+ # if the $arch var is used in the url, replace it by i686
+ tempUrl = Template(tempUrl).safe_substitute(arch='i686')
# add @DBEXT@ to server name. the repo name is parsed
# from the mirror url; it is the third (or fourth) dir
diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index e83a97d2..1dd3ffba 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -259,10 +259,20 @@ void cb_trans_conv(pmtransconv_t event, void *data1, void *data2,
alpm_pkg_get_name(data2));
break;
case PM_TRANS_CONV_CONFLICT_PKG:
- *response = yesno(_(":: %s conflicts with %s. Remove %s?"),
- (char *)data1,
- (char *)data2,
- (char *)data2);
+ /* data parameters: target package, local package, conflict (strings) */
+ /* print conflict only if it contains new information */
+ if(!strcmp(data1, data3) || !strcmp(data2, data3)) {
+ *response = noyes(_(":: %s and %s are in conflict. Remove %s?"),
+ (char *)data1,
+ (char *)data2,
+ (char *)data2);
+ } else {
+ *response = noyes(_(":: %s and %s are in conflict (%s). Remove %s?"),
+ (char *)data1,
+ (char *)data2,
+ (char *)data3,
+ (char *)data2);
+ }
break;
case PM_TRANS_CONV_REMOVE_PKGS:
{
@@ -275,7 +285,7 @@ void cb_trans_conv(pmtransconv_t event, void *data1, void *data2,
printf(_(":: the following package(s) cannot be upgraded due to "
"unresolvable dependencies:\n"));
list_display(" ", namelist);
- *response = yesno(_("\nDo you want to skip the above "
+ *response = noyes(_("\nDo you want to skip the above "
"package(s) for this upgrade?"));
alpm_list_free(namelist);
}
@@ -294,6 +304,12 @@ void cb_trans_conv(pmtransconv_t event, void *data1, void *data2,
(char *)data1);
break;
}
+ if(config->noask) {
+ if(config->ask & event) {
+ /* inverse the default answer */
+ *response = !*response;
+ }
+ }
}
/* callback to handle display of transaction progress */
diff --git a/src/pacman/conf.h b/src/pacman/conf.h
index 2d3de987..3c588a7e 100644
--- a/src/pacman/conf.h
+++ b/src/pacman/conf.h
@@ -63,6 +63,8 @@ typedef struct __config_t {
unsigned short group;
pmtransflag_t flags;
+ unsigned short noask;
+ unsigned int ask;
/* conf file options */
unsigned short chomp; /* I Love Candy! */
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index 77c558d1..64598b09 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -149,6 +149,7 @@ static void usage(int op, const char * const myname)
printf(_(" -r, --root <path> set an alternate installation root\n"));
printf(_(" -b, --dbpath <path> set an alternate database location\n"));
printf(_(" --cachedir <dir> set an alternate package cache location\n"));
+ printf(_(" --arch <arch> set an alternate architecture\n"));
}
}
@@ -195,6 +196,19 @@ static void setuseragent(void)
setenv("HTTP_USER_AGENT", agent, 0);
}
+static void setarch(const char *arch)
+{
+ if (strcmp(arch, "auto") == 0) {
+ struct utsname un;
+ uname(&un);
+ pm_printf(PM_LOG_DEBUG, "config: architecture: %s\n", un.machine);
+ alpm_option_set_arch(un.machine);
+ } else {
+ pm_printf(PM_LOG_DEBUG, "config: architecture: %s\n", arch);
+ alpm_option_set_arch(arch);
+ }
+}
+
/** Free the resources.
*
* @param ret the return value
@@ -370,12 +384,14 @@ static int parseargs(int argc, char *argv[])
{"debug", optional_argument, 0, 1003},
{"noprogressbar", no_argument, 0, 1004},
{"noscriptlet", no_argument, 0, 1005},
+ {"ask", required_argument, 0, 1006},
{"cachedir", required_argument, 0, 1007},
{"asdeps", no_argument, 0, 1008},
{"logfile", required_argument, 0, 1009},
{"ignoregroup", required_argument, 0, 1010},
{"needed", no_argument, 0, 1011},
{"asexplicit", no_argument, 0, 1012},
+ {"arch", required_argument, 0, 1013},
{0, 0, 0, 0}
};
@@ -426,6 +442,7 @@ static int parseargs(int argc, char *argv[])
break;
case 1004: config->noprogressbar = 1; break;
case 1005: config->flags |= PM_TRANS_FLAG_NOSCRIPTLET; break;
+ case 1006: config->noask = 1; config->ask = atoi(optarg); break;
case 1007:
if(alpm_option_add_cachedir(optarg) != 0) {
pm_printf(PM_LOG_ERROR, _("problem adding cachedir '%s' (%s)\n"),
@@ -450,6 +467,9 @@ static int parseargs(int argc, char *argv[])
case 1012:
config->flags |= PM_TRANS_FLAG_ALLEXPLICIT;
break;
+ case 1013:
+ setarch(optarg);
+ break;
case 'Q': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_QUERY); break;
case 'R': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_REMOVE); break;
case 'S': config->op = (config->op != PM_OP_MAIN ? 0 : PM_OP_SYNC); break;
@@ -615,9 +635,7 @@ int download_with_xfercommand(const char *url, const char *localpath,
int ret = 0;
int retval;
int usepart = 0;
- char *ptr1, *ptr2;
- char origCmd[PATH_MAX];
- char parsedCmd[PATH_MAX] = "";
+ char *parsedcmd,*tempcmd;
char cwd[PATH_MAX];
char *destfile, *tempfile, *filename;
@@ -632,28 +650,18 @@ int download_with_xfercommand(const char *url, const char *localpath,
destfile = get_destfile(localpath, filename);
tempfile = get_tempfile(localpath, filename);
- strncpy(origCmd, config->xfercommand, sizeof(origCmd));
+ tempcmd = strdup(config->xfercommand);
/* replace all occurrences of %o with fn.part */
- ptr1 = origCmd;
- while((ptr2 = strstr(ptr1, "%o"))) {
+ if(strstr(tempcmd, "%o")) {
usepart = 1;
- ptr2[0] = '\0';
- strcat(parsedCmd, ptr1);
- strcat(parsedCmd, tempfile);
- ptr1 = ptr2 + 2;
+ parsedcmd = strreplace(tempcmd, "%o", tempfile);
+ free(tempcmd);
+ tempcmd = parsedcmd;
}
- strcat(parsedCmd, ptr1);
/* replace all occurrences of %u with the download URL */
- strncpy(origCmd, parsedCmd, sizeof(origCmd));
- parsedCmd[0] = '\0';
- ptr1 = origCmd;
- while((ptr2 = strstr(ptr1, "%u"))) {
- ptr2[0] = '\0';
- strcat(parsedCmd, ptr1);
- strcat(parsedCmd, url);
- ptr1 = ptr2 + 2;
- }
- strcat(parsedCmd, ptr1);
+ parsedcmd = strreplace(tempcmd, "%u", url);
+ free(tempcmd);
+
/* cwd to the download directory */
getcwd(cwd, PATH_MAX);
if(chdir(localpath)) {
@@ -662,8 +670,8 @@ int download_with_xfercommand(const char *url, const char *localpath,
goto cleanup;
}
/* execute the parsed command via /bin/sh -c */
- pm_printf(PM_LOG_DEBUG, "running command: %s\n", parsedCmd);
- retval = system(parsedCmd);
+ pm_printf(PM_LOG_DEBUG, "running command: %s\n", parsedcmd);
+ retval = system(parsedcmd);
if(retval == -1) {
pm_printf(PM_LOG_WARNING, "running XferCommand: fork failed!\n");
@@ -689,6 +697,7 @@ cleanup:
}
free(destfile);
free(tempfile);
+ free(parsedcmd);
return(ret);
}
@@ -787,10 +796,7 @@ static int _parseconfig(const char *file, const char *givensection,
}
if(ptr == NULL && strcmp(section, "options") == 0) {
/* directives without settings, all in [options] */
- if(strcmp(key, "NoPassiveFtp") == 0) {
- alpm_option_set_nopassiveftp(1);
- pm_printf(PM_LOG_DEBUG, "config: nopassiveftp\n");
- } else if(strcmp(key, "UseSyslog") == 0) {
+ if(strcmp(key, "UseSyslog") == 0) {
alpm_option_set_usesyslog(1);
pm_printf(PM_LOG_DEBUG, "config: usesyslog\n");
} else if(strcmp(key, "ILoveCandy") == 0) {
@@ -830,6 +836,10 @@ static int _parseconfig(const char *file, const char *givensection,
setrepeatingoption(ptr, "HoldPkg", option_add_holdpkg);
} else if(strcmp(key, "SyncFirst") == 0) {
setrepeatingoption(ptr, "SyncFirst", option_add_syncfirst);
+ } else if(strcmp(key, "Architecture") == 0) {
+ if(!alpm_option_get_arch()) {
+ setarch(ptr);
+ }
} else if(strcmp(key, "DBPath") == 0) {
/* don't overwrite a path specified on the command line */
if(!config->dbpath) {
@@ -878,7 +888,23 @@ static int _parseconfig(const char *file, const char *givensection,
}
} else if(strcmp(key, "Server") == 0) {
/* let's attempt a replacement for the current repo */
- char *server = strreplace(ptr, "$repo", section);
+ char *temp = strreplace(ptr, "$repo", section);
+ /* let's attempt a replacement for the arch */
+ const char *arch = alpm_option_get_arch();
+ char *server;
+ if(arch) {
+ server = strreplace(temp, "$arch", arch);
+ free(temp);
+ } else {
+ if(strstr(temp, "$arch")) {
+ free(temp);
+ pm_printf(PM_LOG_ERROR, _("The mirror '%s' contains the $arch"
+ " variable, but no Architecture is defined.\n"), ptr);
+ ret = 1;
+ goto cleanup;
+ }
+ server = temp;
+ }
if(alpm_db_setserver(db, server) != 0) {
/* pm_errno is set by alpm_db_setserver */
@@ -923,6 +949,29 @@ static int parseconfig(const char *file)
return(_parseconfig(file, NULL, NULL));
}
+/** print commandline to logfile
+ */
+static void cl_to_log(int argc, char* argv[])
+{
+ size_t size = 0;
+ int i;
+ for(i = 0; i<argc; i++) {
+ size += strlen(argv[i]) + 1;
+ }
+ char *cl_text = malloc(size);
+ if(!cl_text)
+ return;
+ char *p = cl_text;
+ for(i = 0; i<argc-1; i++) {
+ strcpy(p, argv[i]);
+ p += strlen(argv[i]);
+ *p++ = ' ';
+ }
+ strcpy(p, argv[i]);
+ alpm_logaction("Running '%s'\n", cl_text);
+ free(cl_text);
+}
+
/** Main function.
* @param argc argc
* @param argv argv
@@ -1018,6 +1067,11 @@ int main(int argc, char *argv[])
alpm_option_set_totaldlcb(cb_dl_total);
}
+ /* noask is meant to be non-interactive */
+ if(config->noask) {
+ config->noconfirm = 1;
+ }
+
#if defined(HAVE_GETEUID) && !defined(CYGWIN)
/* check if we have sufficient permission for the requested operation */
if(myuid > 0 && needs_root()) {
@@ -1049,6 +1103,11 @@ int main(int argc, char *argv[])
cleanup(EXIT_FAILURE);
}
+ /* Log commandline */
+ if(needs_root()) {
+ cl_to_log(argc, argv);
+ }
+
/* start the requested operation */
switch(config->op) {
case PM_OP_REMOVE:
diff --git a/src/pacman/remove.c b/src/pacman/remove.c
index 0efbd94e..ced4e12f 100644
--- a/src/pacman/remove.c
+++ b/src/pacman/remove.c
@@ -51,50 +51,23 @@ int pacman_remove(alpm_list_t *targets)
}
/* Step 0: create a new transaction */
- if(trans_init(PM_TRANS_TYPE_REMOVE, config->flags) == -1) {
+ if(trans_init(config->flags) == -1) {
return(1);
}
/* Step 1: add targets to the created transaction */
for(i = targets; i; i = alpm_list_next(i)) {
- char *targ = alpm_list_getdata(i);
- if(alpm_trans_addtarget(targ) == -1) {
- if(pm_errno == PM_ERR_PKG_NOT_FOUND) {
- printf(_("%s not found, searching for group...\n"), targ);
- pmgrp_t *grp = alpm_db_readgrp(db_local, targ);
- if(grp == NULL) {
- pm_fprintf(stderr, PM_LOG_ERROR, _("'%s': not found in local db\n"), targ);
- retval = 1;
- goto cleanup;
- } else {
- alpm_list_t *p, *pkgnames = NULL;
- /* convert packages to package names */
- for(p = alpm_grp_get_pkgs(grp); p; p = alpm_list_next(p)) {
- pmpkg_t *pkg = alpm_list_getdata(p);
- pkgnames = alpm_list_add(pkgnames, (void *)alpm_pkg_get_name(pkg));
- }
- printf(_(":: group %s:\n"), targ);
- list_display(" ", pkgnames);
- int all = yesno(_(" Remove whole content?"));
- for(p = pkgnames; p; p = alpm_list_next(p)) {
- char *pkgn = alpm_list_getdata(p);
- if(all || yesno(_(":: Remove %s from group %s?"), pkgn, targ)) {
- if(alpm_trans_addtarget(pkgn) == -1) {
- pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", targ,
- alpm_strerrorlast());
- retval = 1;
- alpm_list_free(pkgnames);
- goto cleanup;
- }
- }
- }
- alpm_list_free(pkgnames);
- }
- } else {
- pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", targ, alpm_strerrorlast());
- retval = 1;
- goto cleanup;
- }
+ char *target = alpm_list_getdata(i);
+ char *targ = strchr(target, '/');
+ if(targ && strncmp(target, "local", 5) == 0) {
+ targ++;
+ } else {
+ targ = target;
+ }
+ if(alpm_remove_target(targ) == -1) {
+ pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", targ, alpm_strerrorlast());
+ retval = 1;
+ goto cleanup;
}
}
@@ -103,6 +76,12 @@ int pacman_remove(alpm_list_t *targets)
pm_fprintf(stderr, PM_LOG_ERROR, _("failed to prepare transaction (%s)\n"),
alpm_strerrorlast());
switch(pm_errno) {
+ case PM_ERR_PKG_INVALID_ARCH:
+ for(i = data; i; i = alpm_list_next(i)) {
+ char *pkg = alpm_list_getdata(i);
+ printf(_(":: package %s does not have a valid architecture\n"), pkg);
+ }
+ break;
case PM_ERR_UNSATISFIED_DEPS:
for(i = data; i; i = alpm_list_next(i)) {
pmdepmissing_t *miss = alpm_list_getdata(i);
@@ -123,7 +102,7 @@ int pacman_remove(alpm_list_t *targets)
/* Search for holdpkg in target list */
int holdpkg = 0;
- for(i = alpm_trans_get_pkgs(); i; i = alpm_list_next(i)) {
+ for(i = alpm_trans_get_remove(); i; i = alpm_list_next(i)) {
pmpkg_t *pkg = alpm_list_getdata(i);
if(alpm_list_find_str(config->holdpkg, alpm_pkg_get_name(pkg))) {
pm_printf(PM_LOG_WARNING, _("%s is designated as a HoldPkg.\n"),
@@ -140,7 +119,7 @@ int pacman_remove(alpm_list_t *targets)
if(config->flags & PM_TRANS_FLAG_RECURSE ||
config->flags & PM_TRANS_FLAG_CASCADE) {
/* list transaction targets */
- alpm_list_t *pkglist = alpm_trans_get_pkgs();
+ alpm_list_t *pkglist = alpm_trans_get_remove();
display_targets(pkglist, 0);
printf("\n");
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index dc936219..b23a9633 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -242,7 +242,7 @@ static int sync_synctree(int level, alpm_list_t *syncs)
alpm_list_t *i;
int success = 0, ret;
- if(trans_init(PM_TRANS_TYPE_SYNC, 0) == -1) {
+ if(trans_init(0) == -1) {
return(0);
}
@@ -548,89 +548,66 @@ static alpm_list_t *syncfirst() {
return(res);
}
+static int process_target(char *target)
+{
+ /* process targets */
+ char *targ = strchr(target, '/');
+ char *db = NULL;
+ int ret;
+ if(targ) {
+ *targ = '\0';
+ targ++;
+ db = target;
+ ret = alpm_sync_dbtarget(db,targ);
+ } else {
+ targ = target;
+ ret = alpm_sync_target(targ);
+ }
+
+ if(ret == -1) {
+ if(pm_errno == PM_ERR_TRANS_DUP_TARGET
+ || pm_errno == PM_ERR_PKG_IGNORED) {
+ /* just skip duplicate or ignored targets */
+ pm_printf(PM_LOG_WARNING, _("skipping target: %s\n"), targ);
+ return(0);
+ }
+ pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n",
+ targ, alpm_strerrorlast());
+ return(1);
+ }
+
+ return(0);
+}
+
static int sync_trans(alpm_list_t *targets)
{
int retval = 0;
alpm_list_t *data = NULL;
- alpm_list_t *sync_dbs = alpm_option_get_syncdbs();
alpm_list_t *packages = NULL;
+ alpm_list_t *i;
/* Step 1: create a new transaction... */
- if(trans_init(PM_TRANS_TYPE_SYNC, config->flags) == -1) {
+ if(trans_init(config->flags) == -1) {
return(1);
}
+ /* process targets */
+ for(i = targets; i; i = alpm_list_next(i)) {
+ char *targ = alpm_list_getdata(i);
+ if(process_target(targ) == 1) {
+ retval = 1;
+ goto cleanup;
+ }
+ }
+
if(config->op_s_upgrade) {
printf(_(":: Starting full system upgrade...\n"));
alpm_logaction("starting full system upgrade\n");
- if(alpm_trans_sysupgrade(config->op_s_upgrade >= 2) == -1) {
+ if(alpm_sync_sysupgrade(config->op_s_upgrade >= 2) == -1) {
pm_fprintf(stderr, PM_LOG_ERROR, "%s\n", alpm_strerrorlast());
retval = 1;
goto cleanup;
}
- } else {
- alpm_list_t *i;
-
- /* process targets */
- for(i = targets; i; i = alpm_list_next(i)) {
- char *targ = alpm_list_getdata(i);
- if(alpm_trans_addtarget(targ) == -1) {
- pmgrp_t *grp = NULL;
- int found = 0;
- alpm_list_t *j;
-
- if(pm_errno == PM_ERR_TRANS_DUP_TARGET || pm_errno == PM_ERR_PKG_IGNORED) {
- /* just skip duplicate or ignored targets */
- pm_printf(PM_LOG_WARNING, _("skipping target: %s\n"), targ);
- continue;
- }
- if(pm_errno != PM_ERR_PKG_NOT_FOUND) {
- pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n",
- targ, alpm_strerrorlast());
- retval = 1;
- goto cleanup;
- }
- /* target not found: check if it's a group */
- printf(_("%s package not found, searching for group...\n"), targ);
- for(j = sync_dbs; j; j = alpm_list_next(j)) {
- pmdb_t *db = alpm_list_getdata(j);
- grp = alpm_db_readgrp(db, targ);
- if(grp) {
- alpm_list_t *k, *pkgnames = NULL;
-
- found++;
- printf(_(":: group %s (including ignored packages):\n"), targ);
- /* remove dupe entries in case a package exists in multiple repos */
- alpm_list_t *grppkgs = alpm_grp_get_pkgs(grp);
- alpm_list_t *pkgs = alpm_list_remove_dupes(grppkgs);
- for(k = pkgs; k; k = alpm_list_next(k)) {
- pkgnames = alpm_list_add(pkgnames,
- (char*)alpm_pkg_get_name(k->data));
- }
- list_display(" ", pkgnames);
- if(yesno(_(":: Install whole content?"))) {
- for(k = pkgnames; k; k = alpm_list_next(k)) {
- targets = alpm_list_add(targets, strdup(alpm_list_getdata(k)));
- }
- } else {
- for(k = pkgnames; k; k = alpm_list_next(k)) {
- char *pkgname = alpm_list_getdata(k);
- if(yesno(_(":: Install %s from group %s?"), pkgname, targ)) {
- targets = alpm_list_add(targets, strdup(pkgname));
- }
- }
- }
- alpm_list_free(pkgnames);
- alpm_list_free(pkgs);
- }
- }
- if(!found) {
- pm_fprintf(stderr, PM_LOG_ERROR, _("'%s': not found in sync db\n"), targ);
- retval = 1;
- goto cleanup;
- }
- }
- }
}
/* Step 2: "compute" the transaction based on targets and flags */
@@ -639,6 +616,12 @@ static int sync_trans(alpm_list_t *targets)
alpm_strerrorlast());
switch(pm_errno) {
alpm_list_t *i;
+ case PM_ERR_PKG_INVALID_ARCH:
+ for(i = data; i; i = alpm_list_next(i)) {
+ char *pkg = alpm_list_getdata(i);
+ printf(_(":: package %s does not have a valid architecture\n"), pkg);
+ }
+ break;
case PM_ERR_UNSATISFIED_DEPS:
for(i = data; i; i = alpm_list_next(i)) {
pmdepmissing_t *miss = alpm_list_getdata(i);
@@ -650,10 +633,17 @@ static int sync_trans(alpm_list_t *targets)
}
break;
case PM_ERR_CONFLICTING_DEPS:
- for(i = data; i; i = alpm_list_next(i)) {
+ for(i = data; i; i = alpm_list_next(i)) {
pmconflict_t *conflict = alpm_list_getdata(i);
- printf(_(":: %s: conflicts with %s\n"),
- alpm_conflict_get_package1(conflict), alpm_conflict_get_package2(conflict));
+ const char *package1 = alpm_conflict_get_package1(conflict);
+ const char *package2 = alpm_conflict_get_package2(conflict);
+ const char *reason = alpm_conflict_get_reason(conflict);
+ /* only print reason if it contains new information */
+ if(!strcmp(package1, reason) || !strcmp(package2, reason)) {
+ printf(_(":: %s and %s are in conflict\n"), package1, package2);
+ } else {
+ printf(_(":: %s and %s are in conflict (%s)\n"), package1, package2, reason);
+ }
}
break;
default:
@@ -663,7 +653,7 @@ static int sync_trans(alpm_list_t *targets)
goto cleanup;
}
- packages = alpm_trans_get_pkgs();
+ packages = alpm_trans_get_add();
if(packages == NULL) {
/* nothing to do: just exit without complaining */
printf(_(" local database is up to date\n"));
@@ -691,7 +681,8 @@ static int sync_trans(alpm_list_t *targets)
goto cleanup;
}
- display_synctargets(packages);
+ display_targets(alpm_trans_get_remove(), 0);
+ display_targets(alpm_trans_get_add(), 1);
printf("\n");
int confirm;
@@ -768,7 +759,7 @@ int pacman_sync(alpm_list_t *targets)
if(config->op_s_clean) {
int ret = 0;
- if(trans_init(PM_TRANS_TYPE_SYNC, 0) == -1) {
+ if(trans_init(0) == -1) {
return(1);
}
diff --git a/src/pacman/upgrade.c b/src/pacman/upgrade.c
index 1570f95e..57c7b790 100644
--- a/src/pacman/upgrade.c
+++ b/src/pacman/upgrade.c
@@ -42,7 +42,6 @@
int pacman_upgrade(alpm_list_t *targets)
{
alpm_list_t *i, *data = NULL;
- pmtranstype_t transtype = PM_TRANS_TYPE_UPGRADE;
int retval = 0;
if(targets == NULL) {
@@ -65,7 +64,7 @@ int pacman_upgrade(alpm_list_t *targets)
}
/* Step 1: create a new transaction */
- if(trans_init(transtype, config->flags) == -1) {
+ if(trans_init(config->flags) == -1) {
return(1);
}
@@ -73,7 +72,7 @@ int pacman_upgrade(alpm_list_t *targets)
printf(_("loading package data...\n"));
for(i = targets; i; i = alpm_list_next(i)) {
char *targ = alpm_list_getdata(i);
- if(alpm_trans_addtarget(targ) == -1) {
+ if(alpm_add_target(targ) == -1) {
pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n",
targ, alpm_strerrorlast());
trans_release();
@@ -87,6 +86,12 @@ int pacman_upgrade(alpm_list_t *targets)
pm_fprintf(stderr, PM_LOG_ERROR, _("failed to prepare transaction (%s)\n"),
alpm_strerrorlast());
switch(pm_errno) {
+ case PM_ERR_PKG_INVALID_ARCH:
+ for(i = data; i; i = alpm_list_next(i)) {
+ char *pkg = alpm_list_getdata(i);
+ printf(_(":: package %s does not have a valid architecture\n"), pkg);
+ }
+ break;
case PM_ERR_UNSATISFIED_DEPS:
for(i = data; i; i = alpm_list_next(i)) {
pmdepmissing_t *miss = alpm_list_getdata(i);
@@ -104,42 +109,75 @@ int pacman_upgrade(alpm_list_t *targets)
case PM_ERR_CONFLICTING_DEPS:
for(i = data; i; i = alpm_list_next(i)) {
pmconflict_t *conflict = alpm_list_getdata(i);
- printf(_(":: %s: conflicts with %s\n"),
- alpm_conflict_get_package1(conflict), alpm_conflict_get_package2(conflict));
+ const char *package1 = alpm_conflict_get_package1(conflict);
+ const char *package2 = alpm_conflict_get_package2(conflict);
+ const char *reason = alpm_conflict_get_reason(conflict);
+ /* only print reason if it contains new information */
+ if(!strcmp(package1, reason) || !strcmp(package2, reason)) {
+ printf(_(":: %s and %s are in conflict\n"), package1, package2);
+ } else {
+ printf(_(":: %s and %s are in conflict (%s)\n"), package1, package2, reason);
+ }
}
break;
+ default:
+ break;
+ }
+ trans_release();
+ FREELIST(data);
+ return(1);
+ }
+
+ /* Step 3: perform the installation */
+ /* print targets and ask user confirmation */
+ alpm_list_t *packages = alpm_trans_get_add();
+ if(packages == NULL) { /* we are done */
+ trans_release();
+ return(retval);
+ }
+ display_targets(alpm_trans_get_remove(), 0);
+ display_targets(alpm_trans_get_add(), 1);
+ printf("\n");
+ int confirm = yesno(_("Proceed with installation?"));
+ if(!confirm) {
+ trans_release();
+ return(retval);
+ }
+
+ if(alpm_trans_commit(&data) == -1) {
+ pm_fprintf(stderr, PM_LOG_ERROR, _("failed to commit transaction (%s)\n"),
+ alpm_strerrorlast());
+ switch(pm_errno) {
+ alpm_list_t *i;
case PM_ERR_FILE_CONFLICTS:
for(i = data; i; i = alpm_list_next(i)) {
pmfileconflict_t *conflict = alpm_list_getdata(i);
switch(alpm_fileconflict_get_type(conflict)) {
case PM_FILECONFLICT_TARGET:
printf(_("%s exists in both '%s' and '%s'\n"),
- alpm_fileconflict_get_file(conflict),
- alpm_fileconflict_get_target(conflict),
- alpm_fileconflict_get_ctarget(conflict));
- break;
+ alpm_fileconflict_get_file(conflict),
+ alpm_fileconflict_get_target(conflict),
+ alpm_fileconflict_get_ctarget(conflict));
+ break;
case PM_FILECONFLICT_FILESYSTEM:
printf(_("%s: %s exists in filesystem\n"),
- alpm_fileconflict_get_target(conflict),
- alpm_fileconflict_get_file(conflict));
- break;
+ alpm_fileconflict_get_target(conflict),
+ alpm_fileconflict_get_file(conflict));
+ break;
}
}
- printf(_("\nerrors occurred, no packages were upgraded.\n"));
+ break;
+ case PM_ERR_PKG_INVALID:
+ case PM_ERR_DLT_INVALID:
+ for(i = data; i; i = alpm_list_next(i)) {
+ char *filename = alpm_list_getdata(i);
+ printf(_("%s is invalid or corrupted\n"), filename);
+ }
break;
default:
break;
}
- trans_release();
FREELIST(data);
- return(1);
- }
- alpm_list_free(data);
-
- /* Step 3: perform the installation */
- if(alpm_trans_commit(NULL) == -1) {
- pm_fprintf(stderr, PM_LOG_ERROR, _("failed to commit transaction (%s)\n"),
- alpm_strerrorlast());
trans_release();
return(1);
}
diff --git a/src/pacman/util.c b/src/pacman/util.c
index a02b43cd..353aae3a 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -45,9 +45,9 @@
#include "callback.h"
-int trans_init(pmtranstype_t type, pmtransflag_t flags)
+int trans_init(pmtransflag_t flags)
{
- if(alpm_trans_init(type, flags, cb_trans_evt,
+ if(alpm_trans_init(flags, cb_trans_evt,
cb_trans_conv, cb_trans_progress) == -1) {
pm_fprintf(stderr, PM_LOG_ERROR, _("failed to init transaction (%s)\n"),
alpm_strerrorlast());
@@ -85,34 +85,18 @@ int needs_root(void)
/* gets the current screen column width */
int getcols(void)
{
- if(!isatty(1)) {
- /* We will default to 80 columns if we're not a tty
- * this seems a fairly standard file width.
- */
- return 80;
- } else {
#ifdef TIOCGSIZE
- struct ttysize win;
- if(ioctl(1, TIOCGSIZE, &win) == 0) {
- return win.ts_cols;
- }
-#elif defined(TIOCGWINSZ)
- struct winsize win;
- if(ioctl(1, TIOCGWINSZ, &win) == 0) {
- return win.ws_col;
- }
-#endif
- /* If we can't figure anything out, we'll just assume 80 columns */
- /* TODO any problems caused by this assumption? */
- return 80;
+ struct ttysize win;
+ if(ioctl(1, TIOCGSIZE, &win) == 0) {
+ return win.ts_cols;
}
- /* Original envvar way - prone to display issues
- const char *cenv = getenv("COLUMNS");
- if(cenv != NULL) {
- return atoi(cenv);
+#elif defined(TIOCGWINSZ)
+ struct winsize win;
+ if(ioctl(1, TIOCGWINSZ, &win) == 0) {
+ return win.ws_col;
}
- return -1;
- */
+#endif
+ return 0;
}
/* does the same thing as 'mkdir -p' */
@@ -256,6 +240,14 @@ void indentprint(const char *str, int indent)
return;
}
+ cols = getcols();
+
+ /* if we're not a tty, print without indenting */
+ if(cols == 0) {
+ printf("%s", str);
+ return;
+ }
+
len = strlen(str) + 1;
wcstr = calloc(len, sizeof(wchar_t));
len = mbstowcs(wcstr, str, len);
@@ -265,7 +257,6 @@ void indentprint(const char *str, int indent)
if(!p) {
return;
}
- cols = getcols();
while(*p) {
if(*p == L' ') {
@@ -284,7 +275,7 @@ void indentprint(const char *str, int indent)
}
if(len > (cols - cidx - 1)) {
/* wrap to a newline and reindent */
- fprintf(stdout, "\n%-*s", indent, "");
+ printf("\n%-*s", indent, "");
cidx = indent;
} else {
printf(" ");
@@ -292,7 +283,7 @@ void indentprint(const char *str, int indent)
}
continue;
}
- fprintf(stdout, "%lc", (wint_t)*p);
+ printf("%lc", (wint_t)*p);
cidx += wcwidth(*p);
p++;
}
@@ -344,48 +335,65 @@ char *strtrim(char *str)
return(str);
}
-/* Helper function for strreplace */
-static void _strnadd(char **str, const char *append, unsigned int count)
-{
- if(*str) {
- *str = realloc(*str, strlen(*str) + count + 1);
- } else {
- *str = calloc(sizeof(char), count + 1);
- }
-
- strncat(*str, append, count);
-}
-
/* Replace all occurances of 'needle' with 'replace' in 'str', returning
* a new string (must be free'd) */
char *strreplace(const char *str, const char *needle, const char *replace)
{
- const char *p, *q;
- p = q = str;
+ const char *p = NULL, *q = NULL;
+ char *newstr = NULL, *newp = NULL;
+ alpm_list_t *i = NULL, *list = NULL;
+ size_t needlesz = strlen(needle), replacesz = strlen(replace);
+ size_t newsz;
- char *newstr = NULL;
- unsigned int needlesz = strlen(needle),
- replacesz = strlen(replace);
+ if(!str) {
+ return(NULL);
+ }
- while (1) {
+ p = str;
+ q = strstr(p, needle);
+ while(q) {
+ list = alpm_list_add(list, (char *)q);
+ p = q + needlesz;
q = strstr(p, needle);
- if(!q) { /* not found */
- if(*p) {
- /* add the rest of 'p' */
- _strnadd(&newstr, p, strlen(p));
- }
- break;
- } else { /* found match */
- if(q > p){
- /* add chars between this occurance and last occurance, if any */
- _strnadd(&newstr, p, q - p);
- }
- _strnadd(&newstr, replace, replacesz);
- p = q + needlesz;
+ }
+
+ /* no occurences of needle found */
+ if(!list) {
+ return(strdup(str));
+ }
+ /* size of new string = size of old string + "number of occurences of needle"
+ * x "size difference between replace and needle" */
+ newsz = strlen(str) + 1 +
+ alpm_list_count(list) * (replacesz - needlesz);
+ newstr = malloc(newsz);
+ if(!newstr) {
+ return(NULL);
+ }
+ *newstr = '\0';
+
+ p = str;
+ newp = newstr;
+ for(i = list; i; i = alpm_list_next(i)) {
+ q = alpm_list_getdata(i);
+ if(q > p){
+ /* add chars between this occurence and last occurence, if any */
+ strncpy(newp, p, q - p);
+ newp += q - p;
}
+ strncpy(newp, replace, replacesz);
+ newp += replacesz;
+ p = q + needlesz;
}
+ alpm_list_free(list);
- return newstr;
+ if(*p) {
+ /* add the rest of 'p' */
+ strcpy(newp, p);
+ newp += strlen(p);
+ }
+ *newp = '\0';
+
+ return(newstr);
}
/** Splits a string into a list of strings using the chosen character as
@@ -476,7 +484,7 @@ void list_display(const char *title, const alpm_list_t *list)
/* two additional spaces are added to the length */
s += 2;
int maxcols = getcols();
- if(s + cols > maxcols) {
+ if(s + cols > maxcols && maxcols > 0) {
int j;
cols = len;
printf("\n");
@@ -576,37 +584,6 @@ void display_targets(const alpm_list_t *pkgs, int install)
FREELIST(targets);
}
-/* Display a list of transaction targets.
- * `pkgs` should be a list of pmpkg_t's,
- * retrieved from a transaction object
- */
-void display_synctargets(const alpm_list_t *syncpkgs)
-{
- const alpm_list_t *i, *j;
- alpm_list_t *pkglist = NULL, *rpkglist = NULL;
-
- for(i = syncpkgs; i; i = alpm_list_next(i)) {
- pmpkg_t *pkg = alpm_list_getdata(i);
- pkglist = alpm_list_add(pkglist, pkg);
-
- /* The removes member contains a list of packages to be removed
- * due to the package that is being installed. */
- alpm_list_t *to_replace = alpm_pkg_get_removes(pkg);
-
- for(j = to_replace; j; j = alpm_list_next(j)) {
- pmpkg_t *rp = alpm_list_getdata(j);
- rpkglist = alpm_list_add(rpkglist, rp);
- }
- }
-
- /* start displaying information */
- display_targets(rpkglist, 0);
- display_targets(pkglist, 1);
-
- alpm_list_free(pkglist);
- alpm_list_free(rpkglist);
-}
-
/* Helper function for comparing strings using the
* alpm "compare func" signature */
int str_cmp(const void *s1, const void *s2)
diff --git a/src/pacman/util.h b/src/pacman/util.h
index 12824221..a71de2d7 100644
--- a/src/pacman/util.h
+++ b/src/pacman/util.h
@@ -37,7 +37,7 @@
/* update speed for the fill_progress based functions */
#define UPDATE_SPEED_SEC 0.2f
-int trans_init(pmtranstype_t type, pmtransflag_t flags);
+int trans_init(pmtransflag_t flags);
int trans_release(void);
int needs_root(void);
int getcols(void);
@@ -54,7 +54,6 @@ void string_display(const char *title, const char *string);
void list_display(const char *title, const alpm_list_t *list);
void list_display_linebreak(const char *title, const alpm_list_t *list);
void display_targets(const alpm_list_t *pkgs, int install);
-void display_synctargets(const alpm_list_t *syncpkgs);
void display_new_optdepends(pmpkg_t *oldpkg, pmpkg_t *newpkg);
void display_optdepends(pmpkg_t *pkg);
int yesno(char *fmt, ...);