Revamp scriptlet path formation for scriptlets in local database
Expose the current static get_pkgpath() function internally to the rest of the library as _alpm_local_db_pkgpath(). This allows use of this convenience function in add.c and remove.c when forming the path to the scriptlet location. Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
73139ccb3c
commit
39b0ac43fc
4 changed files with 20 additions and 18 deletions
|
@ -650,14 +650,12 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg,
|
||||||
/* run the post-install script if it exists */
|
/* run the post-install script if it exists */
|
||||||
if(alpm_pkg_has_scriptlet(newpkg)
|
if(alpm_pkg_has_scriptlet(newpkg)
|
||||||
&& !(trans->flags & ALPM_TRANS_FLAG_NOSCRIPTLET)) {
|
&& !(trans->flags & ALPM_TRANS_FLAG_NOSCRIPTLET)) {
|
||||||
char scriptlet[PATH_MAX];
|
char *scriptlet = _alpm_local_db_pkgpath(db, newpkg, "install");
|
||||||
const char *scriptlet_name;
|
const char *scriptlet_name = is_upgrade ? "post_upgrade" : "post_install";
|
||||||
snprintf(scriptlet, PATH_MAX, "%s%s-%s/install",
|
|
||||||
_alpm_db_path(db), newpkg->name, newpkg->version);
|
|
||||||
scriptlet_name = is_upgrade ? "post_upgrade" : "post_install";
|
|
||||||
|
|
||||||
_alpm_runscriptlet(handle, scriptlet, scriptlet_name,
|
_alpm_runscriptlet(handle, scriptlet, scriptlet_name,
|
||||||
newpkg->version, oldpkg ? oldpkg->version : NULL, 0);
|
newpkg->version, oldpkg ? oldpkg->version : NULL, 0);
|
||||||
|
free(scriptlet);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(is_upgrade) {
|
if(is_upgrade) {
|
||||||
|
|
|
@ -475,7 +475,7 @@ static int local_db_populate(alpm_db_t *db)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Note: the return value must be freed by the caller */
|
/* Note: the return value must be freed by the caller */
|
||||||
static char *get_pkgpath(alpm_db_t *db, alpm_pkg_t *info, const char *filename)
|
char *_alpm_local_db_pkgpath(alpm_db_t *db, alpm_pkg_t *info, const char *filename)
|
||||||
{
|
{
|
||||||
size_t len;
|
size_t len;
|
||||||
char *pkgpath;
|
char *pkgpath;
|
||||||
|
@ -544,7 +544,7 @@ static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq)
|
||||||
_alpm_log(db->handle, ALPM_LOG_FUNCTION, "loading package data for %s : level=0x%x\n",
|
_alpm_log(db->handle, ALPM_LOG_FUNCTION, "loading package data for %s : level=0x%x\n",
|
||||||
info->name, inforeq);
|
info->name, inforeq);
|
||||||
|
|
||||||
pkgpath = get_pkgpath(db, info, NULL);
|
pkgpath = _alpm_local_db_pkgpath(db, info, NULL);
|
||||||
if(!pkgpath || access(pkgpath, F_OK)) {
|
if(!pkgpath || access(pkgpath, F_OK)) {
|
||||||
/* directory doesn't exist or can't be opened */
|
/* directory doesn't exist or can't be opened */
|
||||||
_alpm_log(db->handle, ALPM_LOG_DEBUG, "cannot find '%s-%s' in db '%s'\n",
|
_alpm_log(db->handle, ALPM_LOG_DEBUG, "cannot find '%s-%s' in db '%s'\n",
|
||||||
|
@ -558,7 +558,7 @@ static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq)
|
||||||
|
|
||||||
/* DESC */
|
/* DESC */
|
||||||
if(inforeq & INFRQ_DESC && !(info->infolevel & INFRQ_DESC)) {
|
if(inforeq & INFRQ_DESC && !(info->infolevel & INFRQ_DESC)) {
|
||||||
char *path = get_pkgpath(db, info, "desc");
|
char *path = _alpm_local_db_pkgpath(db, info, "desc");
|
||||||
if(!path || (fp = fopen(path, "r")) == NULL) {
|
if(!path || (fp = fopen(path, "r")) == NULL) {
|
||||||
_alpm_log(db->handle, ALPM_LOG_ERROR, _("could not open file %s: %s\n"), path, strerror(errno));
|
_alpm_log(db->handle, ALPM_LOG_ERROR, _("could not open file %s: %s\n"), path, strerror(errno));
|
||||||
free(path);
|
free(path);
|
||||||
|
@ -628,7 +628,7 @@ static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq)
|
||||||
|
|
||||||
/* FILES */
|
/* FILES */
|
||||||
if(inforeq & INFRQ_FILES && !(info->infolevel & INFRQ_FILES)) {
|
if(inforeq & INFRQ_FILES && !(info->infolevel & INFRQ_FILES)) {
|
||||||
char *path = get_pkgpath(db, info, "files");
|
char *path = _alpm_local_db_pkgpath(db, info, "files");
|
||||||
if(!path || (fp = fopen(path, "r")) == NULL) {
|
if(!path || (fp = fopen(path, "r")) == NULL) {
|
||||||
_alpm_log(db->handle, ALPM_LOG_ERROR, _("could not open file %s: %s\n"), path, strerror(errno));
|
_alpm_log(db->handle, ALPM_LOG_ERROR, _("could not open file %s: %s\n"), path, strerror(errno));
|
||||||
free(path);
|
free(path);
|
||||||
|
@ -685,7 +685,7 @@ static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq)
|
||||||
|
|
||||||
/* INSTALL */
|
/* INSTALL */
|
||||||
if(inforeq & INFRQ_SCRIPTLET && !(info->infolevel & INFRQ_SCRIPTLET)) {
|
if(inforeq & INFRQ_SCRIPTLET && !(info->infolevel & INFRQ_SCRIPTLET)) {
|
||||||
char *path = get_pkgpath(db, info, "install");
|
char *path = _alpm_local_db_pkgpath(db, info, "install");
|
||||||
if(access(path, F_OK) == 0) {
|
if(access(path, F_OK) == 0) {
|
||||||
info->scriptlet = 1;
|
info->scriptlet = 1;
|
||||||
}
|
}
|
||||||
|
@ -714,7 +714,7 @@ int _alpm_local_db_prepare(alpm_db_t *db, alpm_pkg_t *info)
|
||||||
}
|
}
|
||||||
|
|
||||||
oldmask = umask(0000);
|
oldmask = umask(0000);
|
||||||
pkgpath = get_pkgpath(db, info, NULL);
|
pkgpath = _alpm_local_db_pkgpath(db, info, NULL);
|
||||||
|
|
||||||
if((retval = mkdir(pkgpath, 0755)) != 0) {
|
if((retval = mkdir(pkgpath, 0755)) != 0) {
|
||||||
_alpm_log(db->handle, ALPM_LOG_ERROR, _("could not create directory %s: %s\n"),
|
_alpm_log(db->handle, ALPM_LOG_ERROR, _("could not create directory %s: %s\n"),
|
||||||
|
@ -746,7 +746,7 @@ int _alpm_local_db_write(alpm_db_t *db, alpm_pkg_t *info, alpm_dbinfrq_t inforeq
|
||||||
char *path;
|
char *path;
|
||||||
_alpm_log(db->handle, ALPM_LOG_DEBUG, "writing %s-%s DESC information back to db\n",
|
_alpm_log(db->handle, ALPM_LOG_DEBUG, "writing %s-%s DESC information back to db\n",
|
||||||
info->name, info->version);
|
info->name, info->version);
|
||||||
path = get_pkgpath(db, info, "desc");
|
path = _alpm_local_db_pkgpath(db, info, "desc");
|
||||||
if(!path || (fp = fopen(path, "w")) == NULL) {
|
if(!path || (fp = fopen(path, "w")) == NULL) {
|
||||||
_alpm_log(db->handle, ALPM_LOG_ERROR, _("could not open file %s: %s\n"),
|
_alpm_log(db->handle, ALPM_LOG_ERROR, _("could not open file %s: %s\n"),
|
||||||
path, strerror(errno));
|
path, strerror(errno));
|
||||||
|
@ -857,7 +857,7 @@ int _alpm_local_db_write(alpm_db_t *db, alpm_pkg_t *info, alpm_dbinfrq_t inforeq
|
||||||
char *path;
|
char *path;
|
||||||
_alpm_log(db->handle, ALPM_LOG_DEBUG, "writing %s-%s FILES information back to db\n",
|
_alpm_log(db->handle, ALPM_LOG_DEBUG, "writing %s-%s FILES information back to db\n",
|
||||||
info->name, info->version);
|
info->name, info->version);
|
||||||
path = get_pkgpath(db, info, "files");
|
path = _alpm_local_db_pkgpath(db, info, "files");
|
||||||
if(!path || (fp = fopen(path, "w")) == NULL) {
|
if(!path || (fp = fopen(path, "w")) == NULL) {
|
||||||
_alpm_log(db->handle, ALPM_LOG_ERROR, _("could not open file %s: %s\n"),
|
_alpm_log(db->handle, ALPM_LOG_ERROR, _("could not open file %s: %s\n"),
|
||||||
path, strerror(errno));
|
path, strerror(errno));
|
||||||
|
@ -903,8 +903,9 @@ cleanup:
|
||||||
int _alpm_local_db_remove(alpm_db_t *db, alpm_pkg_t *info)
|
int _alpm_local_db_remove(alpm_db_t *db, alpm_pkg_t *info)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
char *pkgpath = get_pkgpath(db, info, NULL);
|
char *pkgpath = _alpm_local_db_pkgpath(db, info, NULL);
|
||||||
|
|
||||||
|
/* TODO explicit file removes and then an rmdir? */
|
||||||
ret = _alpm_rmrf(pkgpath);
|
ret = _alpm_rmrf(pkgpath);
|
||||||
free(pkgpath);
|
free(pkgpath);
|
||||||
if(ret != 0) {
|
if(ret != 0) {
|
||||||
|
|
|
@ -93,6 +93,7 @@ void _alpm_db_unregister(alpm_db_t *db);
|
||||||
int _alpm_local_db_prepare(alpm_db_t *db, alpm_pkg_t *info);
|
int _alpm_local_db_prepare(alpm_db_t *db, alpm_pkg_t *info);
|
||||||
int _alpm_local_db_write(alpm_db_t *db, alpm_pkg_t *info, alpm_dbinfrq_t inforeq);
|
int _alpm_local_db_write(alpm_db_t *db, alpm_pkg_t *info, alpm_dbinfrq_t inforeq);
|
||||||
int _alpm_local_db_remove(alpm_db_t *db, alpm_pkg_t *info);
|
int _alpm_local_db_remove(alpm_db_t *db, alpm_pkg_t *info);
|
||||||
|
char *_alpm_local_db_pkgpath(alpm_db_t *db, alpm_pkg_t *info, const char *filename);
|
||||||
|
|
||||||
/* cache bullshit */
|
/* cache bullshit */
|
||||||
/* packages */
|
/* packages */
|
||||||
|
|
|
@ -359,7 +359,6 @@ int _alpm_remove_single_package(alpm_handle_t *handle,
|
||||||
const char *pkgname = oldpkg->name;
|
const char *pkgname = oldpkg->name;
|
||||||
const char *pkgver = oldpkg->version;
|
const char *pkgver = oldpkg->version;
|
||||||
alpm_filelist_t *filelist;
|
alpm_filelist_t *filelist;
|
||||||
char scriptlet[PATH_MAX];
|
|
||||||
size_t i;
|
size_t i;
|
||||||
|
|
||||||
if(newpkg) {
|
if(newpkg) {
|
||||||
|
@ -370,13 +369,13 @@ int _alpm_remove_single_package(alpm_handle_t *handle,
|
||||||
_alpm_log(handle, ALPM_LOG_DEBUG, "removing package %s-%s\n",
|
_alpm_log(handle, ALPM_LOG_DEBUG, "removing package %s-%s\n",
|
||||||
pkgname, pkgver);
|
pkgname, pkgver);
|
||||||
|
|
||||||
snprintf(scriptlet, PATH_MAX, "%s%s-%s/install",
|
|
||||||
_alpm_db_path(handle->db_local), pkgname, pkgver);
|
|
||||||
|
|
||||||
/* run the pre-remove scriptlet if it exists */
|
/* run the pre-remove scriptlet if it exists */
|
||||||
if(alpm_pkg_has_scriptlet(oldpkg) &&
|
if(alpm_pkg_has_scriptlet(oldpkg) &&
|
||||||
!(handle->trans->flags & ALPM_TRANS_FLAG_NOSCRIPTLET)) {
|
!(handle->trans->flags & ALPM_TRANS_FLAG_NOSCRIPTLET)) {
|
||||||
|
char *scriptlet = _alpm_local_db_pkgpath(handle->db_local,
|
||||||
|
oldpkg, "install");
|
||||||
_alpm_runscriptlet(handle, scriptlet, "pre_remove", pkgver, NULL, 0);
|
_alpm_runscriptlet(handle, scriptlet, "pre_remove", pkgver, NULL, 0);
|
||||||
|
free(scriptlet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -453,7 +452,10 @@ int _alpm_remove_single_package(alpm_handle_t *handle,
|
||||||
/* run the post-remove script if it exists */
|
/* run the post-remove script if it exists */
|
||||||
if(alpm_pkg_has_scriptlet(oldpkg) &&
|
if(alpm_pkg_has_scriptlet(oldpkg) &&
|
||||||
!(handle->trans->flags & ALPM_TRANS_FLAG_NOSCRIPTLET)) {
|
!(handle->trans->flags & ALPM_TRANS_FLAG_NOSCRIPTLET)) {
|
||||||
|
char *scriptlet = _alpm_local_db_pkgpath(handle->db_local,
|
||||||
|
oldpkg, "install");
|
||||||
_alpm_runscriptlet(handle, scriptlet, "post_remove", pkgver, NULL, 0);
|
_alpm_runscriptlet(handle, scriptlet, "post_remove", pkgver, NULL, 0);
|
||||||
|
free(scriptlet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue