summaryrefslogtreecommitdiffstats
path: root/lib/libalpm/add.c
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-11-14 06:45:55 +0100
committerDan McGee <dan@archlinux.org>2011-11-16 21:51:06 +0100
commitdee8144ce5ca96ceca643d74fd6152ecf812f8af (patch)
tree9206036726557a195046ccb5bcf9eb796c6d47ae /lib/libalpm/add.c
parentf1ec3b9b10d1657412d6592180c56887c3a6ae20 (diff)
downloadpacman-dee8144ce5ca96ceca643d74fd6152ecf812f8af.tar.gz
pacman-dee8144ce5ca96ceca643d74fd6152ecf812f8af.tar.xz
Add helper method for creating and opening archive object
This moves the common setup code of about 5 different callers into one method. Error messages will now be common and shared in all places; several paths did not have any messages at all before. In addition, we now pick an ideal block size for the archive read based off the larger value of our default buffer size or the st.st_blksize field. For a filesystem such as NFS, this is often much larger than the default 8192- values such as 32768 and 131072 are common. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/add.c')
-rw-r--r--lib/libalpm/add.c22
1 files changed, 8 insertions, 14 deletions
diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
index 44b852f2..78615bb1 100644
--- a/lib/libalpm/add.c
+++ b/lib/libalpm/add.c
@@ -525,23 +525,14 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg,
if(!(trans->flags & ALPM_TRANS_FLAG_DBONLY)) {
struct archive *archive;
struct archive_entry *entry;
- int cwdfd;
+ struct stat buf;
+ int fd, cwdfd;
_alpm_log(handle, ALPM_LOG_DEBUG, "extracting files\n");
- if((archive = archive_read_new()) == NULL) {
- handle->pm_errno = ALPM_ERR_LIBARCHIVE;
- ret = -1;
- goto cleanup;
- }
-
- archive_read_support_compression_all(archive);
- archive_read_support_format_all(archive);
-
- _alpm_log(handle, ALPM_LOG_DEBUG, "archive: %s\n", pkgfile);
- if(archive_read_open_filename(archive, pkgfile,
- ALPM_BUFFER_SIZE) != ARCHIVE_OK) {
- handle->pm_errno = ALPM_ERR_PKG_OPEN;
+ fd = _alpm_open_archive(db->handle, pkgfile, &buf,
+ &archive, ALPM_ERR_PKG_OPEN);
+ if(fd < 0) {
ret = -1;
goto cleanup;
}
@@ -556,6 +547,8 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg,
if(chdir(handle->root) != 0) {
_alpm_log(handle, ALPM_LOG_ERROR, _("could not change directory to %s (%s)\n"),
handle->root, strerror(errno));
+ archive_read_finish(archive);
+ CLOSE(fd);
ret = -1;
goto cleanup;
}
@@ -597,6 +590,7 @@ static int commit_single_pkg(alpm_handle_t *handle, alpm_pkg_t *newpkg,
errors += extract_single_file(handle, archive, entry, newpkg, oldpkg);
}
archive_read_finish(archive);
+ CLOSE(fd);
/* restore the old cwd if we have it */
if(cwdfd >= 0) {