Mega-commit to document the API with doxygen.
Some changes were made to the API when making the documentation: - A few exported functions are now hidden, because they were only used internally in the library. - A few exported symbols were renamed to document them better than previously. - Cosmetic changes all along the way, as well as some fixes here and there. --HG-- extra : convert_revision : xtraeme%40gmail.com-20100121021019-onbsivlrhdb7t3ou
This commit is contained in:
163
lib/unpack.c
163
lib/unpack.c
@@ -32,74 +32,11 @@
|
||||
|
||||
#include <xbps_api.h>
|
||||
|
||||
static int unpack_archive_fini(struct archive *, prop_dictionary_t);
|
||||
static void set_extract_flags(int *);
|
||||
|
||||
int SYMEXPORT
|
||||
xbps_unpack_binary_pkg(prop_dictionary_t pkg)
|
||||
{
|
||||
const char *pkgname, *repoloc;
|
||||
struct archive *ar = NULL;
|
||||
char *binfile = NULL;
|
||||
int pkg_fd, rv = 0;
|
||||
|
||||
assert(pkg != NULL);
|
||||
|
||||
if (!prop_dictionary_get_cstring_nocopy(pkg, "pkgname", &pkgname))
|
||||
return errno;
|
||||
if (!prop_dictionary_get_cstring_nocopy(pkg, "repository", &repoloc))
|
||||
return errno;
|
||||
binfile = xbps_get_binpkg_local_path(pkg, repoloc);
|
||||
if (binfile == NULL)
|
||||
return EINVAL;
|
||||
|
||||
if ((pkg_fd = open(binfile, O_RDONLY)) == -1) {
|
||||
rv = errno;
|
||||
goto out;
|
||||
}
|
||||
|
||||
ar = archive_read_new();
|
||||
if (ar == NULL) {
|
||||
rv = errno;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*
|
||||
* Enable support for tar format and all compression methods.
|
||||
*/
|
||||
archive_read_support_compression_all(ar);
|
||||
archive_read_support_format_tar(ar);
|
||||
|
||||
if ((rv = archive_read_open_fd(ar, pkg_fd,
|
||||
ARCHIVE_READ_BLOCKSIZE)) != 0)
|
||||
goto out;
|
||||
|
||||
if ((rv = unpack_archive_fini(ar, pkg)) == 0) {
|
||||
/*
|
||||
* If installation of package was successful, make sure
|
||||
* its files are written in storage (if possible).
|
||||
*/
|
||||
if (fsync(pkg_fd) == -1) {
|
||||
rv = errno;
|
||||
goto out;
|
||||
}
|
||||
/*
|
||||
* Set package state to unpacked.
|
||||
*/
|
||||
rv = xbps_set_pkg_state_installed(pkgname,
|
||||
XBPS_PKG_STATE_UNPACKED);
|
||||
}
|
||||
|
||||
out:
|
||||
if (ar)
|
||||
archive_read_finish(ar);
|
||||
if (pkg_fd != -1)
|
||||
(void)close(pkg_fd);
|
||||
if (binfile)
|
||||
free(binfile);
|
||||
|
||||
return rv;
|
||||
}
|
||||
/**
|
||||
* @file lib/unpack.c
|
||||
* @brief Binary package file unpacking routines
|
||||
* @defgroup unpack Binary package file unpacking functions
|
||||
*/
|
||||
|
||||
static void
|
||||
set_extract_flags(int *flags)
|
||||
@@ -154,30 +91,6 @@ unpack_archive_fini(struct archive *ar, prop_dictionary_t pkg)
|
||||
if (xbps_check_is_installed_pkgname(pkgname))
|
||||
update = true;
|
||||
|
||||
/*
|
||||
* If we are updating an essential package, we have to run the
|
||||
* pre-remove stage by the current package, because later some
|
||||
* files could be removed.
|
||||
*/
|
||||
if (update && essential) {
|
||||
buf = xbps_xasprintf(".%s/metadata/%s/REMOVE",
|
||||
XBPS_META_PATH, pkgname);
|
||||
if (buf == NULL)
|
||||
return errno;
|
||||
if (access(buf, R_OK|X_OK) == 0) {
|
||||
if ((rv = xbps_file_chdir_exec(rootdir, buf, "pre",
|
||||
pkgname, version, "yes", NULL)) != 0) {
|
||||
fprintf(stderr, "%s: prerm action target error"
|
||||
"(%s) while updating!\n",
|
||||
pkgname, strerror(errno));
|
||||
free(buf);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
free(buf);
|
||||
buf = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Process the archive files.
|
||||
*/
|
||||
@@ -401,3 +314,69 @@ unpack_archive_fini(struct archive *ar, prop_dictionary_t pkg)
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
int
|
||||
xbps_unpack_binary_pkg(prop_dictionary_t pkg)
|
||||
{
|
||||
const char *pkgname, *repoloc;
|
||||
struct archive *ar = NULL;
|
||||
char *binfile = NULL;
|
||||
int pkg_fd, rv = 0;
|
||||
|
||||
assert(pkg != NULL);
|
||||
|
||||
if (!prop_dictionary_get_cstring_nocopy(pkg, "pkgname", &pkgname))
|
||||
return errno;
|
||||
if (!prop_dictionary_get_cstring_nocopy(pkg, "repository", &repoloc))
|
||||
return errno;
|
||||
binfile = xbps_get_binpkg_local_path(pkg, repoloc);
|
||||
if (binfile == NULL)
|
||||
return EINVAL;
|
||||
|
||||
if ((pkg_fd = open(binfile, O_RDONLY)) == -1) {
|
||||
rv = errno;
|
||||
goto out;
|
||||
}
|
||||
|
||||
ar = archive_read_new();
|
||||
if (ar == NULL) {
|
||||
rv = errno;
|
||||
goto out;
|
||||
}
|
||||
|
||||
/*
|
||||
* Enable support for tar format and all compression methods.
|
||||
*/
|
||||
archive_read_support_compression_all(ar);
|
||||
archive_read_support_format_tar(ar);
|
||||
|
||||
if ((rv = archive_read_open_fd(ar, pkg_fd,
|
||||
ARCHIVE_READ_BLOCKSIZE)) != 0)
|
||||
goto out;
|
||||
|
||||
if ((rv = unpack_archive_fini(ar, pkg)) == 0) {
|
||||
/*
|
||||
* If installation of package was successful, make sure
|
||||
* its files are written in storage (if possible).
|
||||
*/
|
||||
if (fsync(pkg_fd) == -1) {
|
||||
rv = errno;
|
||||
goto out;
|
||||
}
|
||||
/*
|
||||
* Set package state to unpacked.
|
||||
*/
|
||||
rv = xbps_set_pkg_state_installed(pkgname,
|
||||
XBPS_PKG_STATE_UNPACKED);
|
||||
}
|
||||
|
||||
out:
|
||||
if (ar)
|
||||
archive_read_finish(ar);
|
||||
if (pkg_fd != -1)
|
||||
(void)close(pkg_fd);
|
||||
if (binfile)
|
||||
free(binfile);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
Reference in New Issue
Block a user