summaryrefslogtreecommitdiffstats
path: root/lib/libalpm/be_sync.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/be_sync.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/be_sync.c')
-rw-r--r--lib/libalpm/be_sync.c23
1 files changed, 3 insertions, 20 deletions
diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c
index aa260020..54c4f879 100644
--- a/lib/libalpm/be_sync.c
+++ b/lib/libalpm/be_sync.c
@@ -433,26 +433,9 @@ static int sync_db_populate(alpm_db_t *db)
return -1;
}
- if((archive = archive_read_new()) == NULL) {
- RET_ERR(db->handle, ALPM_ERR_LIBARCHIVE, -1);
- }
-
- archive_read_support_compression_all(archive);
- archive_read_support_format_all(archive);
-
- _alpm_log(db->handle, ALPM_LOG_DEBUG,
- "opening database archive %s\n", dbpath);
- OPEN(fd, dbpath, O_RDONLY);
- if(fd < 0 || archive_read_open_fd(archive, fd,
- ALPM_BUFFER_SIZE) != ARCHIVE_OK) {
- const char *err = fd < 0 ? strerror(errno) : archive_error_string(archive);
- _alpm_log(db->handle, ALPM_LOG_ERROR,
- _("could not open file %s: %s\n"), dbpath, err);
- db->handle->pm_errno = ALPM_ERR_DB_OPEN;
- goto cleanup;
- }
- if(fstat(fd, &buf) != 0) {
- db->handle->pm_errno = ALPM_ERR_DB_OPEN;
+ fd = _alpm_open_archive(db->handle, dbpath, &buf,
+ &archive, ALPM_ERR_DB_OPEN);
+ if(fd < 0) {
goto cleanup;
}
est_count = estimate_package_count(&buf, archive);