xbps-bin: add -v flag, used when installing/removing currently.

--HG--
extra : convert_revision : d543b52213bf3d35b17ef29ff74a879bc4342cef
This commit is contained in:
Juan RP 2009-02-17 00:08:03 +01:00
parent 8d5e1ab017
commit fb998feacf
8 changed files with 83 additions and 63 deletions

View File

@ -52,6 +52,7 @@ usage(void)
" show\t<pkgname>\n"
" Options shared by all actions:\n"
" -r\t\t<rootdir>\n"
" -v\t\t<verbose>\n"
"\n"
" Examples:\n"
" $ xbps-bin install klibc\n"
@ -110,15 +111,18 @@ main(int argc, char **argv)
{
prop_dictionary_t dict;
char *plist, *root = NULL;
int c, rv = 0;
int c, flags = 0, rv = 0;
while ((c = getopt(argc, argv, "r:")) != -1) {
while ((c = getopt(argc, argv, "r:v")) != -1) {
switch (c) {
case 'r':
/* To specify the root directory */
root = optarg;
xbps_set_rootdir(root);
break;
case 'v':
flags |= XBPS_UNPACK_VERBOSE;
break;
case '?':
default:
usage();
@ -164,8 +168,8 @@ main(int argc, char **argv)
/* Install into root directory by default. */
if (strcasecmp(argv[0], "install") == 0) {
rv = xbps_install_binary_pkg(argv[1], root);
if (rv) {
rv = xbps_install_binary_pkg(argv[1], root, flags);
if (rv != 0 && rv != EEXIST) {
dict = xbps_get_pkg_deps_dictionary();
if (dict == NULL && errno == ENOENT)
printf("Unable to locate %s in "
@ -177,8 +181,8 @@ main(int argc, char **argv)
}
printf("Package %s installed successfully.\n", argv[1]);
} else {
rv = xbps_remove_binary_pkg(argv[1], root);
if (rv) {
rv = xbps_remove_binary_pkg(argv[1], root, flags);
if (rv != 0) {
if (errno == ENOENT)
printf("Package %s is not installed.\n",
argv[1]);

View File

@ -27,15 +27,14 @@
#define _XBPS_INSTALL_H_
/* From lib/install.c, lib/depends.c and lib/unpack.c */
int xbps_install_pkg_deps(prop_dictionary_t, const char *);
int xbps_install_binary_pkg(const char *, const char *);
int xbps_install_pkg_deps(prop_dictionary_t, const char *, int);
int xbps_install_binary_pkg(const char *, const char *, int);
int xbps_install_binary_pkg_fini(prop_dictionary_t, prop_dictionary_t,
const char *);
const char *, int);
int xbps_register_pkg(prop_dictionary_t, const char *, const char *,
const char *, bool);
int xbps_unpack_binary_pkg(prop_dictionary_t, prop_dictionary_t,
const char *,
void (*cb_print)(prop_dictionary_t));
const char *, int);
int xbps_update_pkg_requiredby(prop_array_t, prop_dictionary_t);
int xbps_find_deps_in_pkg(prop_dictionary_t);

View File

@ -27,7 +27,7 @@
#define _XBPS_REMOVE_H_
/* From lib/remove.c */
int xbps_remove_binary_pkg(const char *, const char *);
int xbps_remove_binary_pkg(const char *, const char *, int);
int xbps_unregister_pkg(const char *);
#endif /* !_XBPS_REMOVE_H_ */

View File

@ -50,6 +50,9 @@
/* Filename of the package properties plist file. */
#define XBPS_PKGPROPS "props.plist"
/* Unpack flags */
#define XBPS_UNPACK_VERBOSE 0x00000001
#include "cmpver.h"
#include "fexec.h"
#include "humanize_number.h"

View File

@ -301,6 +301,10 @@ xbps_find_deps_in_pkg(prop_dictionary_t pkg)
assert(pkg != NULL);
pkg_rdeps = prop_dictionary_get(pkg, "run_depends");
if (pkg_rdeps == NULL)
return 0;
/*
* Get the dictionary with the list of registered repositories.
*/
@ -330,8 +334,6 @@ xbps_find_deps_in_pkg(prop_dictionary_t pkg)
return ENOMEM;
}
pkg_rdeps = prop_dictionary_get(pkg, "run_depends");
/*
* Iterate over the repository pool and find out if we have
* all available binary packages.
@ -589,7 +591,7 @@ find_pkg_deps_from_repo(prop_dictionary_t repo, prop_dictionary_t pkg,
}
int
xbps_install_pkg_deps(prop_dictionary_t pkg, const char *destdir)
xbps_install_pkg_deps(prop_dictionary_t pkg, const char *destdir, int flags)
{
prop_array_t required, missing;
prop_object_t obj;
@ -623,7 +625,7 @@ xbps_install_pkg_deps(prop_dictionary_t pkg, const char *destdir)
* Install all required dependencies, previously sorted.
*/
while ((obj = prop_object_iterator_next(iter)) != NULL) {
rv = xbps_install_binary_pkg_fini(NULL, obj, destdir);
rv = xbps_install_binary_pkg_fini(NULL, obj, destdir, flags);
if (rv != 0)
break;
}

View File

@ -37,13 +37,14 @@
struct cbargs {
const char *destdir;
const char *pkgname;
int flags;
};
static int install_binpkg_repo_cb(prop_object_t, void *, bool *);
int
xbps_install_binary_pkg_fini(prop_dictionary_t repo, prop_dictionary_t pkg,
const char *destdir)
const char *destdir, int flags)
{
const char *pkgname, *version, *desc;
int rv = 0;
@ -65,23 +66,22 @@ xbps_install_binary_pkg_fini(prop_dictionary_t repo, prop_dictionary_t pkg,
(void)fflush(stdout);
rv = xbps_unpack_binary_pkg(repo, pkg, destdir, NULL);
rv = xbps_unpack_binary_pkg(repo, pkg, destdir, flags);
if (rv == 0) {
rv = xbps_register_pkg(pkg, pkgname, version, desc, automatic);
if (rv == EEXIST)
rv = 0;
if (rv != 0) {
printf("failed!\n");
return rv;
}
}
if (rv == 0)
printf("done.\n");
else
printf("failed!\n");
printf("done.\n");
return rv;
return 0;
}
int
xbps_install_binary_pkg(const char *pkgname, const char *destdir)
xbps_install_binary_pkg(const char *pkgname, const char *destdir, int flags)
{
struct cbargs cb;
int rv = 0;
@ -95,14 +95,15 @@ xbps_install_binary_pkg(const char *pkgname, const char *destdir)
cb.pkgname = pkgname;
cb.destdir = destdir;
cb.flags = flags;
/*
* Iterate over the repository pool and find out if we have
* all available binary packages.
*/
rv = xbps_callback_array_iter_in_repolist(install_binpkg_repo_cb,
(void *)&cb);
if (rv == 0 && errno == ENOENT)
rv = errno;
if (rv == 0 && errno == EAGAIN)
return ENOENT;
return rv;
}
@ -135,7 +136,7 @@ install_binpkg_repo_cb(prop_object_t obj, void *arg, bool *cbloop_done)
pkgrd = xbps_find_pkg_in_dict(repod, "packages", pkgname);
if (pkgrd == NULL) {
prop_object_release(repod);
errno = ENOENT;
errno = EAGAIN;
return 0;
}
@ -144,7 +145,8 @@ install_binpkg_repo_cb(prop_object_t obj, void *arg, bool *cbloop_done)
*/
if (!xbps_pkg_has_rundeps(pkgrd)) {
/* pkg has no deps, just install it. */
rv = xbps_install_binary_pkg_fini(repod, pkgrd, destdir);
rv = xbps_install_binary_pkg_fini(repod, pkgrd, destdir,
cb->flags);
prop_object_release(repod);
return rv;
}
@ -164,8 +166,9 @@ install_binpkg_repo_cb(prop_object_t obj, void *arg, bool *cbloop_done)
/*
* Install all required dependencies and the package itself.
*/
if ((rv = xbps_install_pkg_deps(pkgrd, destdir)) == 0) {
rv = xbps_install_binary_pkg_fini(repod, pkgrd, destdir);
if ((rv = xbps_install_pkg_deps(pkgrd, destdir, cb->flags)) == 0) {
rv = xbps_install_binary_pkg_fini(repod, pkgrd, destdir,
cb->flags);
prop_object_release(repod);
if (rv == 0)
*cbloop_done = true;

View File

@ -57,7 +57,7 @@ xbps_unregister_pkg(const char *pkgname)
}
static int
xbps_remove_binary_pkg_meta(const char *pkgname, const char *destdir)
xbps_remove_binary_pkg_meta(const char *pkgname, const char *destdir, int flags)
{
struct dirent *dp;
DIR *dirp;
@ -88,8 +88,9 @@ xbps_remove_binary_pkg_meta(const char *pkgname, const char *destdir)
}
if ((rv = unlink(path)) == -1) {
printf("WARNING: can't remove %s (%s)\n",
pkgname, strerror(errno));
if (flags & XBPS_UNPACK_VERBOSE)
printf("WARNING: can't remove %s (%s)\n",
pkgname, strerror(errno));
}
(void)memset(&path, 0, sizeof(path));
}
@ -100,7 +101,7 @@ xbps_remove_binary_pkg_meta(const char *pkgname, const char *destdir)
}
int
xbps_remove_binary_pkg(const char *pkgname, const char *destdir)
xbps_remove_binary_pkg(const char *pkgname, const char *destdir, int flags)
{
FILE *flist;
char path[PATH_MAX - 1], line[LINE_MAX - 1], *p, *buf;
@ -193,19 +194,23 @@ xbps_remove_binary_pkg(const char *pkgname, const char *destdir)
rv = 0;
goto next;
}
printf("WARNING: can't remove directory"
" %s (%s)\n", path, strerror(errno));
if (flags & XBPS_UNPACK_VERBOSE)
printf("WARNING: can't remove "
"directory %s (%s)\n",
path, strerror(errno));
goto next;
}
printf("Removed directory: %s\n", path);
if (flags & XBPS_UNPACK_VERBOSE)
printf("Removed directory: %s\n", path);
goto next;
}
printf("WARNING: can't remove file %s (%s)\n", path,
strerror(errno));
if (flags & XBPS_UNPACK_VERBOSE)
printf("WARNING: can't remove file %s (%s)\n", path,
strerror(errno));
goto next;
}
printf("Removed file: %s\n", path);
if (flags & XBPS_UNPACK_VERBOSE)
printf("Removed file: %s\n", path);
next:
free(p);
p = NULL;
@ -226,7 +231,7 @@ next:
out:
free(buf);
rv = xbps_remove_binary_pkg_meta(pkgname, destdir);
rv = xbps_remove_binary_pkg_meta(pkgname, destdir, flags);
return rv;
}

View File

@ -35,14 +35,14 @@
#include <xbps_api.h>
static int unpack_archive_init(prop_dictionary_t, const char *, const char *);
static int unpack_archive_fini(struct archive *, const char *,
static int unpack_archive_init(prop_dictionary_t, const char *,
const char *, int);
static int unpack_archive_fini(struct archive *, const char *, int,
prop_dictionary_t);
int
xbps_unpack_binary_pkg(prop_dictionary_t repo, prop_dictionary_t pkg,
const char *destdir,
void (*cb_print)(prop_dictionary_t))
const char *destdir, int flags)
{
prop_string_t filename, repoloc, arch;
char *binfile, *path;
@ -72,10 +72,7 @@ xbps_unpack_binary_pkg(prop_dictionary_t repo, prop_dictionary_t pkg,
}
free(path);
if (cb_print)
(*cb_print)(pkg);
rv = unpack_archive_init(pkg, destdir, binfile);
rv = unpack_archive_init(pkg, destdir, binfile, flags);
free(binfile);
return rv;
}
@ -83,7 +80,7 @@ xbps_unpack_binary_pkg(prop_dictionary_t repo, prop_dictionary_t pkg,
static int
unpack_archive_init(prop_dictionary_t pkg, const char *destdir,
const char *binfile)
const char *binfile, int flags)
{
struct archive *ar;
int pkg_fd, rv;
@ -111,7 +108,7 @@ unpack_archive_init(prop_dictionary_t pkg, const char *destdir,
return rv;
}
rv = unpack_archive_fini(ar, destdir, pkg);
rv = unpack_archive_fini(ar, destdir, flags, pkg);
/*
* If installation of package was successful, make sure the package
* is really on storage (if possible).
@ -139,7 +136,7 @@ unpack_archive_init(prop_dictionary_t pkg, const char *destdir,
* the consumer.
*/
static int
unpack_archive_fini(struct archive *ar, const char *destdir,
unpack_archive_fini(struct archive *ar, const char *destdir, int flags,
prop_dictionary_t pkg)
{
struct archive_entry *entry;
@ -148,7 +145,7 @@ unpack_archive_fini(struct archive *ar, const char *destdir,
const char *prepost = "./XBPS_PREPOST_INSTALL";
const char *pkgname, *version;
char *buf, *path;
int rv = 0, flags = 0;
int rv = 0, lflags = 0;
bool actgt = false;
assert(ar != NULL);
@ -158,9 +155,9 @@ unpack_archive_fini(struct archive *ar, const char *destdir,
prop_dictionary_get_cstring_nocopy(pkg, "version", &version);
if (getuid() == 0)
flags = FEXTRACT_FLAGS;
lflags = FEXTRACT_FLAGS;
else
flags = EXTRACT_FLAGS;
lflags = EXTRACT_FLAGS;
/*
* This length is '.%s/metadata/%s/prepost-inst' not
@ -205,7 +202,7 @@ unpack_archive_fini(struct archive *ar, const char *destdir,
archive_entry_set_pathname(entry, buf);
rv = archive_read_extract(ar, entry, flags);
rv = archive_read_extract(ar, entry, lflags);
if (rv != 0 && rv != EEXIST)
break;
@ -223,18 +220,25 @@ unpack_archive_fini(struct archive *ar, const char *destdir,
/*
* Extract all data from the archive now.
*/
rv = archive_read_extract(ar, entry, flags);
rv = archive_read_extract(ar, entry, lflags);
if (rv != 0 && rv != EEXIST) {
printf("\ncouldn't unpack %s (%s), exiting!\n",
archive_entry_pathname(entry), strerror(errno));
(void)fflush(stdout);
break;
} else if (rv == EEXIST) {
printf("\nignoring existent component %s.\n",
archive_entry_pathname(entry));
(void)fflush(stdout);
if (flags & XBPS_UNPACK_VERBOSE) {
printf("\nignoring existent component %s.\n",
archive_entry_pathname(entry));
(void)fflush(stdout);
}
continue;
}
if (flags & XBPS_UNPACK_VERBOSE) {
printf(" %s\n", archive_entry_pathname(entry));
(void)fflush(stdout);
}
}
if (rv == 0 && actgt) {