Merged purge code in remove, configurable transaction regpkgdb flushing.

See the NEWS file for info.
This commit is contained in:
Juan RP
2011-12-24 01:05:26 +01:00
parent d7a32a7eca
commit 3b7491d29b
32 changed files with 613 additions and 818 deletions

View File

@@ -35,44 +35,6 @@
#include <xbps_api.h>
#include "defs.h"
static int
write_pkgd_to_regpkgdb(prop_dictionary_t pkgd,
prop_array_t regpkgs,
const char *pkgn)
{
struct xbps_handle *xhp = xbps_handle_get();
char *path;
int rv;
rv = xbps_array_replace_dict_by_name(regpkgs, pkgd, pkgn);
if (rv != 0) {
xbps_error_printf("%s: failed to replace pkgd: %s\n",
pkgn, strerror(rv));
return -1;
}
if (!prop_dictionary_set(xhp->regpkgdb_dictionary,
"packages", regpkgs)) {
xbps_error_printf("%s: failed to set new regpkgdb "
"packages array: %s", pkgn, strerror(errno));
return -1;
}
path = xbps_xasprintf("%s/%s/%s", xhp->rootdir,
XBPS_META_PATH, XBPS_REGPKGDB);
if (path == NULL)
return -1;
if (!prop_dictionary_externalize_to_zfile(
xhp->regpkgdb_dictionary, path)) {
xbps_error_printf("%s: failed to write regpkgdb plist:"
" %s\n", pkgn, strerror(errno));
free(path);
return -1;
}
free(path);
return 0;
}
/*
* Checks package integrity of an installed package.
* The following task is accomplished in this file:
@@ -94,6 +56,8 @@ check_pkg_requiredby(prop_dictionary_t pkgd_regpkgdb,
struct xbps_handle *xhp = xbps_handle_get();
const char *curpkgn, *pkgname, *pkgver;
size_t i;
int rv;
bool pkg_fixed = false;
(void)pkg_propsd;
(void)pkg_filesd;
@@ -101,7 +65,7 @@ check_pkg_requiredby(prop_dictionary_t pkgd_regpkgdb,
prop_dictionary_get_cstring_nocopy(pkgd_regpkgdb, "pkgname", &pkgname);
prop_dictionary_get_cstring_nocopy(pkgd_regpkgdb, "pkgver", &pkgver);
regpkgs = prop_dictionary_get(xhp->regpkgdb_dictionary, "packages");
regpkgs = prop_dictionary_get(xhp->regpkgdb, "packages");
for (i = 0; i < prop_array_count(regpkgs); i++) {
obj = prop_array_get(regpkgs, i);
@@ -181,13 +145,30 @@ check_pkg_requiredby(prop_dictionary_t pkgd_regpkgdb,
*/
prop_array_add(reqby, curpkgver);
prop_dictionary_set(pkgd_regpkgdb, "requiredby", reqby);
if (write_pkgd_to_regpkgdb(pkgd_regpkgdb, regpkgs, pkgname) != 0)
rv = xbps_array_replace_dict_by_name(regpkgs, obj, curpkgn);
if (rv != 0) {
xbps_error_printf("%s: failed to replace pkgd: %s\n",
curpkgn, strerror(rv));
return -1;
}
if (!prop_dictionary_set(xhp->regpkgdb, "packages", regpkgs)) {
xbps_error_printf("%s: failed to set new regpkgdb "
"packages array: %s", curpkgn, strerror(errno));
return -1;
}
pkg_fixed = true;
printf("%s: added requiredby entry for %s.\n",
pkgver, prop_string_cstring_nocopy(curpkgver));
prop_object_release(curpkg_propsd);
}
if (pkg_fixed == false)
return rv;
return 0;
if ((rv = xbps_regpkgdb_update(xhp, true)) != 0) {
xbps_error_printf("failed to write regpkgdb plist: "
" %s\n", strerror(rv));
return rv;
}
return rv;
}

View File

@@ -47,9 +47,9 @@ struct list_pkgver_cb {
/* from transaction.c */
int install_new_pkg(const char *, bool);
int update_pkg(const char *);
int remove_pkg(const char *, bool, bool);
int remove_pkg(const char *, bool);
int autoupdate_pkgs(bool, bool);
int autoremove_pkgs(bool, bool);
int autoremove_pkgs(bool);
int exec_transaction(bool, bool);
/* from remove.c */

View File

@@ -68,17 +68,17 @@ main(int argc, char **argv)
struct sigaction sa;
const char *rootdir, *cachedir, *conffile, *option;
int i, c, flags, rv;
bool yes, purge, debug, reqby_force, force_rm_with_deps, recursive_rm;
bool yes, debug, reqby_force, force_rm_with_deps, recursive_rm;
bool install_auto, install_manual, show_download_pkglist_url;
bool reinstall;
rootdir = cachedir = conffile = option = NULL;
flags = rv = 0;
reqby_force = yes = purge = force_rm_with_deps = false;
reqby_force = yes = force_rm_with_deps = false;
recursive_rm = debug = reinstall = false;
install_auto = install_manual = show_download_pkglist_url = false;
while ((c = getopt(argc, argv, "AC:c:dDFfMo:pRr:Vvy")) != -1) {
while ((c = getopt(argc, argv, "AC:c:dDFfMo:Rr:Vvy")) != -1) {
switch (c) {
case 'A':
install_auto = true;
@@ -109,9 +109,6 @@ main(int argc, char **argv)
case 'o':
option = optarg;
break;
case 'p':
purge = true;
break;
case 'R':
recursive_rm = true;
break;
@@ -147,15 +144,6 @@ main(int argc, char **argv)
exit(EXIT_FAILURE);
}
/*
* Register a signal handler to clean up resources used by libxbps.
*/
memset(&sa, 0, sizeof(sa));
sa.sa_handler = cleanup;
sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);
sigaction(SIGQUIT, &sa, NULL);
/*
* Initialize libxbps.
*/
@@ -185,6 +173,14 @@ main(int argc, char **argv)
exit(EXIT_FAILURE);
}
/*
* Register a signal handler to clean up resources used by libxbps.
*/
memset(&sa, 0, sizeof(sa));
sa.sa_handler = cleanup;
sigaction(SIGINT, &sa, NULL);
sigaction(SIGTERM, &sa, NULL);
if (strcasecmp(argv[0], "list") == 0) {
/* Lists packages currently registered in database. */
if (argc < 1 || argc > 2)
@@ -199,12 +195,12 @@ main(int argc, char **argv)
lpc.state = XBPS_PKG_STATE_HALF_UNPACKED;
else if (strcmp(argv[1], "unpacked") == 0)
lpc.state = XBPS_PKG_STATE_UNPACKED;
else if (strcmp(argv[1], "config-files") == 0)
lpc.state = XBPS_PKG_STATE_CONFIG_FILES;
else if (strcmp(argv[1], "half-removed") == 0)
lpc.state = XBPS_PKG_STATE_HALF_REMOVED;
else {
fprintf(stderr,
"E: invalid state `%s'. Accepted values: "
"config-files, unpacked, "
"half-removed, unpacked, half-unpacked, "
"installed [default]\n", argv[1]);
rv = -1;
goto out;
@@ -249,7 +245,7 @@ main(int argc, char **argv)
usage(xhp);
for (i = 1; i < argc; i++) {
rv = remove_pkg(argv[i], purge, recursive_rm);
rv = remove_pkg(argv[i], recursive_rm);
if (rv == 0)
continue;
else if (rv != EEXIST)
@@ -323,19 +319,7 @@ main(int argc, char **argv)
if (argc != 1)
usage(xhp);
rv = autoremove_pkgs(yes, purge);
} else if (strcasecmp(argv[0], "purge") == 0) {
/*
* Purge a package completely.
*/
if (argc != 2)
usage(xhp);
if (strcasecmp(argv[1], "all") == 0)
rv = xbps_purge_packages();
else
rv = xbps_purge_pkg(argv[1], true);
rv = autoremove_pkgs(yes);
} else if (strcasecmp(argv[0], "reconfigure") == 0) {
/*

View File

@@ -66,9 +66,6 @@ state_cb(const struct xbps_state_cb_data *xscd, void *cbdata)
case XBPS_STATE_REMOVE:
printf("Removing `%s-%s' ...\n", xscd->pkgname, xscd->version);
break;
case XBPS_STATE_PURGE:
printf("Purging `%s-%s' ...\n", xscd->pkgname, xscd->version);
break;
case XBPS_STATE_CONFIGURE:
printf("Configuring `%s-%s' ...\n", xscd->pkgname,
xscd->version);
@@ -125,21 +122,12 @@ state_cb(const struct xbps_state_cb_data *xscd, void *cbdata)
"(rootdir: %s).", xscd->pkgname, xscd->version,
xhp->rootdir);
break;
case XBPS_STATE_PURGE_DONE:
printf("Purged `%s-%s' successfully.\n",
xscd->pkgname, xscd->version);
if (xhp->syslog_enabled)
syslog(LOG_NOTICE, "Purged `%s-%s' successfully "
"(rootdir: %s).", xscd->pkgname, xscd->version,
xhp->rootdir);
break;
/* errors */
case XBPS_STATE_UNPACK_FAIL:
case XBPS_STATE_UPDATE_FAIL:
case XBPS_STATE_CONFIGURE_FAIL:
case XBPS_STATE_REGISTER_FAIL:
case XBPS_STATE_UNREGISTER_FAIL:
case XBPS_STATE_PURGE_FAIL:
case XBPS_STATE_REMOVE_FAIL:
case XBPS_STATE_VERIFY_FAIL:
case XBPS_STATE_DOWNLOAD_FAIL:

View File

@@ -222,11 +222,11 @@ autoupdate_pkgs(bool yes, bool show_download_pkglist_url)
}
int
autoremove_pkgs(bool yes, bool purge)
autoremove_pkgs(bool yes)
{
int rv = 0;
if ((rv = xbps_transaction_autoremove_pkgs(purge)) != 0) {
if ((rv = xbps_transaction_autoremove_pkgs()) != 0) {
if (rv == ENOENT) {
printf("No package orphans were found.\n");
return 0;
@@ -328,7 +328,7 @@ update_pkg(const char *pkgname)
}
int
remove_pkg(const char *pkgname, bool purge, bool recursive)
remove_pkg(const char *pkgname, bool recursive)
{
prop_dictionary_t pkgd;
prop_array_t reqby;
@@ -336,7 +336,7 @@ remove_pkg(const char *pkgname, bool purge, bool recursive)
size_t x;
int rv;
rv = xbps_transaction_remove_pkg(pkgname, purge, recursive);
rv = xbps_transaction_remove_pkg(pkgname, recursive);
if (rv == EEXIST) {
/* pkg has revdeps */
pkgd = xbps_find_pkg_dict_installed(pkgname, false);

View File

@@ -1,4 +1,4 @@
.Dd December 22, 2011
.Dd December 23, 2011
.Os Void GNU/Linux
.Dt xbps-bin 8
.Sh NAME
@@ -60,7 +60,6 @@ depending on it, i.e package is a dependency of any other installed package.
.It Fl f
Used currently in the
.Em install ,
.Em purge ,
.Em reconfigure
and
.Em remove
@@ -69,10 +68,8 @@ targets. If set, package(s) will be reconfigured regardless of its state in
target, or to
.Em force
removal of package files even if its hash does not match in the
.Em purge
and
.Em remove
targets. If set, package(s) will be reinstalled even if its state is
target. If set, package(s) will be reinstalled even if its state is
.Em installed
when used with the
.Em install
@@ -95,13 +92,6 @@ Used currently in the
target. Prints the value of specified key(s) from
package's properties dictionary. Multiple keys can be specified delimited by
the comma character.
.It Fl p
Used currently in the
.Em remove
and
.Em autoremove
targets. If enabled, after removing
a package it is also purged.
.It Fl R
Used currently in the
.Em remove
@@ -175,28 +165,14 @@ to list only packages with the specified
By default only packages fully installed will be listed if
.Em state
has not been specified. Accepted states are:
.Em config-files ,
.Em half-removed ,
.Em half-unpacked ,
.Em unpacked ,
.Em installed
and
.Em installed .
.Em unpacked .
.It Sy list-manual
Lists packages that were installed manually by the user, i.e not as dependencies
of any other package.
.It Sy purge Ar pkgname | Ar all
Purge an installed package:
.Em pkgname
or
.Em all
packages. The purge stage runs the post-remove action set in the REMOVE script
in its metadata directory
.Pa (/var/db/xbps/metadata/pkgname)
and will remove configuration (if they were not modified by the user) and
metadata files. The package will be fully removed from the system once it
has been purged. If
.Ql -f
option is used, configuration files that have been
.Em modified WILL BE REMOVED. BEWARE WITH THIS!
.It Sy reconfigure Ar pkgname | Ar all
Reconfigure an unpacked package. Packages in this state are not fully installed,
because they were not configured for whatever reason. The configure stage will
@@ -209,16 +185,7 @@ option is used, the package will be reconfigured even if its state is already in
.It Sy remove Ar pkgname(s)
Removes the installed package
.Em pkgname(s) .
Its files will be removed and its state will be changed to
.Em config-files
in the package database. Configuration files, its metadata directory/files and its
information in the package database are preserved. To fully remove a package in
.Em config-files
state, it must be purged with the
.Em purge
command or alternatively use the
.Ql -p
flag. If
Files not matching the original SHA256 hash will be preserved. If
.Ql -f
option is used, package files will be
.Em removed even if its SHA256 hash don't match .
@@ -257,10 +224,9 @@ target that will update all currently installed packages.
A package can be in a different state while it is being
.Em installed ,
.Em removed ,
.Em unpacked ,
.Em configured
.Em unpacked
or
.Em purged .
.Em configured .
The following states are available:
.Bl -tag -width ident
.It Sy installed
@@ -271,11 +237,13 @@ The package was being unpacked but didn't finish properly for unknown reasons.
The package has been unpacked in destination root directory, but it is not fully
installed because it was not yet configured. Please note that some packages will
do not work if they are only unpacked.
.It Sy config-files
The package has been removed but configuration files and its metadata directory
are still available (and it is still registered in the package database).
You can purge safely packages that are in this state, modified configuration
files will be preserved.
.It Sy half-remove
The package removal did not finish for unknown reasons (power outage, process killed, etc).
The
.Em purge
action in its metadata REMOVE script has not been yet executed. The package
metadata directory is still available and it is registered in package database.
Packages in this state can be still removed.
.Sh FILES
.Bl -tag -width /var/db/xbps/metadata/<pkgname>/props.plist -compact
.It Pa /etc/xbps/xbps.conf

View File

@@ -94,6 +94,7 @@ die(const char *fmt, ...)
vfprintf(stderr, fmt, ap);
fprintf(stderr, " (%s)\n", strerror(save_errno));
va_end(ap);
xbps_end(xbps_handle_get());
exit(EXIT_FAILURE);
}

View File

@@ -215,6 +215,9 @@ main(int argc, char **argv)
in_chroot ? "[chroot] " : "" , argv[1], argv[2],
strerror(rv), MSG_RESET);
} else {
if ((rv = xbps_regpkgdb_update(xhp, true)) != 0)
exit(EXIT_FAILURE);
printf("%s%s=> %s-%s registered successfully.%s\n",
MSG_NORMAL, in_chroot ? "[chroot] " : "",
argv[1], argv[2], MSG_RESET);