Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
add information about origin db
  • Loading branch information
vnepogodin committed Feb 2, 2023
1 parent 076bd55 commit a8a7114
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/libalpm/add.c
Expand Up @@ -69,6 +69,13 @@ int SYMEXPORT alpm_add_pkg(alpm_handle_t *handle, alpm_pkg_t *pkg)
pkgver = pkg->version;

_alpm_log(handle, ALPM_LOG_DEBUG, "adding package '%s'\n", pkgname);
const char* pkg_db_name = alpm_db_get_name(alpm_pkg_get_db(pkg));
if(pkg_db_name != NULL) {
if(pkg->installed_db != NULL) {
free(pkg->installed_db);
}
pkg->installed_db = strdup(pkg_db_name);
}

if((dup = alpm_pkg_find(trans->add, pkgname))) {
if(dup == pkg) {
Expand Down
5 changes: 5 additions & 0 deletions lib/libalpm/alpm.h
Expand Up @@ -2428,6 +2428,11 @@ const char *alpm_pkg_get_version(alpm_pkg_t *pkg);
*/
alpm_pkgfrom_t alpm_pkg_get_origin(alpm_pkg_t *pkg);

/** Returns the installed db of the package.
* @return an alpm_pkgfrom_t constant, -1 on error
*/
const char* alpm_pkg_get_installed_db(alpm_pkg_t *pkg);

/** Returns the package description.
* @param pkg a pointer to package
* @return a reference to an internal string
Expand Down
13 changes: 13 additions & 0 deletions lib/libalpm/be_local.c
Expand Up @@ -195,6 +195,12 @@ static alpm_list_t *_cache_get_backup(alpm_pkg_t *pkg)
return pkg->backup;
}

static const char *_cache_get_installed_db(alpm_pkg_t *pkg)
{
LAZY_LOAD(INFRQ_DESC);
return pkg->installed_db;
}

/**
* Open a package changelog for reading. Similar to fopen in functionality,
* except that the returned 'file stream' is from the database.
Expand Down Expand Up @@ -337,6 +343,7 @@ static const struct pkg_operations local_pkg_ops = {
.get_isize = _cache_get_isize,
.get_reason = _cache_get_reason,
.get_validation = _cache_get_validation,
.get_installed_db = _cache_get_installed_db,
.has_scriptlet = _cache_has_scriptlet,
.get_licenses = _cache_get_licenses,
.get_groups = _cache_get_groups,
Expand Down Expand Up @@ -756,6 +763,8 @@ static int local_db_read(alpm_pkg_t *info, int inforeq)
READ_AND_STORE_ALL(info->licenses);
} else if(strcmp(line, "%ARCH%") == 0) {
READ_AND_STORE(info->arch);
} else if(strcmp(line, "%INSTALLED_DB%") == 0) {
READ_AND_STORE(info->installed_db);
} else if(strcmp(line, "%BUILDDATE%") == 0) {
READ_NEXT();
info->builddate = _alpm_parsedate(line);
Expand Down Expand Up @@ -980,6 +989,10 @@ int _alpm_local_db_write(alpm_db_t *db, alpm_pkg_t *info, int inforeq)
fprintf(fp, "%%ARCH%%\n"
"%s\n\n", info->arch);
}
if(info->installed_db) {
fprintf(fp, "%%INSTALLED_DB%%\n"
"%s\n\n", info->installed_db);
}
if(info->builddate) {
fprintf(fp, "%%BUILDDATE%%\n"
"%jd\n\n", (intmax_t)info->builddate);
Expand Down
11 changes: 11 additions & 0 deletions lib/libalpm/package.c
Expand Up @@ -86,6 +86,7 @@ static off_t _pkg_get_isize(alpm_pkg_t *pkg) { return pkg->isize; }
static alpm_pkgreason_t _pkg_get_reason(alpm_pkg_t *pkg) { return pkg->reason; }
static int _pkg_get_validation(alpm_pkg_t *pkg) { return pkg->validation; }
static int _pkg_has_scriptlet(alpm_pkg_t *pkg) { return pkg->scriptlet; }
static const char *_pkg_get_installed_db(alpm_pkg_t *pkg) { return pkg->installed_db; }

static alpm_list_t *_pkg_get_licenses(alpm_pkg_t *pkg) { return pkg->licenses; }
static alpm_list_t *_pkg_get_groups(alpm_pkg_t *pkg) { return pkg->groups; }
Expand Down Expand Up @@ -150,6 +151,7 @@ const struct pkg_operations default_pkg_ops = {
.get_reason = _pkg_get_reason,
.get_validation = _pkg_get_validation,
.has_scriptlet = _pkg_has_scriptlet,
.get_installed_db = _pkg_get_installed_db,

.get_licenses = _pkg_get_licenses,
.get_groups = _pkg_get_groups,
Expand Down Expand Up @@ -212,6 +214,13 @@ alpm_pkgfrom_t SYMEXPORT alpm_pkg_get_origin(alpm_pkg_t *pkg)
return pkg->origin;
}

const char SYMEXPORT *alpm_pkg_get_installed_db(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return NULL);
pkg->handle->pm_errno = ALPM_ERR_OK;
return pkg->ops->get_installed_db(pkg);
}

const char SYMEXPORT *alpm_pkg_get_desc(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return NULL);
Expand Down Expand Up @@ -609,6 +618,7 @@ int _alpm_pkg_dup(alpm_pkg_t *pkg, alpm_pkg_t **new_ptr)
STRDUP(newpkg->name, pkg->name, goto cleanup);
STRDUP(newpkg->version, pkg->version, goto cleanup);
STRDUP(newpkg->desc, pkg->desc, goto cleanup);
STRDUP(newpkg->installed_db, pkg->installed_db, goto cleanup);
STRDUP(newpkg->url, pkg->url, goto cleanup);
newpkg->builddate = pkg->builddate;
newpkg->installdate = pkg->installdate;
Expand Down Expand Up @@ -682,6 +692,7 @@ void _alpm_pkg_free(alpm_pkg_t *pkg)
FREE(pkg->name);
FREE(pkg->version);
FREE(pkg->desc);
FREE(pkg->installed_db);
FREE(pkg->url);
FREE(pkg->packager);
FREE(pkg->md5sum);
Expand Down
2 changes: 2 additions & 0 deletions lib/libalpm/package.h
Expand Up @@ -54,6 +54,7 @@ struct pkg_operations {
alpm_pkgreason_t (*get_reason) (alpm_pkg_t *);
int (*get_validation) (alpm_pkg_t *);
int (*has_scriptlet) (alpm_pkg_t *);
const char *(*get_installed_db) (alpm_pkg_t *);

alpm_list_t *(*get_licenses) (alpm_pkg_t *);
alpm_list_t *(*get_groups) (alpm_pkg_t *);
Expand Down Expand Up @@ -98,6 +99,7 @@ struct __alpm_pkg_t {
char *sha256sum;
char *base64_sig;
char *arch;
char *installed_db;

alpm_time_t builddate;
alpm_time_t installdate;
Expand Down
7 changes: 7 additions & 0 deletions lib/libalpm/sync.c
Expand Up @@ -240,6 +240,12 @@ int SYMEXPORT alpm_sync_sysupgrade(alpm_handle_t *handle, int enable_downgrade)
alpm_pkg_t *spkg = _alpm_db_get_pkgfromcache(sdb, lpkg->name);
if(spkg) {
if(check_literal(handle, lpkg, spkg, enable_downgrade)) {
const char* sdb_name = alpm_db_get_name(sdb);
if (spkg->installed_db != NULL) {
free(spkg->installed_db);
}

spkg->installed_db = (sdb_name) ? strdup(sdb_name) : NULL;
trans->add = alpm_list_add(trans->add, spkg);
}
/* jump to next local package */
Expand Down Expand Up @@ -1092,6 +1098,7 @@ static int load_packages(alpm_handle_t *handle, alpm_list_t **data,
_alpm_log(handle, ALPM_LOG_DEBUG, "failed to load pkgfile internal\n");
error = 1;
} else {
pkgfile->installed_db = (spkg->installed_db) ? strdup(spkg->installed_db) : NULL;
if(strcmp(spkg->name, pkgfile->name) != 0) {
_alpm_log(handle, ALPM_LOG_DEBUG,
"internal package name mismatch, expected: '%s', actual: '%s'\n",
Expand Down
6 changes: 6 additions & 0 deletions src/pacman/package.c
Expand Up @@ -64,6 +64,7 @@ enum {
T_PROVIDES,
T_REPLACES,
T_REPOSITORY,
T_FROM_DB,
T_REQUIRED_BY,
T_SHA_256_SUM,
T_SIGNATURES,
Expand Down Expand Up @@ -118,6 +119,7 @@ static void make_aligned_titles(void)
buf[T_PROVIDES] = _("Provides");
buf[T_REPLACES] = _("Replaces");
buf[T_REPOSITORY] = _("Repository");
buf[T_FROM_DB] = _("Installed From");
buf[T_REQUIRED_BY] = _("Required By");
buf[T_SHA_256_SUM] = _("SHA-256 Sum");
buf[T_SIGNATURES] = _("Signatures");
Expand Down Expand Up @@ -262,6 +264,10 @@ void dump_pkg_full(alpm_pkg_t *pkg, int extra)
string_display(titles[T_REPOSITORY],
alpm_db_get_name(alpm_pkg_get_db(pkg)), cols);
}
if(from == ALPM_PKG_FROM_LOCALDB) {
string_display(titles[T_FROM_DB],
alpm_pkg_get_installed_db(pkg), cols);
}
string_display(titles[T_NAME], alpm_pkg_get_name(pkg), cols);
string_display(titles[T_VERSION], alpm_pkg_get_version(pkg), cols);
string_display(titles[T_DESCRIPTION], alpm_pkg_get_desc(pkg), cols);
Expand Down

0 comments on commit a8a7114

Please sign in to comment.