Use fs blksize from stat(2)ed file when reading archives.

This commit is contained in:
Juan RP 2013-08-29 14:30:14 +02:00
parent 1bea5725ae
commit 24ff0472dd
6 changed files with 48 additions and 21 deletions

View File

@ -50,6 +50,11 @@
#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 {
TAILQ_ENTRY(xentry) entries;
char *file, *type, *target, *hash;
@ -781,7 +786,7 @@ main(int argc, char **argv)
}
archive_entry_linkresolver_free(resolver);
/* close and free archive */
archive_write_free(ar);
archive_write_finish(ar);
/*
* Archive was created successfully; flush data to storage,

View File

@ -78,7 +78,7 @@ repodata_flush(struct xbps_handle *xhp, const char *repodir,
}
free(xml);
archive_write_free(ar);
archive_write_finish(ar);
/* Write data to tempfile and rename */
fdatasync(repofd);

View File

@ -50,8 +50,6 @@
#include "queue.h"
#include "fetch.h"
#define ARCHIVE_READ_BLOCKSIZE 10240
#define EXTRACT_FLAGS ARCHIVE_EXTRACT_SECURE_NODOTDOT | \
ARCHIVE_EXTRACT_SECURE_SYMLINKS
#define FEXTRACT_FLAGS ARCHIVE_EXTRACT_OWNER | ARCHIVE_EXTRACT_PERM | \

View File

@ -626,9 +626,10 @@ int HIDDEN
xbps_unpack_binary_pkg(struct xbps_handle *xhp, xbps_dictionary_t pkg_repod)
{
struct archive *ar = NULL;
struct stat st;
const char *pkgver;
char *bpkg;
int pkg_fd, rv = 0;
char *bpkg = NULL;
int pkg_fd = -1, rv = 0;
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);
if (pkg_fd == -1) {
rv = archive_errno(ar);
rv = errno;
xbps_set_cb_state(xhp, XBPS_STATE_UNPACK_FAIL,
rv, pkgver,
"%s: [unpack] failed to open binary package `%s': %s",
pkgver, bpkg, strerror(rv));
free(bpkg);
archive_read_free(ar);
return rv;
goto out;
}
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.
*/
@ -690,9 +703,10 @@ xbps_unpack_binary_pkg(struct xbps_handle *xhp, xbps_dictionary_t pkg_repod)
pkgver, strerror(rv));
}
out:
if (pkg_fd != -1)
close(pkg_fd);
if (ar)
archive_read_free(ar);
archive_read_finish(ar);
if (bpkg)
free(bpkg);

View File

@ -123,9 +123,8 @@ open_archive(const char *url)
archive_read_support_compression_xz(a);
archive_read_support_format_tar(a);
if (archive_read_open_filename(a, url,
ARCHIVE_READ_BLOCKSIZE)) {
archive_read_close(a);
if (archive_read_open_filename(a, url, 32768)) {
archive_read_finish(a);
return NULL;
}
return a;
@ -185,7 +184,7 @@ xbps_get_pkg_plist_from_binpkg(const char *fname, const char *plistf)
break;
}
archive_read_free(a);
archive_read_finish(a);
return plistd;
}

View File

@ -28,6 +28,7 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <fcntl.h>
#include "xbps_api_impl.h"
@ -50,6 +51,7 @@ struct xbps_repo *
xbps_repo_open(struct xbps_handle *xhp, const char *url)
{
struct xbps_repo *repo;
struct stat st;
const char *arch;
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_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",
repofile, strerror(archive_errno(repo->ar)));
archive_read_free(repo->ar);
archive_read_finish(repo->ar);
free(repo);
repo = NULL;
}
out:
free(repofile);
return repo;
}
@ -144,7 +155,7 @@ xbps_repo_close(struct xbps_repo *repo)
if (repo->ar == NULL)
return;
archive_read_free(repo->ar);
archive_read_finish(repo->ar);
if (xbps_object_type(repo->idx) == XBPS_TYPE_DICTIONARY)
xbps_object_release(repo->idx);
if (xbps_object_type(repo->idxfiles) == XBPS_TYPE_DICTIONARY)