mirror of
https://github.com/void-linux/void-packages.git
synced 2025-06-07 15:43:49 +02:00
xbps_unpack_binary_pkg(): merge a func on it.
--HG-- extra : convert_revision : 1cf498bf353a23062178b4be826b52bb48a3e906
This commit is contained in:
parent
3062c40e63
commit
39c24fdd2c
1 changed files with 15 additions and 27 deletions
42
lib/unpack.c
42
lib/unpack.c
|
@ -35,15 +35,15 @@
|
||||||
|
|
||||||
#include <xbps_api.h>
|
#include <xbps_api.h>
|
||||||
|
|
||||||
static int unpack_archive_init(prop_dictionary_t, const char *);
|
|
||||||
static int unpack_archive_fini(struct archive *, prop_dictionary_t);
|
static int unpack_archive_fini(struct archive *, prop_dictionary_t);
|
||||||
|
|
||||||
int
|
int
|
||||||
xbps_unpack_binary_pkg(prop_dictionary_t pkg)
|
xbps_unpack_binary_pkg(prop_dictionary_t pkg)
|
||||||
{
|
{
|
||||||
prop_string_t filename, repoloc, arch;
|
prop_string_t filename, repoloc, arch;
|
||||||
|
struct archive *ar;
|
||||||
char *binfile;
|
char *binfile;
|
||||||
int rv = 0;
|
int pkg_fd, rv = 0;
|
||||||
|
|
||||||
assert(pkg != NULL);
|
assert(pkg != NULL);
|
||||||
|
|
||||||
|
@ -63,41 +63,24 @@ xbps_unpack_binary_pkg(prop_dictionary_t pkg)
|
||||||
if (binfile == NULL)
|
if (binfile == NULL)
|
||||||
return EINVAL;
|
return EINVAL;
|
||||||
|
|
||||||
rv = unpack_archive_init(pkg, binfile);
|
if ((pkg_fd = open(binfile, O_RDONLY)) == -1) {
|
||||||
free(binfile);
|
rv = errno;
|
||||||
return rv;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
|
||||||
unpack_archive_init(prop_dictionary_t pkg, const char *binfile)
|
|
||||||
{
|
|
||||||
struct archive *ar;
|
|
||||||
int pkg_fd, rv;
|
|
||||||
|
|
||||||
assert(pkg != NULL);
|
|
||||||
assert(binfile != NULL);
|
|
||||||
|
|
||||||
if ((pkg_fd = open(binfile, O_RDONLY)) == -1)
|
|
||||||
return errno;
|
|
||||||
|
|
||||||
ar = archive_read_new();
|
ar = archive_read_new();
|
||||||
if (ar == NULL) {
|
if (ar == NULL) {
|
||||||
(void)close(pkg_fd);
|
rv = ENOMEM;
|
||||||
return ENOMEM;
|
goto out2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Enable support for tar format and all compression methods */
|
/* Enable support for tar format and all compression methods */
|
||||||
archive_read_support_compression_all(ar);
|
archive_read_support_compression_all(ar);
|
||||||
archive_read_support_format_tar(ar);
|
archive_read_support_format_tar(ar);
|
||||||
|
|
||||||
/* 2048 is arbitrary... dunno what value is better. */
|
|
||||||
if ((rv = archive_read_open_fd(ar, pkg_fd,
|
if ((rv = archive_read_open_fd(ar, pkg_fd,
|
||||||
ARCHIVE_READ_BLOCKSIZE)) != 0) {
|
ARCHIVE_READ_BLOCKSIZE)) != 0)
|
||||||
archive_read_finish(ar);
|
goto out3;
|
||||||
(void)close(pkg_fd);
|
|
||||||
return rv;
|
|
||||||
}
|
|
||||||
|
|
||||||
rv = unpack_archive_fini(ar, pkg);
|
rv = unpack_archive_fini(ar, pkg);
|
||||||
/*
|
/*
|
||||||
|
@ -108,11 +91,16 @@ unpack_archive_init(prop_dictionary_t pkg, const char *binfile)
|
||||||
if (fsync(pkg_fd) == -1)
|
if (fsync(pkg_fd) == -1)
|
||||||
rv = errno;
|
rv = errno;
|
||||||
|
|
||||||
|
out3:
|
||||||
archive_read_finish(ar);
|
archive_read_finish(ar);
|
||||||
|
out2:
|
||||||
(void)close(pkg_fd);
|
(void)close(pkg_fd);
|
||||||
|
out:
|
||||||
|
free(binfile);
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Flags for extracting files in binary packages.
|
* Flags for extracting files in binary packages.
|
||||||
*/
|
*/
|
||||||
|
|
Loading…
Add table
Reference in a new issue