#include "config.h"
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <archive.h>
#include <archive_entry.h>
#include "alpm_list.h"
#include "alpm.h"
#include "util.h"
#include "log.h"
#include "handle.h"
#include "package.h"
#include "deps.h"
static void *_package_changelog_open(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return NULL);
struct archive *archive = NULL;
struct archive_entry *entry;
const char *pkgfile = pkg->origin_data.file;
if((archive = archive_read_new()) == NULL) {
RET_ERR(pkg->handle, ALPM_ERR_LIBARCHIVE, NULL);
}
archive_read_support_compression_all(archive);
archive_read_support_format_all(archive);
if(archive_read_open_filename(archive, pkgfile,
ALPM_BUFFER_SIZE) != ARCHIVE_OK) {
RET_ERR(pkg->handle, ALPM_ERR_PKG_OPEN, NULL);
}
while(archive_read_next_header(archive, &entry) == ARCHIVE_OK) {
const char *entry_name = archive_entry_pathname(entry);
if(strcmp(entry_name, ".CHANGELOG") == 0) {
return archive;
}
}
archive_read_finish(archive);
errno = ENOENT;
return NULL;
}
static size_t _package_changelog_read(void *ptr, size_t size,
const alpm_pkg_t UNUSED *pkg, void *fp)
{
ssize_t sret = archive_read_data((struct archive *)fp, ptr, size);
if(sret < 0) {
RET_ERR(pkg->handle, ALPM_ERR_LIBARCHIVE, 0);
} else {
return (size_t)sret;
}
}
static int _package_changelog_close(const alpm_pkg_t UNUSED *pkg, void *fp)
{
return archive_read_finish((struct archive *)fp);
}
static struct pkg_operations *get_file_pkg_ops(void)
{
static struct pkg_operations file_pkg_ops;
static int file_pkg_ops_initialized = 0;
if(!file_pkg_ops_initialized) {
file_pkg_ops = default_pkg_ops;
file_pkg_ops.changelog_open = _package_changelog_open;
file_pkg_ops.changelog_read = _package_changelog_read;
file_pkg_ops.changelog_close =
|