Use fs blksize from stat(2)ed file when reading archives.
This commit is contained in:
parent
1bea5725ae
commit
24ff0472dd
@ -50,6 +50,11 @@
|
|||||||
|
|
||||||
#define _PROGNAME "xbps-create"
|
#define _PROGNAME "xbps-create"
|
||||||
|
|
||||||
|
/* libarchive 2.x compat */
|
||||||
|
#if ARCHIVE_VERSION_NUMBER >= 3000000
|
||||||
|
# define archive_write_finish(x) archive_write_free(x)
|
||||||
|
#endif
|
||||||
|
|
||||||
struct xentry {
|
struct xentry {
|
||||||
TAILQ_ENTRY(xentry) entries;
|
TAILQ_ENTRY(xentry) entries;
|
||||||
char *file, *type, *target, *hash;
|
char *file, *type, *target, *hash;
|
||||||
@ -781,7 +786,7 @@ main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
archive_entry_linkresolver_free(resolver);
|
archive_entry_linkresolver_free(resolver);
|
||||||
/* close and free archive */
|
/* close and free archive */
|
||||||
archive_write_free(ar);
|
archive_write_finish(ar);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Archive was created successfully; flush data to storage,
|
* Archive was created successfully; flush data to storage,
|
||||||
|
@ -78,7 +78,7 @@ repodata_flush(struct xbps_handle *xhp, const char *repodir,
|
|||||||
}
|
}
|
||||||
free(xml);
|
free(xml);
|
||||||
|
|
||||||
archive_write_free(ar);
|
archive_write_finish(ar);
|
||||||
|
|
||||||
/* Write data to tempfile and rename */
|
/* Write data to tempfile and rename */
|
||||||
fdatasync(repofd);
|
fdatasync(repofd);
|
||||||
|
@ -50,8 +50,6 @@
|
|||||||
#include "queue.h"
|
#include "queue.h"
|
||||||
#include "fetch.h"
|
#include "fetch.h"
|
||||||
|
|
||||||
#define ARCHIVE_READ_BLOCKSIZE 10240
|
|
||||||
|
|
||||||
#define EXTRACT_FLAGS ARCHIVE_EXTRACT_SECURE_NODOTDOT | \
|
#define EXTRACT_FLAGS ARCHIVE_EXTRACT_SECURE_NODOTDOT | \
|
||||||
ARCHIVE_EXTRACT_SECURE_SYMLINKS
|
ARCHIVE_EXTRACT_SECURE_SYMLINKS
|
||||||
#define FEXTRACT_FLAGS ARCHIVE_EXTRACT_OWNER | ARCHIVE_EXTRACT_PERM | \
|
#define FEXTRACT_FLAGS ARCHIVE_EXTRACT_OWNER | ARCHIVE_EXTRACT_PERM | \
|
||||||
|
@ -626,9 +626,10 @@ int HIDDEN
|
|||||||
xbps_unpack_binary_pkg(struct xbps_handle *xhp, xbps_dictionary_t pkg_repod)
|
xbps_unpack_binary_pkg(struct xbps_handle *xhp, xbps_dictionary_t pkg_repod)
|
||||||
{
|
{
|
||||||
struct archive *ar = NULL;
|
struct archive *ar = NULL;
|
||||||
|
struct stat st;
|
||||||
const char *pkgver;
|
const char *pkgver;
|
||||||
char *bpkg;
|
char *bpkg = NULL;
|
||||||
int pkg_fd, rv = 0;
|
int pkg_fd = -1, rv = 0;
|
||||||
|
|
||||||
assert(xbps_object_type(pkg_repod) == XBPS_TYPE_DICTIONARY);
|
assert(xbps_object_type(pkg_repod) == XBPS_TYPE_DICTIONARY);
|
||||||
|
|
||||||
@ -658,17 +659,29 @@ xbps_unpack_binary_pkg(struct xbps_handle *xhp, xbps_dictionary_t pkg_repod)
|
|||||||
|
|
||||||
pkg_fd = open(bpkg, O_RDONLY|O_CLOEXEC);
|
pkg_fd = open(bpkg, O_RDONLY|O_CLOEXEC);
|
||||||
if (pkg_fd == -1) {
|
if (pkg_fd == -1) {
|
||||||
rv = archive_errno(ar);
|
rv = errno;
|
||||||
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
|
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
|
||||||
rv, pkgver,
|
rv, pkgver,
|
||||||
"%s: [unpack] failed to open binary package `%s': %s",
|
"%s: [unpack] failed to open binary package `%s': %s",
|
||||||
pkgver, bpkg, strerror(rv));
|
pkgver, bpkg, strerror(rv));
|
||||||
free(bpkg);
|
goto out;
|
||||||
archive_read_free(ar);
|
}
|
||||||
return rv;
|
if (fstat(pkg_fd, &st) == -1) {
|
||||||
|
rv = errno;
|
||||||
|
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
|
||||||
|
rv, pkgver,
|
||||||
|
"%s: [unpack] failed to fstat binary package `%s': %s",
|
||||||
|
pkgver, bpkg, strerror(rv));
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
if (archive_read_open_fd(ar, pkg_fd, st.st_blksize) == ARCHIVE_FATAL) {
|
||||||
|
rv = archive_errno(ar);
|
||||||
|
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
|
||||||
|
rv, pkgver,
|
||||||
|
"%s: [unpack] failed to read binary package `%s': %s",
|
||||||
|
pkgver, bpkg, strerror(rv));
|
||||||
|
goto out;
|
||||||
}
|
}
|
||||||
archive_read_open_fd(ar, pkg_fd, ARCHIVE_READ_BLOCKSIZE);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Extract archive files.
|
* Extract archive files.
|
||||||
*/
|
*/
|
||||||
@ -690,9 +703,10 @@ xbps_unpack_binary_pkg(struct xbps_handle *xhp, xbps_dictionary_t pkg_repod)
|
|||||||
pkgver, strerror(rv));
|
pkgver, strerror(rv));
|
||||||
}
|
}
|
||||||
out:
|
out:
|
||||||
close(pkg_fd);
|
if (pkg_fd != -1)
|
||||||
|
close(pkg_fd);
|
||||||
if (ar)
|
if (ar)
|
||||||
archive_read_free(ar);
|
archive_read_finish(ar);
|
||||||
if (bpkg)
|
if (bpkg)
|
||||||
free(bpkg);
|
free(bpkg);
|
||||||
|
|
||||||
|
@ -123,9 +123,8 @@ open_archive(const char *url)
|
|||||||
archive_read_support_compression_xz(a);
|
archive_read_support_compression_xz(a);
|
||||||
archive_read_support_format_tar(a);
|
archive_read_support_format_tar(a);
|
||||||
|
|
||||||
if (archive_read_open_filename(a, url,
|
if (archive_read_open_filename(a, url, 32768)) {
|
||||||
ARCHIVE_READ_BLOCKSIZE)) {
|
archive_read_finish(a);
|
||||||
archive_read_close(a);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return a;
|
return a;
|
||||||
@ -185,7 +184,7 @@ xbps_get_pkg_plist_from_binpkg(const char *fname, const char *plistf)
|
|||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
archive_read_free(a);
|
archive_read_finish(a);
|
||||||
|
|
||||||
return plistd;
|
return plistd;
|
||||||
}
|
}
|
||||||
|
17
lib/repo.c
17
lib/repo.c
@ -28,6 +28,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
#include "xbps_api_impl.h"
|
#include "xbps_api_impl.h"
|
||||||
|
|
||||||
@ -50,6 +51,7 @@ struct xbps_repo *
|
|||||||
xbps_repo_open(struct xbps_handle *xhp, const char *url)
|
xbps_repo_open(struct xbps_handle *xhp, const char *url)
|
||||||
{
|
{
|
||||||
struct xbps_repo *repo;
|
struct xbps_repo *repo;
|
||||||
|
struct stat st;
|
||||||
const char *arch;
|
const char *arch;
|
||||||
char *repofile;
|
char *repofile;
|
||||||
|
|
||||||
@ -85,13 +87,22 @@ xbps_repo_open(struct xbps_handle *xhp, const char *url)
|
|||||||
archive_read_support_compression_xz(repo->ar);
|
archive_read_support_compression_xz(repo->ar);
|
||||||
archive_read_support_format_tar(repo->ar);
|
archive_read_support_format_tar(repo->ar);
|
||||||
|
|
||||||
if (archive_read_open_filename(repo->ar, repofile, ARCHIVE_READ_BLOCKSIZE)) {
|
if (stat(repofile, &st) == -1) {
|
||||||
|
xbps_dbg_printf(xhp, "[repo] cannot stat repository file %s: %s\n",
|
||||||
|
repofile, strerror(errno));
|
||||||
|
archive_read_finish(repo->ar);
|
||||||
|
free(repo);
|
||||||
|
repo = NULL;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
if (archive_read_open_filename(repo->ar, repofile, st.st_blksize) == ARCHIVE_FATAL) {
|
||||||
xbps_dbg_printf(xhp, "[repo] cannot open repository file %s: %s\n",
|
xbps_dbg_printf(xhp, "[repo] cannot open repository file %s: %s\n",
|
||||||
repofile, strerror(archive_errno(repo->ar)));
|
repofile, strerror(archive_errno(repo->ar)));
|
||||||
archive_read_free(repo->ar);
|
archive_read_finish(repo->ar);
|
||||||
free(repo);
|
free(repo);
|
||||||
repo = NULL;
|
repo = NULL;
|
||||||
}
|
}
|
||||||
|
out:
|
||||||
free(repofile);
|
free(repofile);
|
||||||
return repo;
|
return repo;
|
||||||
}
|
}
|
||||||
@ -144,7 +155,7 @@ xbps_repo_close(struct xbps_repo *repo)
|
|||||||
if (repo->ar == NULL)
|
if (repo->ar == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
archive_read_free(repo->ar);
|
archive_read_finish(repo->ar);
|
||||||
if (xbps_object_type(repo->idx) == XBPS_TYPE_DICTIONARY)
|
if (xbps_object_type(repo->idx) == XBPS_TYPE_DICTIONARY)
|
||||||
xbps_object_release(repo->idx);
|
xbps_object_release(repo->idx);
|
||||||
if (xbps_object_type(repo->idxfiles) == XBPS_TYPE_DICTIONARY)
|
if (xbps_object_type(repo->idxfiles) == XBPS_TYPE_DICTIONARY)
|
||||||
|
Loading…
Reference in New Issue
Block a user