xbps_purge_pkg: chdir to rootdir, check that REMOVE file exists and is executable.

This commit is contained in:
Juan RP 2011-01-30 12:49:55 +01:00
parent 243685507a
commit 2492d98d13

View File

@ -171,24 +171,36 @@ xbps_purge_pkg(const char *pkgname, bool check_state)
/* /*
* Execute the purge action in REMOVE script (if found). * Execute the purge action in REMOVE script (if found).
*/ */
prop_dictionary_get_cstring_nocopy(pkgd, "version", &version); if (chdir(xbps_get_rootdir()) == -1) {
rv = errno;
prop_object_release(dict);
xbps_error_printf("[purge] %s: cannot change to rootdir: %s.\n",
pkgname, strerror(rv));
goto out;
}
buf = xbps_xasprintf(".%s/metadata/%s/REMOVE", XBPS_META_PATH, pkgname); buf = xbps_xasprintf(".%s/metadata/%s/REMOVE", XBPS_META_PATH, pkgname);
if (buf == NULL) { if (buf == NULL) {
prop_object_release(dict); prop_object_release(dict);
rv = ENOMEM; rv = ENOMEM;
goto out; goto out;
} }
if (xbps_file_exec(buf, "purge", if (access(buf, X_OK) == 0) {
pkgname, version, "no", NULL) != 0) { prop_dictionary_get_cstring_nocopy(pkgd, "version", &version);
free(buf);
if (errno && errno != ENOENT) { if (xbps_file_exec(buf, "purge",
rv = errno; pkgname, version, "no", NULL) != 0) {
xbps_error_printf("%s: purge action error in REMOVE " free(buf);
"script: %s\n", pkgname, strerror(errno)); if (errno && errno != ENOENT) {
prop_object_release(dict); rv = errno;
goto out; xbps_error_printf("%s: purge action error in "
"REMOVE script: %s\n", pkgname,
strerror(errno));
prop_object_release(dict);
goto out;
}
} }
} }
free(buf);
prop_object_release(dict); prop_object_release(dict);
/* /*
* Remove metadata dir and unregister package. * Remove metadata dir and unregister package.