summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Griffin <aaron@archlinux.org>2007-03-22 08:22:48 +0000
committerAaron Griffin <aaron@archlinux.org>2007-03-22 08:22:48 +0000
commitd8ec08f578f413ef63ad6c23cbc11b1cb70ffd69 (patch)
tree9446470abb253f61e3c3ca37f02eac8ee76416f7
parent3aa0c85716bd854cd88bd8df53ce6811cbf90ef0 (diff)
downloadpacman-d8ec08f578f413ef63ad6c23cbc11b1cb70ffd69.tar.xz
* Correct install scriptlet usage (reuse of handle->root when not needed)
* Skip running scriptlet when chroot fails - to prevent issues in the host filesystem
-rw-r--r--lib/libalpm/add.c15
-rw-r--r--lib/libalpm/remove.c12
-rw-r--r--lib/libalpm/util.c2
3 files changed, 15 insertions, 14 deletions
diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
index 3bb17e90..0c344544 100644
--- a/lib/libalpm/add.c
+++ b/lib/libalpm/add.c
@@ -318,6 +318,7 @@ int _alpm_add_commit(pmtrans_t *trans, pmdb_t *db)
pkg_count = alpm_list_count(trans->targets);
for(targ = trans->packages; targ; targ = targ->next) {
+ char scriptlet[PATH_MAX+1];
int targ_count = 0, is_upgrade = 0, use_md5 = 0;
double percent = 0.0;
pmpkg_t *newpkg = (pmpkg_t *)targ->data;
@@ -328,6 +329,9 @@ int _alpm_add_commit(pmtrans_t *trans, pmdb_t *db)
break;
}
+ snprintf(scriptlet, PATH_MAX, "%s%s-%s/install", db->path,
+ alpm_pkg_get_name(newpkg), alpm_pkg_get_version(newpkg));
+
/* check if we have a valid sha1sum, if not, use MD5 */
if(strlen(newpkg->sha1sum) == 0) {
use_md5 = 1;
@@ -357,7 +361,7 @@ int _alpm_add_commit(pmtrans_t *trans, pmdb_t *db)
/* pre_upgrade scriptlet */
if(alpm_pkg_has_scriptlet(newpkg) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
- _alpm_runscriptlet(handle->root, newpkg->data, "pre_upgrade", newpkg->version, oldpkg->version, trans);
+ _alpm_runscriptlet(handle->root, scriptlet, "pre_upgrade", newpkg->version, oldpkg->version, trans);
}
} else {
is_upgrade = 0;
@@ -367,7 +371,7 @@ int _alpm_add_commit(pmtrans_t *trans, pmdb_t *db)
/* pre_install scriptlet */
if(alpm_pkg_has_scriptlet(newpkg) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
- _alpm_runscriptlet(handle->root, newpkg->data, "pre_install", newpkg->version, NULL, trans);
+ _alpm_runscriptlet(handle->root, scriptlet, "pre_install", newpkg->version, NULL, trans);
}
}
@@ -817,15 +821,12 @@ int _alpm_add_commit(pmtrans_t *trans, pmdb_t *db)
/* run the post-install script if it exists */
if(alpm_pkg_has_scriptlet(newpkg) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
- char pm_install[PATH_MAX];
- snprintf(pm_install, PATH_MAX, "%s%s%s-%s/install", handle->root, db->path,
- alpm_pkg_get_name(newpkg), alpm_pkg_get_version(newpkg));
if(is_upgrade) {
- _alpm_runscriptlet(handle->root, pm_install, "post_upgrade",
+ _alpm_runscriptlet(handle->root, scriptlet, "post_upgrade",
alpm_pkg_get_version(newpkg), oldpkg ? alpm_pkg_get_version(oldpkg) : NULL,
trans);
} else {
- _alpm_runscriptlet(handle->root, pm_install, "post_install",
+ _alpm_runscriptlet(handle->root, scriptlet, "post_install",
alpm_pkg_get_version(newpkg), NULL, trans);
}
}
diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c
index 47e5cfe7..03b23d25 100644
--- a/lib/libalpm/remove.c
+++ b/lib/libalpm/remove.c
@@ -275,7 +275,7 @@ int _alpm_remove_commit(pmtrans_t *trans, pmdb_t *db)
for(targ = trans->packages; targ; targ = targ->next) {
int position = 0;
- char pm_install[PATH_MAX];
+ char scriptlet[PATH_MAX];
alpm_list_t *files;
info = (pmpkg_t*)targ->data;
const char *pkgname = NULL;
@@ -284,6 +284,8 @@ int _alpm_remove_commit(pmtrans_t *trans, pmdb_t *db)
break;
}
+ snprintf(scriptlet, PATH_MAX, "%s%s-%s/install", db->path,
+ pkgname, alpm_pkg_get_version(info));
/* get the name now so we can use it after package is removed */
pkgname = alpm_pkg_get_name(info);
@@ -294,9 +296,7 @@ int _alpm_remove_commit(pmtrans_t *trans, pmdb_t *db)
/* run the pre-remove scriptlet if it exists */
if(alpm_pkg_has_scriptlet(info) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
- snprintf(pm_install, PATH_MAX, "%s/%s-%s/install", db->path,
- pkgname, alpm_pkg_get_version(info));
- _alpm_runscriptlet(handle->root, pm_install, "pre_remove",
+ _alpm_runscriptlet(handle->root, scriptlet, "pre_remove",
alpm_pkg_get_version(info), NULL, trans);
}
}
@@ -324,9 +324,7 @@ int _alpm_remove_commit(pmtrans_t *trans, pmdb_t *db)
if(trans->type != PM_TRANS_TYPE_UPGRADE) {
/* run the post-remove script if it exists */
if(alpm_pkg_has_scriptlet(info) && !(trans->flags & PM_TRANS_FLAG_NOSCRIPTLET)) {
- snprintf(pm_install, PATH_MAX, "%s/%s-%s/install", db->path,
- pkgname, alpm_pkg_get_version(info));
- _alpm_runscriptlet(handle->root, pm_install, "post_remove",
+ _alpm_runscriptlet(handle->root, scriptlet, "post_remove",
alpm_pkg_get_version(info), NULL, trans);
}
}
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index 2b3847ad..daaa8c76 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -431,6 +431,7 @@ int _alpm_runscriptlet(const char *root, const char *installfn,
if(stat(installfn, &buf)) {
/* not found */
+ _alpm_log(PM_LOG_DEBUG, "scriptlet '%s' not found", installfn);
return(0);
}
@@ -469,6 +470,7 @@ int _alpm_runscriptlet(const char *root, const char *installfn,
/* just in case our cwd was removed in the upgrade operation */
if(chdir(root) != 0) {
_alpm_log(PM_LOG_ERROR, _("could not change directory to %s (%s)"), root, strerror(errno));
+ goto cleanup;
}
_alpm_log(PM_LOG_DEBUG, _("executing %s script..."), script);