Introduce xbps_xasprintf() and use it where required.
--HG-- extra : convert_revision : 324a92a4824476059e0993d00c2b925c732a79f8
This commit is contained in:
parent
f5dd58df5d
commit
4bf5c5f750
14 changed files with 108 additions and 175 deletions
|
@ -128,7 +128,7 @@ main(int argc, char **argv)
|
||||||
prop_array_t reqby, orphans;
|
prop_array_t reqby, orphans;
|
||||||
prop_object_t obj;
|
prop_object_t obj;
|
||||||
prop_object_iterator_t iter;
|
prop_object_iterator_t iter;
|
||||||
const char *pkgname, *version, *sep;
|
const char *pkgname, *version, *sep, *rootdir;
|
||||||
char *plist;
|
char *plist;
|
||||||
int c, flags = 0, rv = 0;
|
int c, flags = 0, rv = 0;
|
||||||
bool chkhash = false, forcerm = false, verbose = false;
|
bool chkhash = false, forcerm = false, verbose = false;
|
||||||
|
@ -169,7 +169,9 @@ main(int argc, char **argv)
|
||||||
if (argc != 1)
|
if (argc != 1)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
plist = xbps_append_full_path(true, NULL, XBPS_REGPKGDB);
|
rootdir = xbps_get_rootdir();
|
||||||
|
plist = xbps_xasprintf("%s/%s/%s", rootdir,
|
||||||
|
XBPS_META_PATH, XBPS_REGPKGDB);
|
||||||
if (plist == NULL)
|
if (plist == NULL)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
|
||||||
|
|
|
@ -114,7 +114,7 @@ main(int argc, char **argv)
|
||||||
if (argc < 1)
|
if (argc < 1)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
plist = xbps_append_full_path(true, NULL, XBPS_REGPKGDB);
|
plist = xbps_xasprintf("%s/%s/%s", root, XBPS_META_PATH, XBPS_REGPKGDB);
|
||||||
if (plist == NULL) {
|
if (plist == NULL) {
|
||||||
printf("=> ERROR: couldn't find regpkdb file (%s)\n",
|
printf("=> ERROR: couldn't find regpkdb file (%s)\n",
|
||||||
strerror(errno));
|
strerror(errno));
|
||||||
|
|
|
@ -262,7 +262,7 @@ xbps_repo_genindex(const char *pkgdir)
|
||||||
(strcmp(archdirs[i], "noarch")))
|
(strcmp(archdirs[i], "noarch")))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
path = xbps_append_full_path(false, pkgdir, archdirs[i]);
|
path = xbps_xasprintf("%s/%s", pkgdir, archdirs[i]);
|
||||||
if (path == NULL)
|
if (path == NULL)
|
||||||
return errno;
|
return errno;
|
||||||
|
|
||||||
|
@ -282,8 +282,7 @@ xbps_repo_genindex(const char *pkgdir)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
foundpkg = true;
|
foundpkg = true;
|
||||||
binfile = xbps_append_full_path(false, path,
|
binfile = xbps_xasprintf("%s/%s", path, dp->d_name);
|
||||||
dp->d_name);
|
|
||||||
if (binfile == NULL) {
|
if (binfile == NULL) {
|
||||||
(void)closedir(dirp);
|
(void)closedir(dirp);
|
||||||
free(path);
|
free(path);
|
||||||
|
|
|
@ -181,24 +181,15 @@ int
|
||||||
show_pkg_info_from_metadir(const char *pkgname)
|
show_pkg_info_from_metadir(const char *pkgname)
|
||||||
{
|
{
|
||||||
prop_dictionary_t pkgd;
|
prop_dictionary_t pkgd;
|
||||||
size_t len = 0;
|
const char *rootdir;
|
||||||
char *plist, *path;
|
char *plist;
|
||||||
|
|
||||||
/* XBPS_META_PATH/metadata/<pkgname> + NULL */
|
rootdir = xbps_get_rootdir();
|
||||||
len = strlen(XBPS_META_PATH) + strlen(pkgname) + 12;
|
plist = xbps_xasprintf("%s/%s/metadata/%s/%s", rootdir,
|
||||||
path = malloc(len);
|
XBPS_META_PATH, pkgname, XBPS_PKGPROPS);
|
||||||
if (path == NULL)
|
if (plist == NULL)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
(void)snprintf(path, len, "%s/metadata/%s", XBPS_META_PATH, pkgname);
|
|
||||||
|
|
||||||
plist = xbps_append_full_path(true, path, XBPS_PKGPROPS);
|
|
||||||
if (plist == NULL) {
|
|
||||||
free(path);
|
|
||||||
return EINVAL;
|
|
||||||
}
|
|
||||||
free(path);
|
|
||||||
|
|
||||||
pkgd = prop_dictionary_internalize_from_file(plist);
|
pkgd = prop_dictionary_internalize_from_file(plist);
|
||||||
if (pkgd == NULL) {
|
if (pkgd == NULL) {
|
||||||
free(plist);
|
free(plist);
|
||||||
|
@ -217,27 +208,15 @@ show_pkg_files_from_metadir(const char *pkgname, bool hash)
|
||||||
{
|
{
|
||||||
prop_dictionary_t pkgd;
|
prop_dictionary_t pkgd;
|
||||||
struct show_files_cb sfc;
|
struct show_files_cb sfc;
|
||||||
size_t len = 0;
|
|
||||||
const char *destdir = xbps_get_rootdir();
|
const char *destdir = xbps_get_rootdir();
|
||||||
char *plist, *path;
|
char *plist;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
/* XBPS_META_PATH/metadata/<pkgname>/XBPS_PKGFILES + NULL */
|
plist = xbps_xasprintf("%s/%s/metadata/%s/%s", destdir,
|
||||||
len = strlen(XBPS_META_PATH) + strlen(pkgname) +
|
XBPS_META_PATH, pkgname, XBPS_PKGFILES);
|
||||||
strlen(XBPS_PKGFILES) + 12;
|
if (plist == NULL)
|
||||||
path = malloc(len);
|
|
||||||
if (path == NULL)
|
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
(void)snprintf(path, len, "%s/metadata/%s", XBPS_META_PATH, pkgname);
|
|
||||||
|
|
||||||
plist = xbps_append_full_path(true, path, XBPS_PKGFILES);
|
|
||||||
if (plist == NULL) {
|
|
||||||
free(path);
|
|
||||||
return EINVAL;
|
|
||||||
}
|
|
||||||
free(path);
|
|
||||||
|
|
||||||
pkgd = prop_dictionary_internalize_from_file(plist);
|
pkgd = prop_dictionary_internalize_from_file(plist);
|
||||||
if (pkgd == NULL) {
|
if (pkgd == NULL) {
|
||||||
free(plist);
|
free(plist);
|
||||||
|
@ -277,7 +256,7 @@ show_pkg_files(prop_object_t obj, void *arg, bool *loop_done)
|
||||||
if (sfc->check_hash && file != NULL) {
|
if (sfc->check_hash && file != NULL) {
|
||||||
printf("%s", file);
|
printf("%s", file);
|
||||||
if (sfc->destdir) {
|
if (sfc->destdir) {
|
||||||
path = xbps_append_full_path(false, sfc->destdir, file);
|
path = xbps_xasprintf("%s/%s", sfc->destdir, file);
|
||||||
if (path == NULL)
|
if (path == NULL)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@
|
||||||
#define _XBPS_UTIL_H_
|
#define _XBPS_UTIL_H_
|
||||||
|
|
||||||
/* From lib/util.c */
|
/* From lib/util.c */
|
||||||
char * xbps_append_full_path(bool, const char *, const char *);
|
char * xbps_xasprintf(const char *, ...);
|
||||||
char * xbps_get_file_hash(const char *);
|
char * xbps_get_file_hash(const char *);
|
||||||
int xbps_check_file_hash(const char *, const char *);
|
int xbps_check_file_hash(const char *, const char *);
|
||||||
int xbps_check_pkg_file_hash(prop_dictionary_t, const char *);
|
int xbps_check_pkg_file_hash(prop_dictionary_t, const char *);
|
||||||
|
|
|
@ -93,14 +93,18 @@ xbps_install_binary_pkg(const char *pkgname, bool update)
|
||||||
prop_array_t array;
|
prop_array_t array;
|
||||||
prop_object_t obj;
|
prop_object_t obj;
|
||||||
prop_object_iterator_t repolist_iter;
|
prop_object_iterator_t repolist_iter;
|
||||||
size_t len = 0;
|
const char *repoloc, *instver, *rootdir;
|
||||||
const char *repoloc, *instver;
|
|
||||||
char *plist, *pkg;
|
char *plist, *pkg;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
assert(pkgname != NULL);
|
assert(pkgname != NULL);
|
||||||
|
|
||||||
plist = xbps_append_full_path(true, NULL, XBPS_REPOLIST);
|
rootdir = xbps_get_rootdir();
|
||||||
|
if (rootdir == NULL)
|
||||||
|
rootdir = "";
|
||||||
|
|
||||||
|
plist = xbps_xasprintf("%s/%s/%s", rootdir,
|
||||||
|
XBPS_META_PATH, XBPS_REPOLIST);
|
||||||
if (plist == NULL)
|
if (plist == NULL)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
|
@ -164,13 +168,11 @@ xbps_install_binary_pkg(const char *pkgname, bool update)
|
||||||
* installed, and return immediately in that case.
|
* installed, and return immediately in that case.
|
||||||
*/
|
*/
|
||||||
prop_dictionary_get_cstring_nocopy(pkgrd, "version", &instver);
|
prop_dictionary_get_cstring_nocopy(pkgrd, "version", &instver);
|
||||||
len = strlen(pkgname) + strlen(instver) + 2;
|
pkg = xbps_xasprintf("%s-%s", pkgname, instver);
|
||||||
pkg = malloc(len);
|
|
||||||
if (pkg == NULL) {
|
if (pkg == NULL) {
|
||||||
rv = errno;
|
rv = errno;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
(void)snprintf(pkg, len, "%s-%s", pkgname, instver);
|
|
||||||
if (xbps_check_is_installed_pkg(pkg) == 0) {
|
if (xbps_check_is_installed_pkg(pkg) == 0) {
|
||||||
free(pkg);
|
free(pkg);
|
||||||
rv = EEXIST;
|
rv = EEXIST;
|
||||||
|
@ -243,11 +245,13 @@ xbps_register_pkg(prop_dictionary_t pkgrd, bool update, bool automatic)
|
||||||
{
|
{
|
||||||
prop_dictionary_t dict, pkgd, newpkgd;
|
prop_dictionary_t dict, pkgd, newpkgd;
|
||||||
prop_array_t array;
|
prop_array_t array;
|
||||||
const char *pkgname, *version, *desc;
|
const char *pkgname, *version, *desc, *rootdir;
|
||||||
char *plist;
|
char *plist;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
plist = xbps_append_full_path(true, NULL, XBPS_REGPKGDB);
|
rootdir = xbps_get_rootdir();
|
||||||
|
plist = xbps_xasprintf("%s/%s/%s", rootdir,
|
||||||
|
XBPS_META_PATH, XBPS_REGPKGDB);
|
||||||
if (plist == NULL)
|
if (plist == NULL)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
|
|
|
@ -66,7 +66,6 @@ find_indirect_orphan_pkg(prop_object_t obj, void *arg, bool *loop_done)
|
||||||
{
|
{
|
||||||
struct orphan *orphan = arg;
|
struct orphan *orphan = arg;
|
||||||
prop_array_t reqby;
|
prop_array_t reqby;
|
||||||
size_t len = 0;
|
|
||||||
char *pkg;
|
char *pkg;
|
||||||
bool automatic = false;
|
bool automatic = false;
|
||||||
|
|
||||||
|
@ -82,13 +81,10 @@ find_indirect_orphan_pkg(prop_object_t obj, void *arg, bool *loop_done)
|
||||||
if (reqby == NULL || prop_array_count(reqby) != 1)
|
if (reqby == NULL || prop_array_count(reqby) != 1)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
len = strlen(orphan->pkgname) + strlen(orphan->version) + 2;
|
pkg = xbps_xasprintf("%s-%s", orphan->pkgname, orphan->version);
|
||||||
pkg = malloc(len);
|
|
||||||
if (pkg == NULL)
|
if (pkg == NULL)
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
|
|
||||||
(void)snprintf(pkg, len, "%s-%s", orphan->pkgname, orphan->version);
|
|
||||||
|
|
||||||
if (xbps_find_string_in_array(reqby, pkg)) {
|
if (xbps_find_string_in_array(reqby, pkg)) {
|
||||||
if (!prop_array_add(orphan->array, obj)) {
|
if (!prop_array_add(orphan->array, obj)) {
|
||||||
free(pkg);
|
free(pkg);
|
||||||
|
@ -107,10 +103,13 @@ xbps_find_orphan_packages(void)
|
||||||
prop_object_t obj;
|
prop_object_t obj;
|
||||||
prop_object_iterator_t iter;
|
prop_object_iterator_t iter;
|
||||||
struct orphan orphan;
|
struct orphan orphan;
|
||||||
|
const char *rootdir;
|
||||||
char *plist;
|
char *plist;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
plist = xbps_append_full_path(true, NULL, XBPS_REGPKGDB);
|
rootdir = xbps_get_rootdir();
|
||||||
|
plist = xbps_xasprintf("%s/%s/%s", rootdir,
|
||||||
|
XBPS_META_PATH, XBPS_REGPKGDB);
|
||||||
if (plist == NULL)
|
if (plist == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
|
10
lib/plist.c
10
lib/plist.c
|
@ -70,12 +70,15 @@ xbps_callback_array_iter_in_repolist(int (*fn)(prop_object_t, void *, bool *),
|
||||||
void *arg)
|
void *arg)
|
||||||
{
|
{
|
||||||
prop_dictionary_t repolistd;
|
prop_dictionary_t repolistd;
|
||||||
|
const char *rootdir;
|
||||||
char *plist;
|
char *plist;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
assert(fn != NULL);
|
assert(fn != NULL);
|
||||||
|
|
||||||
plist = xbps_append_full_path(true, NULL, XBPS_REPOLIST);
|
rootdir = xbps_get_rootdir();
|
||||||
|
plist = xbps_xasprintf("%s/%s/%s", rootdir,
|
||||||
|
XBPS_META_PATH, XBPS_REPOLIST);
|
||||||
if (plist == NULL)
|
if (plist == NULL)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
|
@ -158,9 +161,12 @@ prop_dictionary_t
|
||||||
xbps_find_pkg_installed_from_plist(const char *pkgname)
|
xbps_find_pkg_installed_from_plist(const char *pkgname)
|
||||||
{
|
{
|
||||||
prop_dictionary_t pkgd;
|
prop_dictionary_t pkgd;
|
||||||
|
const char *rootdir;
|
||||||
char *plist;
|
char *plist;
|
||||||
|
|
||||||
plist = xbps_append_full_path(true, NULL, XBPS_REGPKGDB);
|
rootdir = xbps_get_rootdir();
|
||||||
|
plist = xbps_xasprintf("%s/%s/%s", rootdir,
|
||||||
|
XBPS_META_PATH, XBPS_REGPKGDB);
|
||||||
if (plist == NULL)
|
if (plist == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
|
56
lib/remove.c
56
lib/remove.c
|
@ -41,12 +41,15 @@ static int remove_pkg_files(prop_object_t, void *, bool *);
|
||||||
int
|
int
|
||||||
xbps_unregister_pkg(const char *pkgname)
|
xbps_unregister_pkg(const char *pkgname)
|
||||||
{
|
{
|
||||||
|
const char *rootdir;
|
||||||
char *plist;
|
char *plist;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
assert(pkgname != NULL);
|
assert(pkgname != NULL);
|
||||||
|
|
||||||
plist = xbps_append_full_path(true, NULL, XBPS_REGPKGDB);
|
rootdir = xbps_get_rootdir();
|
||||||
|
plist = xbps_xasprintf("%s/%s/%s", rootdir,
|
||||||
|
XBPS_META_PATH, XBPS_REGPKGDB);
|
||||||
if (plist == NULL)
|
if (plist == NULL)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
|
@ -63,18 +66,19 @@ xbps_remove_binary_pkg_meta(const char *pkgname)
|
||||||
{
|
{
|
||||||
struct dirent *dp;
|
struct dirent *dp;
|
||||||
DIR *dirp;
|
DIR *dirp;
|
||||||
const char *rootdir = xbps_get_rootdir();
|
const char *rootdir;
|
||||||
char metadir[PATH_MAX - 1], path[PATH_MAX - 1];
|
char *metadir, *path;
|
||||||
int flags = 0, rv = 0;
|
int flags = 0, rv = 0;
|
||||||
|
|
||||||
assert(pkgname != NULL);
|
assert(pkgname != NULL);
|
||||||
|
|
||||||
rootdir = xbps_get_rootdir();
|
rootdir = xbps_get_rootdir();
|
||||||
if (rootdir == NULL)
|
|
||||||
rootdir = "";
|
|
||||||
flags = xbps_get_flags();
|
flags = xbps_get_flags();
|
||||||
|
|
||||||
(void)snprintf(metadir, sizeof(metadir), "%s%s/metadata/%s",
|
metadir = xbps_xasprintf("%s/%s/metadata/%s", rootdir,
|
||||||
rootdir, XBPS_META_PATH, pkgname);
|
XBPS_META_PATH, pkgname);
|
||||||
|
if (metadir == NULL)
|
||||||
|
return errno;
|
||||||
|
|
||||||
dirp = opendir(metadir);
|
dirp = opendir(metadir);
|
||||||
if (dirp == NULL)
|
if (dirp == NULL)
|
||||||
|
@ -85,9 +89,10 @@ xbps_remove_binary_pkg_meta(const char *pkgname)
|
||||||
(strcmp(dp->d_name, "..") == 0))
|
(strcmp(dp->d_name, "..") == 0))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (snprintf(path, sizeof(path), "%s%s/metadata/%s/%s",
|
path = xbps_xasprintf("%s/%s", metadir, dp->d_name);
|
||||||
rootdir, XBPS_META_PATH, pkgname, dp->d_name) < 0) {
|
if (path == NULL) {
|
||||||
(void)closedir(dirp);
|
(void)closedir(dirp);
|
||||||
|
free(metadir);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,10 +101,11 @@ xbps_remove_binary_pkg_meta(const char *pkgname)
|
||||||
printf("WARNING: can't remove %s (%s)\n",
|
printf("WARNING: can't remove %s (%s)\n",
|
||||||
pkgname, strerror(errno));
|
pkgname, strerror(errno));
|
||||||
}
|
}
|
||||||
(void)memset(&path, 0, sizeof(path));
|
free(path);
|
||||||
}
|
}
|
||||||
(void)closedir(dirp);
|
(void)closedir(dirp);
|
||||||
rv = rmdir(metadir);
|
rv = rmdir(metadir);
|
||||||
|
free(metadir);
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
@ -108,7 +114,7 @@ static int
|
||||||
remove_pkg_files(prop_object_t obj, void *arg, bool *loop_done)
|
remove_pkg_files(prop_object_t obj, void *arg, bool *loop_done)
|
||||||
{
|
{
|
||||||
prop_bool_t bobj;
|
prop_bool_t bobj;
|
||||||
const char *file = NULL, *rootdir, *sha256, *type;
|
const char *file, *rootdir, *sha256, *type;
|
||||||
char *path = NULL;
|
char *path = NULL;
|
||||||
int flags = 0, rv = 0;
|
int flags = 0, rv = 0;
|
||||||
|
|
||||||
|
@ -116,14 +122,12 @@ remove_pkg_files(prop_object_t obj, void *arg, bool *loop_done)
|
||||||
(void)loop_done;
|
(void)loop_done;
|
||||||
|
|
||||||
rootdir = xbps_get_rootdir();
|
rootdir = xbps_get_rootdir();
|
||||||
if (rootdir == NULL)
|
|
||||||
rootdir = "";
|
|
||||||
flags = xbps_get_flags();
|
flags = xbps_get_flags();
|
||||||
|
|
||||||
if (!prop_dictionary_get_cstring_nocopy(obj, "file", &file))
|
if (!prop_dictionary_get_cstring_nocopy(obj, "file", &file))
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
path = xbps_append_full_path(false, rootdir, file);
|
path = xbps_xasprintf("%s/%s", rootdir, file);
|
||||||
if (path == NULL)
|
if (path == NULL)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
|
@ -209,9 +213,8 @@ xbps_remove_binary_pkg(const char *pkgname, bool update)
|
||||||
{
|
{
|
||||||
prop_dictionary_t dict;
|
prop_dictionary_t dict;
|
||||||
const char *rootdir = xbps_get_rootdir();
|
const char *rootdir = xbps_get_rootdir();
|
||||||
char path[PATH_MAX - 1], *buf;
|
char *path, *buf;
|
||||||
int fd, rv = 0;
|
int fd, rv = 0;
|
||||||
size_t len = 0;
|
|
||||||
bool prepostf = false;
|
bool prepostf = false;
|
||||||
|
|
||||||
assert(pkgname != NULL);
|
assert(pkgname != NULL);
|
||||||
|
@ -229,20 +232,11 @@ xbps_remove_binary_pkg(const char *pkgname, bool update)
|
||||||
if (xbps_check_is_installed_pkgname(pkgname) == false)
|
if (xbps_check_is_installed_pkgname(pkgname) == false)
|
||||||
return ENOENT;
|
return ENOENT;
|
||||||
|
|
||||||
/*
|
buf = xbps_xasprintf("%s/%s/metadata/%s/REMOVE", rootdir,
|
||||||
* This length is '%s%s/metadata/%s/REMOVE' + NULL.
|
XBPS_META_PATH, pkgname);
|
||||||
*/
|
|
||||||
len = strlen(XBPS_META_PATH) + strlen(rootdir) + strlen(pkgname) + 19;
|
|
||||||
buf = malloc(len);
|
|
||||||
if (buf == NULL)
|
if (buf == NULL)
|
||||||
return errno;
|
return errno;
|
||||||
|
|
||||||
if (snprintf(buf, len, "%s%s/metadata/%s/REMOVE",
|
|
||||||
rootdir, XBPS_META_PATH, pkgname) < 0) {
|
|
||||||
free(buf);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Find out if the REMOVE file exists.
|
* Find out if the REMOVE file exists.
|
||||||
*/
|
*/
|
||||||
|
@ -272,14 +266,20 @@ xbps_remove_binary_pkg(const char *pkgname, bool update)
|
||||||
* Iterate over the pkg file list dictionary and remove all
|
* Iterate over the pkg file list dictionary and remove all
|
||||||
* files/dirs associated.
|
* files/dirs associated.
|
||||||
*/
|
*/
|
||||||
(void)snprintf(path, sizeof(path), "%s%s/metadata/%s/files.plist",
|
path = xbps_xasprintf("%s/%s/metadata/%s/files.plist",
|
||||||
rootdir, XBPS_META_PATH, pkgname);
|
rootdir, XBPS_META_PATH, pkgname);
|
||||||
|
if (path == NULL) {
|
||||||
|
free(buf);
|
||||||
|
return errno;
|
||||||
|
}
|
||||||
|
|
||||||
dict = prop_dictionary_internalize_from_file(path);
|
dict = prop_dictionary_internalize_from_file(path);
|
||||||
if (dict == NULL) {
|
if (dict == NULL) {
|
||||||
free(buf);
|
free(buf);
|
||||||
|
free(path);
|
||||||
return errno;
|
return errno;
|
||||||
}
|
}
|
||||||
|
free(path);
|
||||||
|
|
||||||
rv = xbps_callback_array_iter_in_dict(dict, "filelist",
|
rv = xbps_callback_array_iter_in_dict(dict, "filelist",
|
||||||
remove_pkg_files, NULL);
|
remove_pkg_files, NULL);
|
||||||
|
|
|
@ -39,12 +39,15 @@ xbps_register_repository(const char *uri)
|
||||||
prop_dictionary_t dict;
|
prop_dictionary_t dict;
|
||||||
prop_array_t array;
|
prop_array_t array;
|
||||||
prop_object_t obj = NULL;
|
prop_object_t obj = NULL;
|
||||||
|
const char *rootdir;
|
||||||
char *plist;
|
char *plist;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
assert(uri != NULL);
|
assert(uri != NULL);
|
||||||
|
|
||||||
plist = xbps_append_full_path(true, NULL, XBPS_REPOLIST);
|
rootdir = xbps_get_rootdir();
|
||||||
|
plist = xbps_xasprintf("%s/%s/%s", rootdir,
|
||||||
|
XBPS_META_PATH, XBPS_REPOLIST);
|
||||||
if (plist == NULL)
|
if (plist == NULL)
|
||||||
return errno;
|
return errno;
|
||||||
|
|
||||||
|
@ -112,12 +115,15 @@ xbps_unregister_repository(const char *uri)
|
||||||
{
|
{
|
||||||
prop_dictionary_t dict;
|
prop_dictionary_t dict;
|
||||||
prop_array_t array;
|
prop_array_t array;
|
||||||
|
const char *rootdir;
|
||||||
char *plist;
|
char *plist;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
assert(uri != NULL);
|
assert(uri != NULL);
|
||||||
|
|
||||||
plist = xbps_append_full_path(true, NULL, XBPS_REPOLIST);
|
rootdir = xbps_get_rootdir();
|
||||||
|
plist = xbps_xasprintf("%s/%s/%s", rootdir,
|
||||||
|
XBPS_META_PATH, XBPS_REPOLIST);
|
||||||
if (plist == NULL)
|
if (plist == NULL)
|
||||||
return errno;
|
return errno;
|
||||||
|
|
||||||
|
|
|
@ -161,10 +161,13 @@ int
|
||||||
xbps_requiredby_pkg_remove(const char *pkgname)
|
xbps_requiredby_pkg_remove(const char *pkgname)
|
||||||
{
|
{
|
||||||
prop_dictionary_t dict;
|
prop_dictionary_t dict;
|
||||||
|
const char *rootdir;
|
||||||
char *plist;
|
char *plist;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
plist = xbps_append_full_path(true, NULL, XBPS_REGPKGDB);
|
rootdir = xbps_get_rootdir();
|
||||||
|
plist = xbps_xasprintf("%s/%s/%s", rootdir,
|
||||||
|
XBPS_META_PATH, XBPS_REGPKGDB);
|
||||||
if (plist == NULL)
|
if (plist == NULL)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
|
@ -193,20 +196,16 @@ xbps_requiredby_pkg_add(prop_array_t regar, prop_dictionary_t pkg, bool update)
|
||||||
prop_array_t rdeps;
|
prop_array_t rdeps;
|
||||||
prop_object_t obj, obj2;
|
prop_object_t obj, obj2;
|
||||||
prop_object_iterator_t iter, iter2;
|
prop_object_iterator_t iter, iter2;
|
||||||
size_t len = 0;
|
|
||||||
const char *reqname, *pkgname, *version;
|
const char *reqname, *pkgname, *version;
|
||||||
char *rdepname, *fpkgn;
|
char *rdepname, *fpkgn;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
prop_dictionary_get_cstring_nocopy(pkg, "pkgname", &pkgname);
|
prop_dictionary_get_cstring_nocopy(pkg, "pkgname", &pkgname);
|
||||||
prop_dictionary_get_cstring_nocopy(pkg, "version", &version);
|
prop_dictionary_get_cstring_nocopy(pkg, "version", &version);
|
||||||
len = strlen(pkgname) + strlen(version) + 2;
|
fpkgn = xbps_xasprintf("%s-%s", pkgname, version);
|
||||||
fpkgn = malloc(len);
|
|
||||||
if (fpkgn == NULL)
|
if (fpkgn == NULL)
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
|
|
||||||
(void)snprintf(fpkgn, len, "%s-%s", pkgname, version);
|
|
||||||
|
|
||||||
rdeps = prop_dictionary_get(pkg, "run_depends");
|
rdeps = prop_dictionary_get(pkg, "run_depends");
|
||||||
if (rdeps == NULL || prop_array_count(rdeps) == 0) {
|
if (rdeps == NULL || prop_array_count(rdeps) == 0) {
|
||||||
free(fpkgn);
|
free(fpkgn);
|
||||||
|
|
31
lib/unpack.c
31
lib/unpack.c
|
@ -42,7 +42,7 @@ int
|
||||||
xbps_unpack_binary_pkg(prop_dictionary_t repo, prop_dictionary_t pkg)
|
xbps_unpack_binary_pkg(prop_dictionary_t repo, prop_dictionary_t pkg)
|
||||||
{
|
{
|
||||||
prop_string_t filename, repoloc, arch;
|
prop_string_t filename, repoloc, arch;
|
||||||
char *binfile, *path;
|
char *binfile;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
assert(pkg != NULL);
|
assert(pkg != NULL);
|
||||||
|
@ -55,19 +55,12 @@ xbps_unpack_binary_pkg(prop_dictionary_t repo, prop_dictionary_t pkg)
|
||||||
else
|
else
|
||||||
repoloc = prop_dictionary_get(pkg, "repository");
|
repoloc = prop_dictionary_get(pkg, "repository");
|
||||||
|
|
||||||
path = xbps_append_full_path(false,
|
binfile = xbps_xasprintf("%s/%s/%s",
|
||||||
prop_string_cstring_nocopy(repoloc),
|
prop_string_cstring_nocopy(repoloc),
|
||||||
prop_string_cstring_nocopy(arch));
|
prop_string_cstring_nocopy(arch),
|
||||||
if (path == NULL)
|
|
||||||
return EINVAL;
|
|
||||||
|
|
||||||
binfile = xbps_append_full_path(false, path,
|
|
||||||
prop_string_cstring_nocopy(filename));
|
prop_string_cstring_nocopy(filename));
|
||||||
if (binfile == NULL) {
|
if (binfile == NULL)
|
||||||
free(path);
|
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
}
|
|
||||||
free(path);
|
|
||||||
|
|
||||||
rv = unpack_archive_init(pkg, binfile);
|
rv = unpack_archive_init(pkg, binfile);
|
||||||
free(binfile);
|
free(binfile);
|
||||||
|
@ -136,7 +129,6 @@ static int
|
||||||
unpack_archive_fini(struct archive *ar, prop_dictionary_t pkg)
|
unpack_archive_fini(struct archive *ar, prop_dictionary_t pkg)
|
||||||
{
|
{
|
||||||
struct archive_entry *entry;
|
struct archive_entry *entry;
|
||||||
size_t len;
|
|
||||||
const char *prepost = "./INSTALL";
|
const char *prepost = "./INSTALL";
|
||||||
const char *pkgname, *version, *rootdir;
|
const char *pkgname, *version, *rootdir;
|
||||||
char *buf;
|
char *buf;
|
||||||
|
@ -154,7 +146,6 @@ unpack_archive_fini(struct archive *ar, prop_dictionary_t pkg)
|
||||||
} else {
|
} else {
|
||||||
if (chdir("/") == -1)
|
if (chdir("/") == -1)
|
||||||
return errno;
|
return errno;
|
||||||
rootdir = "";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
prop_dictionary_get_cstring_nocopy(pkg, "pkgname", &pkgname);
|
prop_dictionary_get_cstring_nocopy(pkg, "pkgname", &pkgname);
|
||||||
|
@ -165,19 +156,11 @@ unpack_archive_fini(struct archive *ar, prop_dictionary_t pkg)
|
||||||
else
|
else
|
||||||
lflags = EXTRACT_FLAGS;
|
lflags = EXTRACT_FLAGS;
|
||||||
|
|
||||||
/*
|
buf = xbps_xasprintf(".%s/metadata/%s/INSTALL",
|
||||||
* This length is '.%s/metadata/%s/INSTALL' + NULL.
|
XBPS_META_PATH, pkgname);
|
||||||
*/
|
|
||||||
len = strlen(XBPS_META_PATH) + strlen(pkgname) + 20;
|
|
||||||
buf = malloc(len);
|
|
||||||
if (buf == NULL)
|
if (buf == NULL)
|
||||||
return ENOMEM;
|
return errno;
|
||||||
|
|
||||||
if (snprintf(buf, len, ".%s/metadata/%s/INSTALL",
|
|
||||||
XBPS_META_PATH, pkgname) < 0) {
|
|
||||||
free(buf);
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
while (archive_read_next_header(ar, &entry) == ARCHIVE_OK) {
|
while (archive_read_next_header(ar, &entry) == ARCHIVE_OK) {
|
||||||
/*
|
/*
|
||||||
* Run the pre installation action target if there's a script
|
* Run the pre installation action target if there's a script
|
||||||
|
|
75
lib/util.c
75
lib/util.c
|
@ -26,6 +26,7 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#include <stdarg.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
@ -80,7 +81,7 @@ int
|
||||||
xbps_check_pkg_file_hash(prop_dictionary_t pkgd, const char *repoloc)
|
xbps_check_pkg_file_hash(prop_dictionary_t pkgd, const char *repoloc)
|
||||||
{
|
{
|
||||||
const char *sha256, *arch, *filename;
|
const char *sha256, *arch, *filename;
|
||||||
char *binfile, *path;
|
char *binfile;
|
||||||
int rv = 0;
|
int rv = 0;
|
||||||
|
|
||||||
assert(repoloc != NULL);
|
assert(repoloc != NULL);
|
||||||
|
@ -95,17 +96,10 @@ xbps_check_pkg_file_hash(prop_dictionary_t pkgd, const char *repoloc)
|
||||||
if (!prop_dictionary_get_cstring_nocopy(pkgd, "architecture", &arch))
|
if (!prop_dictionary_get_cstring_nocopy(pkgd, "architecture", &arch))
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
path = xbps_append_full_path(false, repoloc, arch);
|
binfile = xbps_xasprintf("%s/%s/%s", repoloc, arch, filename);
|
||||||
if (path == NULL)
|
if (binfile == NULL)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
binfile = xbps_append_full_path(false, path, filename);
|
|
||||||
if (binfile == NULL) {
|
|
||||||
free(path);
|
|
||||||
return EINVAL;
|
|
||||||
}
|
|
||||||
free(path);
|
|
||||||
|
|
||||||
printf("Checking SHA256 for %s ... ", filename);
|
printf("Checking SHA256 for %s ... ", filename);
|
||||||
(void)fflush(stdout);
|
(void)fflush(stdout);
|
||||||
|
|
||||||
|
@ -212,25 +206,13 @@ char *
|
||||||
xbps_get_pkg_index_plist(const char *path)
|
xbps_get_pkg_index_plist(const char *path)
|
||||||
{
|
{
|
||||||
struct utsname un;
|
struct utsname un;
|
||||||
char *plist, *p;
|
|
||||||
|
|
||||||
assert(path != NULL);
|
assert(path != NULL);
|
||||||
|
|
||||||
if (uname(&un) == -1)
|
if (uname(&un) == -1)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
p = xbps_append_full_path(false, path, un.machine);
|
return xbps_xasprintf("%s/%s/%s", path, un.machine, XBPS_PKGINDEX);
|
||||||
if (p == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
plist = xbps_append_full_path(false, p, XBPS_PKGINDEX);
|
|
||||||
if (plist == NULL) {
|
|
||||||
free(p);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
free(p);
|
|
||||||
|
|
||||||
return plist;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
@ -256,6 +238,9 @@ xbps_set_rootdir(const char *dir)
|
||||||
const char *
|
const char *
|
||||||
xbps_get_rootdir(void)
|
xbps_get_rootdir(void)
|
||||||
{
|
{
|
||||||
|
if (rootdir == NULL)
|
||||||
|
rootdir = "";
|
||||||
|
|
||||||
return rootdir;
|
return rootdir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -272,45 +257,15 @@ xbps_get_flags(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
char *
|
char *
|
||||||
xbps_append_full_path(bool use_rootdir, const char *basedir, const char *plist)
|
xbps_xasprintf(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
const char *env;
|
va_list ap;
|
||||||
char *buf = NULL;
|
char *buf;
|
||||||
size_t len = 0;
|
|
||||||
|
|
||||||
assert(plist != NULL);
|
va_start(ap, fmt);
|
||||||
|
if (vasprintf(&buf, fmt, ap) == -1)
|
||||||
if (basedir)
|
return NULL;
|
||||||
env = basedir;
|
va_end(ap);
|
||||||
else
|
|
||||||
env = XBPS_META_PATH;
|
|
||||||
|
|
||||||
if (rootdir && use_rootdir) {
|
|
||||||
len = strlen(rootdir) + strlen(env) + strlen(plist) + 2;
|
|
||||||
buf = malloc(len + 1);
|
|
||||||
if (buf == NULL) {
|
|
||||||
errno = ENOMEM;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (snprintf(buf, len + 1, "%s/%s/%s",
|
|
||||||
rootdir, env, plist) < 0) {
|
|
||||||
errno = ENOSPC;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
len = strlen(env) + strlen(plist) + 1;
|
|
||||||
buf = malloc(len + 1);
|
|
||||||
if (buf == NULL) {
|
|
||||||
errno = ENOMEM;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (snprintf(buf, len + 1, "%s/%s", env, plist) < 0) {
|
|
||||||
errno = ENOSPC;
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|
1
vars.mk
1
vars.mk
|
@ -9,6 +9,7 @@ INSTALL_STRIPPED ?= -s
|
||||||
|
|
||||||
LDFLAGS += -L$(TOPDIR)/lib -L$(PREFIX)/lib -lxbps
|
LDFLAGS += -L$(TOPDIR)/lib -L$(PREFIX)/lib -lxbps
|
||||||
CPPFLAGS += -I$(TOPDIR)/include -D_BSD_SOURCE -D_XOPEN_SOURCE=600
|
CPPFLAGS += -I$(TOPDIR)/include -D_BSD_SOURCE -D_XOPEN_SOURCE=600
|
||||||
|
CPPFLAGS += -D_GNU_SOURCE
|
||||||
WARNFLAGS ?= -pedantic -std=c99 -Wall -Wextra -Werror -Wshadow -Wformat=2
|
WARNFLAGS ?= -pedantic -std=c99 -Wall -Wextra -Werror -Wshadow -Wformat=2
|
||||||
WARNFLAGS += -Wmissing-declarations -Wcomment -Wunused-macros -Wendif-labels
|
WARNFLAGS += -Wmissing-declarations -Wcomment -Wunused-macros -Wendif-labels
|
||||||
CFLAGS += $(WARNFLAGS) -O2 -fPIC -DPIC
|
CFLAGS += $(WARNFLAGS) -O2 -fPIC -DPIC
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue