Added support to run pre/post remove actions with binpkgs.
--HG-- extra : convert_revision : ecc70358e9009a0b2f71aaccc5b8b1282417e3bf
This commit is contained in:
parent
4a9125364a
commit
edfeec4622
1 changed files with 58 additions and 10 deletions
68
lib/remove.c
68
lib/remove.c
|
@ -50,6 +50,8 @@ xbps_unregister_pkg(const char *pkgname)
|
||||||
if (!xbps_remove_pkg_dict_from_file(pkgname, plist))
|
if (!xbps_remove_pkg_dict_from_file(pkgname, plist))
|
||||||
rv = errno;
|
rv = errno;
|
||||||
|
|
||||||
|
free(plist);
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,23 +59,56 @@ int
|
||||||
xbps_remove_binary_pkg(const char *pkgname, const char *destdir)
|
xbps_remove_binary_pkg(const char *pkgname, const char *destdir)
|
||||||
{
|
{
|
||||||
FILE *flist;
|
FILE *flist;
|
||||||
char path[PATH_MAX - 1], line[LINE_MAX - 1], *p;
|
char path[PATH_MAX - 1], line[LINE_MAX - 1], *p, *buf;
|
||||||
int rv = 0;
|
int fd, rv = 0;
|
||||||
size_t len = 0;
|
size_t len = 0;
|
||||||
|
bool prepostf = false;
|
||||||
|
|
||||||
assert(pkgname != NULL);
|
assert(pkgname != NULL);
|
||||||
|
|
||||||
if (destdir) {
|
if (destdir == NULL)
|
||||||
if ((rv = chdir(destdir)) != 0)
|
|
||||||
return errno;
|
|
||||||
} else
|
|
||||||
destdir = "";
|
destdir = "";
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This length is '%s%s/metadata/%s/prepost-action' not
|
||||||
|
* including nul.
|
||||||
|
*/
|
||||||
|
len = strlen(XBPS_META_PATH) + strlen(destdir) + strlen(pkgname) + 26;
|
||||||
|
buf = malloc(len + 1);
|
||||||
|
if (buf == NULL)
|
||||||
|
return errno;
|
||||||
|
|
||||||
|
if (snprintf(buf, len + 1, "%s%s/metadata/%s/prepost-action",
|
||||||
|
destdir, XBPS_META_PATH, pkgname) < 0) {
|
||||||
|
free(buf);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Find out if the prepost-action file exists */
|
||||||
|
if ((fd = open(buf, O_RDONLY)) == -1) {
|
||||||
|
if (errno != ENOENT) {
|
||||||
|
rv = errno;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
/* Run the preremove action */
|
||||||
|
(void)close(fd);
|
||||||
|
prepostf = true;
|
||||||
|
if ((rv = xbps_file_exec(buf, destdir, "prerm", pkgname,
|
||||||
|
NULL)) != 0) {
|
||||||
|
printf("%s: prerm action target error (%s)\n", pkgname,
|
||||||
|
strerror(errno));
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
(void)snprintf(path, sizeof(path), "%s%s/metadata/%s/flist",
|
(void)snprintf(path, sizeof(path), "%s%s/metadata/%s/flist",
|
||||||
destdir, XBPS_META_PATH, pkgname);
|
destdir, XBPS_META_PATH, pkgname);
|
||||||
|
|
||||||
if ((flist = fopen(path, "r")) == NULL)
|
if ((flist = fopen(path, "r")) == NULL) {
|
||||||
return errno;
|
rv = errno;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
while (!feof(flist)) {
|
while (!feof(flist)) {
|
||||||
p = fgets(line, sizeof(line), flist);
|
p = fgets(line, sizeof(line), flist);
|
||||||
|
@ -127,9 +162,22 @@ next:
|
||||||
free(p);
|
free(p);
|
||||||
p = NULL;
|
p = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
(void)fclose(flist);
|
(void)fclose(flist);
|
||||||
|
|
||||||
/* If successful, unregister pkg from db */
|
/* If successful, unregister pkg from db */
|
||||||
return rv ? rv : xbps_unregister_pkg(pkgname);
|
if (rv == 0) {
|
||||||
|
if (((rv = xbps_unregister_pkg(pkgname)) == 0) && prepostf) {
|
||||||
|
/* Run the postremove action target */
|
||||||
|
if ((rv = xbps_file_exec(buf, destdir, "postrm",
|
||||||
|
pkgname, NULL)) != 0) {
|
||||||
|
printf("%s: postrm action target error (%s)\n",
|
||||||
|
pkgname, strerror(errno));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
out:
|
||||||
|
free(buf);
|
||||||
|
|
||||||
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue