Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib/libalpm
diff options
context:
space:
mode:
authorAllan McRae <allan@archlinux.org>2012-05-01 18:12:13 +1000
committerAllan McRae <allan@archlinux.org>2012-12-14 13:45:12 +1000
commit0445c68d9b7738553dd1a5088110b8b0a1e1f7f9 (patch)
treedc71ae968d3a65b87f496635d2f19f162ccdd179 /lib/libalpm
parentda3a0333de34b37d073e1d27e9a07a7fa80025ee (diff)
Add internal functions for reading mtree file from local db
Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'lib/libalpm')
-rw-r--r--lib/libalpm/be_local.c77
-rw-r--r--lib/libalpm/package.c21
-rw-r--r--lib/libalpm/package.h8
3 files changed, 106 insertions, 0 deletions
diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
index f0e4a80f..57092455 100644
--- a/lib/libalpm/be_local.c
+++ b/lib/libalpm/be_local.c
@@ -28,6 +28,10 @@
#include <dirent.h>
#include <limits.h> /* PATH_MAX */
+/* libarchive */
+#include <archive.h>
+#include <archive_entry.h>
+
/* libalpm */
#include "db.h"
#include "alpm_list.h"
@@ -211,6 +215,75 @@ static int _cache_changelog_close(const alpm_pkg_t UNUSED *pkg, void *fp)
return fclose((FILE *)fp);
}
+/**
+ * Open a package mtree file for reading.
+ * @param pkg the local package to read the changelog of
+ * @return a archive structure for the package mtree file
+ */
+static struct archive *_cache_mtree_open(alpm_pkg_t *pkg)
+{
+ int r;
+ struct archive *mtree;
+
+ pkg->handle->pm_errno = 0;
+
+ alpm_db_t *db = alpm_pkg_get_db(pkg);
+ char *mtfile = _alpm_local_db_pkgpath(db, pkg, "mtree");
+
+ if(access(mtfile, F_OK) != 0) {
+ /* there is no mtree file for this package */
+ goto error;
+ }
+
+ if((mtree = archive_read_new()) == NULL) {
+ pkg->handle->pm_errno = ALPM_ERR_LIBARCHIVE;
+ goto error;
+ }
+
+ archive_read_support_filter_gzip(mtree);
+ archive_read_support_format_mtree(mtree);
+
+ if((r = archive_read_open_file(mtree, mtfile, ALPM_BUFFER_SIZE))) {
+ _alpm_log(pkg->handle, ALPM_LOG_ERROR, _("error while reading file %s: %s\n"),
+ mtfile, archive_error_string(mtree));
+ pkg->handle->pm_errno = ALPM_ERR_LIBARCHIVE;
+ archive_read_finish(mtree);
+ goto error;
+ }
+
+ free(mtfile);
+ return mtree;
+
+error:
+ free(mtfile);
+ return NULL;
+}
+
+/**
+ * Read next entry from a package mtree file.
+ * @param pkg the package that the mtree file is being read from
+ * @param archive the archive structure reading from the mtree file
+ * @param entry an archive_entry to store the entry header information
+ * @return 0 if end of archive is reached, non-zero otherwise.
+ */
+static int _cache_mtree_next(const alpm_pkg_t UNUSED *pkg,
+ struct archive *mtree, struct archive_entry **entry)
+{
+ return archive_read_next_header(mtree, entry);
+}
+
+/**
+ * Close a package mtree file for reading.
+ * @param pkg the package that the mtree file was read from
+ * @param mtree the archive structure use for reading from the mtree file
+ * @return whether closing the package changelog stream was successful
+ */
+static int _cache_mtree_close(const alpm_pkg_t UNUSED *pkg,
+ struct archive *mtree)
+{
+ return archive_read_finish(mtree);
+}
+
static int _cache_force_load(alpm_pkg_t *pkg)
{
return local_db_read(pkg, INFRQ_ALL);
@@ -246,6 +319,10 @@ static struct pkg_operations local_pkg_ops = {
.changelog_read = _cache_changelog_read,
.changelog_close = _cache_changelog_close,
+ .mtree_open = _cache_mtree_open,
+ .mtree_next = _cache_mtree_next,
+ .mtree_close = _cache_mtree_close,
+
.force_load = _cache_force_load,
};
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c
index 853771f8..0909ba9b 100644
--- a/lib/libalpm/package.c
+++ b/lib/libalpm/package.c
@@ -121,6 +121,23 @@ static int _pkg_changelog_close(const alpm_pkg_t UNUSED *pkg,
return EOF;
}
+static struct archive *_pkg_mtree_open(alpm_pkg_t UNUSED *pkg)
+{
+ return NULL;
+}
+
+static int _pkg_mtree_next(const alpm_pkg_t UNUSED *pkg,
+ struct archive UNUSED *archive, struct archive_entry UNUSED **entry)
+{
+ return -1;
+}
+
+static int _pkg_mtree_close(const alpm_pkg_t UNUSED *pkg,
+ struct archive UNUSED *archive)
+{
+ return -1;
+}
+
static int _pkg_force_load(alpm_pkg_t UNUSED *pkg) { return 0; }
/** The standard package operations struct. Get fields directly from the
@@ -152,6 +169,10 @@ struct pkg_operations default_pkg_ops = {
.changelog_read = _pkg_changelog_read,
.changelog_close = _pkg_changelog_close,
+ .mtree_open = _pkg_mtree_open,
+ .mtree_next = _pkg_mtree_next,
+ .mtree_close = _pkg_mtree_close,
+
.force_load = _pkg_force_load,
};
diff --git a/lib/libalpm/package.h b/lib/libalpm/package.h
index a915bc33..373fb90f 100644
--- a/lib/libalpm/package.h
+++ b/lib/libalpm/package.h
@@ -26,6 +26,10 @@
#include <sys/types.h> /* off_t */
+/* libarchive */
+#include <archive.h>
+#include <archive_entry.h>
+
#include "alpm.h"
#include "backup.h"
#include "db.h"
@@ -64,6 +68,10 @@ struct pkg_operations {
size_t (*changelog_read) (void *, size_t, const alpm_pkg_t *, void *);
int (*changelog_close) (const alpm_pkg_t *, void *);
+ struct archive *(*mtree_open) (alpm_pkg_t *);
+ int (*mtree_next) (const alpm_pkg_t *, struct archive *, struct archive_entry **);
+ int (*mtree_close) (const alpm_pkg_t *, struct archive *);
+
int (*force_load) (alpm_pkg_t *);
};