Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib/libalpm/package.h
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2008-05-11 16:00:33 -0500
committerAllan McRae <allan@archlinux.org>2010-10-13 23:53:18 +1000
commit6cebd4e6028f717663cda0af1221f3ac74d5ab9f (patch)
tree2da35452bcbd5c2e22379e786d2a4e401b994a4c /lib/libalpm/package.h
parentd1126db1281596ba8ea960bfa963e86731d28b5e (diff)
Complete rework of package accessor logic
Hopefully we've finally arrived at package handling nirvana, or at least this commit will get us a heck of a lot closer. The former method of getting the depends list for a package was the following: 1. call alpm_pkg_get_depends() 2. this method would check if the package came from the cache 3. if so, ensure our cache level is correct, otherwise call db_load 4. finally return the depends list Why did this suck? Because getting the depends list from the package shouldn't care about whether the package was loaded from a file, from the 'package cache', or some other system which we can't even use because the damn thing is so complicated. It should just return the depends list. So what does this commit change? It adds a pointer to a struct of function pointers to every package for all of these 'package operations' as I've decided to call them (I know, sounds completely straightforward, right?). So now when we call an alpm_pkg_get-* function, we don't do any of the cache logic or anything else there- we let the actual backend handle it by delegating all work to the method at pkg->ops->get_depends. Now that be_package has achieved equal status with be_files, we can treat packages from these completely different load points differently. We know a package loaded from a zip file will have all of its fields populated, so we can set up all its accessor functions to be direct accessors. On the other hand, the packages loaded from the local and sync DBs are not always fully-loaded, so their accessor functions are routed through the same logic as before. Net result? More code. However, this code now make it roughly 52 times easier to open the door to something like a read-only tar.gz database backend. Are you still reading? I'm impressed. Looking at the patch will probably be clearer than this long-winded explanation. Signed-off-by: Dan McGee <dan@archlinux.org> [Allan: rebase and adjust] Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'lib/libalpm/package.h')
-rw-r--r--lib/libalpm/package.h56
1 files changed, 56 insertions, 0 deletions
diff --git a/lib/libalpm/package.h b/lib/libalpm/package.h
index daff9717..5ad553ac 100644
--- a/lib/libalpm/package.h
+++ b/lib/libalpm/package.h
@@ -36,6 +36,60 @@ typedef enum _pmpkgfrom_t {
PKG_FROM_SYNCDB
} pmpkgfrom_t;
+/** Package operations struct. This struct contains function pointers to
+ * all methods used to access data in a package to allow for things such
+ * as lazy package intialization (such as used by the file backend). Each
+ * backend is free to define a stuct containing pointers to a specific
+ * implementation of these methods. Some backends may find using the
+ * defined default_pkg_ops struct to work just fine for their needs.
+ */
+struct pkg_operations {
+ const char *(*get_filename) (pmpkg_t *);
+ const char *(*get_name) (pmpkg_t *);
+ const char *(*get_version) (pmpkg_t *);
+ const char *(*get_desc) (pmpkg_t *);
+ const char *(*get_url) (pmpkg_t *);
+ time_t (*get_builddate) (pmpkg_t *);
+ time_t (*get_installdate) (pmpkg_t *);
+ const char *(*get_packager) (pmpkg_t *);
+ const char *(*get_md5sum) (pmpkg_t *);
+ const char *(*get_arch) (pmpkg_t *);
+ off_t (*get_size) (pmpkg_t *);
+ off_t (*get_isize) (pmpkg_t *);
+ pmpkgreason_t (*get_reason) (pmpkg_t *);
+ int (*has_force) (pmpkg_t *);
+
+ alpm_list_t *(*get_licenses) (pmpkg_t *);
+ alpm_list_t *(*get_groups) (pmpkg_t *);
+ alpm_list_t *(*get_depends) (pmpkg_t *);
+ alpm_list_t *(*get_optdepends) (pmpkg_t *);
+ alpm_list_t *(*get_conflicts) (pmpkg_t *);
+ alpm_list_t *(*get_provides) (pmpkg_t *);
+ alpm_list_t *(*get_replaces) (pmpkg_t *);
+ alpm_list_t *(*get_deltas) (pmpkg_t *);
+ alpm_list_t *(*get_files) (pmpkg_t *);
+ alpm_list_t *(*get_backup) (pmpkg_t *);
+
+ void *(*changelog_open) (pmpkg_t *);
+ size_t (*changelog_read) (void *, size_t, const pmpkg_t *, const void *);
+ int (*changelog_close) (const pmpkg_t *, void *);
+
+ /* still to add:
+ * free()
+ * dup()
+ * checkmd5sum() ?
+ * has_scriptlet()
+ * compute_requiredby()
+ */
+};
+
+/** The standard package operations struct. get fields directly from the
+ * struct itself with no abstraction layer or any type of lazy loading.
+ * The actual definition is in package.c so it can have access to the
+ * default accessor functions which are defined there.
+ */
+extern struct pkg_operations default_pkg_ops;
+
struct __pmpkg_t {
char *filename;
char *name;
@@ -76,6 +130,8 @@ struct __pmpkg_t {
char *file;
} origin_data;
pmdbinfrq_t infolevel;
+
+ struct pkg_operations *ops;
};
pmpkg_t* _alpm_pkg_new(void);