[pacman-dev] [PATCH 1/2] libalpm: Parse and write PKGBASEs
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@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
This commit adds the necessary accessor functions to get the PKGBASE of a package, forcing the desc file to be parsed. Signed-off-by: Johannes Löthberg <johannes@kyriasis.com> --- lib/libalpm/alpm.h | 6 ++++++ lib/libalpm/be_local.c | 7 +++++++ lib/libalpm/package.c | 9 +++++++++ lib/libalpm/package.h | 1 + 4 files changed, 23 insertions(+) diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index e6ef3ae..91b9461 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -1101,6 +1101,12 @@ int alpm_pkg_should_ignore(alpm_handle_t *handle, alpm_pkg_t *pkg); */ const char *alpm_pkg_get_filename(alpm_pkg_t *pkg); +/** Returns the package base name. + * @param pkg a pointer to package + * @return a reference to an internal string + */ +const char *alpm_pkg_get_base(alpm_pkg_t *pkg); + /** Returns the package name. * @param pkg a pointer to package * @return a reference to an internal string diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c index 54d3099..dbdfc99 100644 --- a/lib/libalpm/be_local.c +++ b/lib/libalpm/be_local.c @@ -63,6 +63,12 @@ static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq); * initialized. */ +static const char *_cache_get_base(alpm_pkg_t *pkg) +{ + LAZY_LOAD(INFRQ_DESC, NULL); + return pkg->base; +} + static const char *_cache_get_desc(alpm_pkg_t *pkg) { LAZY_LOAD(INFRQ_DESC, NULL); @@ -297,6 +303,7 @@ static int _cache_force_load(alpm_pkg_t *pkg) * logic. */ static struct pkg_operations local_pkg_ops = { + .get_base = _cache_get_base, .get_desc = _cache_get_desc, .get_url = _cache_get_url, .get_builddate = _cache_get_builddate, diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c index e2997f6..92fcb2a 100644 --- a/lib/libalpm/package.c +++ b/lib/libalpm/package.c @@ -83,6 +83,7 @@ int SYMEXPORT alpm_pkg_checkmd5sum(alpm_pkg_t *pkg) * backend logic that needs lazy access, such as the local database through * a lazy-load cache. However, the defaults will work just fine for fully- * populated package structures. */ +static const char *_pkg_get_base(alpm_pkg_t *pkg) { return pkg->base; } static const char *_pkg_get_desc(alpm_pkg_t *pkg) { return pkg->desc; } static const char *_pkg_get_url(alpm_pkg_t *pkg) { return pkg->url; } static alpm_time_t _pkg_get_builddate(alpm_pkg_t *pkg) { return pkg->builddate; } @@ -144,6 +145,7 @@ static int _pkg_force_load(alpm_pkg_t UNUSED *pkg) { return 0; } * struct itself with no abstraction layer or any type of lazy loading. */ struct pkg_operations default_pkg_ops = { + .get_base = _pkg_get_base, .get_desc = _pkg_get_desc, .get_url = _pkg_get_url, .get_builddate = _pkg_get_builddate, @@ -186,6 +188,13 @@ const char SYMEXPORT *alpm_pkg_get_filename(alpm_pkg_t *pkg) return pkg->filename; } +const char SYMEXPORT *alpm_pkg_get_base(alpm_pkg_t *pkg) +{ + ASSERT(pkg != NULL, return NULL); + pkg->handle->pm_errno = 0; + return pkg->ops->get_base(pkg); +} + const char SYMEXPORT *alpm_pkg_get_name(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); diff --git a/lib/libalpm/package.h b/lib/libalpm/package.h index 98c1e6d..5ab9b20 100644 --- a/lib/libalpm/package.h +++ b/lib/libalpm/package.h @@ -43,6 +43,7 @@ * defined default_pkg_ops struct to work just fine for their needs. */ struct pkg_operations { + const char *(*get_base) (alpm_pkg_t *); const char *(*get_desc) (alpm_pkg_t *); const char *(*get_url) (alpm_pkg_t *); alpm_time_t (*get_builddate) (alpm_pkg_t *); -- 2.2.0
On 21/12/14 02:25, Johannes Löthberg wrote:
This commit adds the necessary accessor functions to get the PKGBASE of a package, forcing the desc file to be parsed.
Signed-off-by: Johannes Löthberg <johannes@kyriasis.com> --- lib/libalpm/alpm.h | 6 ++++++ lib/libalpm/be_local.c | 7 +++++++ lib/libalpm/package.c | 9 +++++++++ lib/libalpm/package.h | 1 + 4 files changed, 23 insertions(+)
Are we expecting a third patch to actually do something with this? Maybe something like: $ pacman -Si gcc-libs Repository : core Name : gcc-libs (gcc) Version : 4.9.2-1
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index e6ef3ae..91b9461 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -1101,6 +1101,12 @@ int alpm_pkg_should_ignore(alpm_handle_t *handle, alpm_pkg_t *pkg); */ const char *alpm_pkg_get_filename(alpm_pkg_t *pkg);
+/** Returns the package base name. + * @param pkg a pointer to package + * @return a reference to an internal string + */ +const char *alpm_pkg_get_base(alpm_pkg_t *pkg); +
OK - see my new rule about adding this change to README. Give that was posted after you submitted this, I can handle it.
/** Returns the package name. * @param pkg a pointer to package * @return a reference to an internal string diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c index 54d3099..dbdfc99 100644 --- a/lib/libalpm/be_local.c +++ b/lib/libalpm/be_local.c @@ -63,6 +63,12 @@ static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq); * initialized. */
+static const char *_cache_get_base(alpm_pkg_t *pkg) +{ + LAZY_LOAD(INFRQ_DESC, NULL); + return pkg->base; +} +
OK
static const char *_cache_get_desc(alpm_pkg_t *pkg) { LAZY_LOAD(INFRQ_DESC, NULL); @@ -297,6 +303,7 @@ static int _cache_force_load(alpm_pkg_t *pkg) * logic. */ static struct pkg_operations local_pkg_ops = { + .get_base = _cache_get_base, .get_desc = _cache_get_desc, .get_url = _cache_get_url, .get_builddate = _cache_get_builddate,
OK
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c index e2997f6..92fcb2a 100644 --- a/lib/libalpm/package.c +++ b/lib/libalpm/package.c @@ -83,6 +83,7 @@ int SYMEXPORT alpm_pkg_checkmd5sum(alpm_pkg_t *pkg) * backend logic that needs lazy access, such as the local database through * a lazy-load cache. However, the defaults will work just fine for fully- * populated package structures. */ +static const char *_pkg_get_base(alpm_pkg_t *pkg) { return pkg->base; }
OK
static const char *_pkg_get_desc(alpm_pkg_t *pkg) { return pkg->desc; } static const char *_pkg_get_url(alpm_pkg_t *pkg) { return pkg->url; } static alpm_time_t _pkg_get_builddate(alpm_pkg_t *pkg) { return pkg->builddate; } @@ -144,6 +145,7 @@ static int _pkg_force_load(alpm_pkg_t UNUSED *pkg) { return 0; } * struct itself with no abstraction layer or any type of lazy loading. */ struct pkg_operations default_pkg_ops = { + .get_base = _pkg_get_base,
OK
.get_desc = _pkg_get_desc, .get_url = _pkg_get_url, .get_builddate = _pkg_get_builddate, @@ -186,6 +188,13 @@ const char SYMEXPORT *alpm_pkg_get_filename(alpm_pkg_t *pkg) return pkg->filename; }
+const char SYMEXPORT *alpm_pkg_get_base(alpm_pkg_t *pkg) +{ + ASSERT(pkg != NULL, return NULL); + pkg->handle->pm_errno = 0; + return pkg->ops->get_base(pkg); +} +
OK.
const char SYMEXPORT *alpm_pkg_get_name(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); diff --git a/lib/libalpm/package.h b/lib/libalpm/package.h index 98c1e6d..5ab9b20 100644 --- a/lib/libalpm/package.h +++ b/lib/libalpm/package.h @@ -43,6 +43,7 @@ * defined default_pkg_ops struct to work just fine for their needs. */ struct pkg_operations { + const char *(*get_base) (alpm_pkg_t *);
OK.
const char *(*get_desc) (alpm_pkg_t *); const char *(*get_url) (alpm_pkg_t *); alpm_time_t (*get_builddate) (alpm_pkg_t *);
On 22/12, Allan McRae wrote:
On 21/12/14 02:25, Johannes Löthberg wrote:
This commit adds the necessary accessor functions to get the PKGBASE of a package, forcing the desc file to be parsed.
Signed-off-by: Johannes Löthberg <johannes@kyriasis.com> --- lib/libalpm/alpm.h | 6 ++++++ lib/libalpm/be_local.c | 7 +++++++ lib/libalpm/package.c | 9 +++++++++ lib/libalpm/package.h | 1 + 4 files changed, 23 insertions(+)
Are we expecting a third patch to actually do something with this? Maybe something like:
$ pacman -Si gcc-libs Repository : core Name : gcc-libs (gcc) Version : 4.9.2-1
Not right now, but that would be useful sometimes too, either in parens or as a separate line in -Sii maybe.
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index e6ef3ae..91b9461 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -1101,6 +1101,12 @@ int alpm_pkg_should_ignore(alpm_handle_t *handle, alpm_pkg_t *pkg); */ const char *alpm_pkg_get_filename(alpm_pkg_t *pkg);
+/** Returns the package base name. + * @param pkg a pointer to package + * @return a reference to an internal string + */ +const char *alpm_pkg_get_base(alpm_pkg_t *pkg); +
OK - see my new rule about adding this change to README. Give that was posted after you submitted this, I can handle it.
Should I add another header from 4.2→4.3 in that case? -- Sincerely, Johannes Löthberg PGP Key ID: 0x50FB9B273A9D0BB5 https://theos.kyriasis.com/~kyrias/
On 22/12, Johannes Löthberg wrote:
On 22/12, Allan McRae wrote:
On 21/12/14 02:25, Johannes Löthberg wrote:
This commit adds the necessary accessor functions to get the PKGBASE of a package, forcing the desc file to be parsed.
Signed-off-by: Johannes Löthberg <johannes@kyriasis.com> --- lib/libalpm/alpm.h | 6 ++++++ lib/libalpm/be_local.c | 7 +++++++ lib/libalpm/package.c | 9 +++++++++ lib/libalpm/package.h | 1 + 4 files changed, 23 insertions(+)
Are we expecting a third patch to actually do something with this? Maybe something like:
$ pacman -Si gcc-libs Repository : core Name : gcc-libs (gcc) Version : 4.9.2-1
Not right now, but that would be useful sometimes too, either in parens or as a separate line in -Sii maybe.
Oh right, forgot to say that I firstly wanted to implement it to be able to show it in expac for scripting. (Not for myself though.) -- Sincerely, Johannes Löthberg PGP Key ID: 0x50FB9B273A9D0BB5 https://theos.kyriasis.com/~kyrias/
On 21/12/14 02:25, Johannes Löthberg wrote:
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@kyriasis.com>
You need to free the pkg->base memory in _alpm_pkg_free and copy it in _alpm_pkg_dup. Otherwise fine.
--- 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);
OK. (memory leak)
} 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); + }
OK
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);
OK. (memory leak)
} 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);
OK. (memory leak) Slightly surprized we did not have a placeholder here already.
} 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;
OK.
char *name; char *version; char *desc;
On 22/12, Allan McRae wrote:
On 21/12/14 02:25, Johannes Löthberg wrote:
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@kyriasis.com>
You need to free the pkg->base memory in _alpm_pkg_free and copy it in _alpm_pkg_dup. Otherwise fine.
Crap, that completely slipped my mind. Thanks. -- Sincerely, Johannes Löthberg PGP Key ID: 0x50FB9B273A9D0BB5 https://theos.kyriasis.com/~kyrias/
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@kyriasis.com> --- lib/libalpm/be_local.c | 6 ++++++ lib/libalpm/be_package.c | 2 +- lib/libalpm/be_sync.c | 2 ++ lib/libalpm/package.c | 2 ++ lib/libalpm/package.h | 1 + 5 files changed, 12 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.c b/lib/libalpm/package.c index e2997f6..3be5e74 100644 --- a/lib/libalpm/package.c +++ b/lib/libalpm/package.c @@ -566,6 +566,7 @@ int _alpm_pkg_dup(alpm_pkg_t *pkg, alpm_pkg_t **new_ptr) newpkg->name_hash = pkg->name_hash; STRDUP(newpkg->filename, pkg->filename, goto cleanup); + STRDUP(newpkg->base, pkg->base, goto cleanup); STRDUP(newpkg->name, pkg->name, goto cleanup); STRDUP(newpkg->version, pkg->version, goto cleanup); STRDUP(newpkg->desc, pkg->desc, goto cleanup); @@ -641,6 +642,7 @@ void _alpm_pkg_free(alpm_pkg_t *pkg) } FREE(pkg->filename); + FREE(pkg->base); FREE(pkg->name); FREE(pkg->version); FREE(pkg->desc); 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
This commit adds the necessary accessor functions to get the PKGBASE of a package, forcing the desc file to be parsed. Signed-off-by: Johannes Löthberg <johannes@kyriasis.com> --- lib/libalpm/alpm.h | 6 ++++++ lib/libalpm/be_local.c | 7 +++++++ lib/libalpm/package.c | 9 +++++++++ lib/libalpm/package.h | 1 + 4 files changed, 23 insertions(+) diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index e6ef3ae..91b9461 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -1101,6 +1101,12 @@ int alpm_pkg_should_ignore(alpm_handle_t *handle, alpm_pkg_t *pkg); */ const char *alpm_pkg_get_filename(alpm_pkg_t *pkg); +/** Returns the package base name. + * @param pkg a pointer to package + * @return a reference to an internal string + */ +const char *alpm_pkg_get_base(alpm_pkg_t *pkg); + /** Returns the package name. * @param pkg a pointer to package * @return a reference to an internal string diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c index 54d3099..dbdfc99 100644 --- a/lib/libalpm/be_local.c +++ b/lib/libalpm/be_local.c @@ -63,6 +63,12 @@ static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq); * initialized. */ +static const char *_cache_get_base(alpm_pkg_t *pkg) +{ + LAZY_LOAD(INFRQ_DESC, NULL); + return pkg->base; +} + static const char *_cache_get_desc(alpm_pkg_t *pkg) { LAZY_LOAD(INFRQ_DESC, NULL); @@ -297,6 +303,7 @@ static int _cache_force_load(alpm_pkg_t *pkg) * logic. */ static struct pkg_operations local_pkg_ops = { + .get_base = _cache_get_base, .get_desc = _cache_get_desc, .get_url = _cache_get_url, .get_builddate = _cache_get_builddate, diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c index 3be5e74..ce6b0a2 100644 --- a/lib/libalpm/package.c +++ b/lib/libalpm/package.c @@ -83,6 +83,7 @@ int SYMEXPORT alpm_pkg_checkmd5sum(alpm_pkg_t *pkg) * backend logic that needs lazy access, such as the local database through * a lazy-load cache. However, the defaults will work just fine for fully- * populated package structures. */ +static const char *_pkg_get_base(alpm_pkg_t *pkg) { return pkg->base; } static const char *_pkg_get_desc(alpm_pkg_t *pkg) { return pkg->desc; } static const char *_pkg_get_url(alpm_pkg_t *pkg) { return pkg->url; } static alpm_time_t _pkg_get_builddate(alpm_pkg_t *pkg) { return pkg->builddate; } @@ -144,6 +145,7 @@ static int _pkg_force_load(alpm_pkg_t UNUSED *pkg) { return 0; } * struct itself with no abstraction layer or any type of lazy loading. */ struct pkg_operations default_pkg_ops = { + .get_base = _pkg_get_base, .get_desc = _pkg_get_desc, .get_url = _pkg_get_url, .get_builddate = _pkg_get_builddate, @@ -186,6 +188,13 @@ const char SYMEXPORT *alpm_pkg_get_filename(alpm_pkg_t *pkg) return pkg->filename; } +const char SYMEXPORT *alpm_pkg_get_base(alpm_pkg_t *pkg) +{ + ASSERT(pkg != NULL, return NULL); + pkg->handle->pm_errno = 0; + return pkg->ops->get_base(pkg); +} + const char SYMEXPORT *alpm_pkg_get_name(alpm_pkg_t *pkg) { ASSERT(pkg != NULL, return NULL); diff --git a/lib/libalpm/package.h b/lib/libalpm/package.h index 98c1e6d..5ab9b20 100644 --- a/lib/libalpm/package.h +++ b/lib/libalpm/package.h @@ -43,6 +43,7 @@ * defined default_pkg_ops struct to work just fine for their needs. */ struct pkg_operations { + const char *(*get_base) (alpm_pkg_t *); const char *(*get_desc) (alpm_pkg_t *); const char *(*get_url) (alpm_pkg_t *); alpm_time_t (*get_builddate) (alpm_pkg_t *); -- 2.2.0
participants (2)
-
Allan McRae
-
Johannes Löthberg