[pacman-dev] [PATCH 1/2] libalpm: Parse and write PKGBASEs

Johannes Löthberg johannes at kyriasis.com
Sat Dec 20 16:25:02 UTC 2014


This commit adds support to libalpm to parse the pkgbase present in
packages .PKGINFO files, writing the PKGBASE to the %BASE% section of
the local DBs desc files and for parsing it again when loading the local
DB

Signed-off-by: Johannes Löthberg <johannes at kyriasis.com>
---
 lib/libalpm/be_local.c   | 6 ++++++
 lib/libalpm/be_package.c | 2 +-
 lib/libalpm/be_sync.c    | 2 ++
 lib/libalpm/package.h    | 1 +
 4 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
index 9376396..54d3099 100644
--- a/lib/libalpm/be_local.c
+++ b/lib/libalpm/be_local.c
@@ -701,6 +701,8 @@ static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq)
 					_alpm_log(db->handle, ALPM_LOG_ERROR, _("%s database is inconsistent: version "
 								"mismatch on package %s\n"), db->treename, info->name);
 				}
+			} else if(strcmp(line, "%BASE%") == 0) {
+				READ_AND_STORE(info->base);
 			} else if(strcmp(line, "%DESC%") == 0) {
 				READ_AND_STORE(info->desc);
 			} else if(strcmp(line, "%GROUPS%") == 0) {
@@ -904,6 +906,10 @@ int _alpm_local_db_write(alpm_db_t *db, alpm_pkg_t *info, alpm_dbinfrq_t inforeq
 		free(path);
 		fprintf(fp, "%%NAME%%\n%s\n\n"
 						"%%VERSION%%\n%s\n\n", info->name, info->version);
+		if(info->base) {
+			fprintf(fp, "%%BASE%%\n"
+							"%s\n\n", info->base);
+		}
 		if(info->desc) {
 			fprintf(fp, "%%DESC%%\n"
 							"%s\n\n", info->desc);
diff --git a/lib/libalpm/be_package.c b/lib/libalpm/be_package.c
index 5617f4f..2d42465 100644
--- a/lib/libalpm/be_package.c
+++ b/lib/libalpm/be_package.c
@@ -193,7 +193,7 @@ static int parse_descfile(alpm_handle_t *handle, struct archive *a, alpm_pkg_t *
 				STRDUP(newpkg->name, ptr, return -1);
 				newpkg->name_hash = _alpm_hash_sdbm(newpkg->name);
 			} else if(strcmp(key, "pkgbase") == 0) {
-				/* not used atm */
+				STRDUP(newpkg->base, ptr, return -1);
 			} else if(strcmp(key, "pkgver") == 0) {
 				STRDUP(newpkg->version, ptr, return -1);
 			} else if(strcmp(key, "basever") == 0) {
diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c
index 5245948..6e89ad9 100644
--- a/lib/libalpm/be_sync.c
+++ b/lib/libalpm/be_sync.c
@@ -614,6 +614,8 @@ static int sync_db_read(alpm_db_t *db, struct archive *archive,
 				if(_alpm_validate_filename(db, pkg->name, pkg->filename) < 0) {
 					return -1;
 				}
+			} else if(strcmp(line, "%BASE%") == 0) {
+				READ_AND_STORE(pkg->base);
 			} else if(strcmp(line, "%DESC%") == 0) {
 				READ_AND_STORE(pkg->desc);
 			} else if(strcmp(line, "%GROUPS%") == 0) {
diff --git a/lib/libalpm/package.h b/lib/libalpm/package.h
index 357c20e..98c1e6d 100644
--- a/lib/libalpm/package.h
+++ b/lib/libalpm/package.h
@@ -85,6 +85,7 @@ extern struct pkg_operations default_pkg_ops;
 struct __alpm_pkg_t {
 	unsigned long name_hash;
 	char *filename;
+	char *base;
 	char *name;
 	char *version;
 	char *desc;
-- 
2.2.0


More information about the pacman-dev mailing list