/* * pkg - Dependency database * Tracks package dependencies and installation reasons * https://rawnix.org * * Copyright (c) 2025 zorz@gmx.com * SPDX-License-Identifier: BSD-2-Clause */ #ifndef DEPDB_H #define DEPDB_H #include "pkg.h" #include "pkgdb.h" #include /* Installation reason */ typedef enum { REASON_MANUAL, /* user explicitly requested */ REASON_AUTO /* installed as dependency */ } install_reason_t; /* Dependency database entry */ typedef struct { char *name; char *version; char *release; install_reason_t reason; time_t install_time; strarray_t *depends; /* runtime deps — used for orphan detection */ } dep_entry_t; /* Hash table entry */ typedef struct depdb_hash { char *key; dep_entry_t *entry; struct depdb_hash *next; } depdb_hash_t; /* Dependency database */ typedef struct { depdb_hash_t **buckets; size_t bucket_count; size_t size; char *path; } depdb_t; /* Database management */ depdb_t *depdb_open(const char *root); void depdb_close(depdb_t *db); int depdb_save(depdb_t *db); /* Entry management */ dep_entry_t *dep_entry_new(const char *name, const char *version, const char *release, install_reason_t reason); void dep_entry_free(dep_entry_t *entry); /* Database operations */ int depdb_add(depdb_t *db, dep_entry_t *entry); dep_entry_t *depdb_find(depdb_t *db, const char *name); int depdb_remove(depdb_t *db, const char *name); /* Query operations */ strarray_t *depdb_list(depdb_t *db); strarray_t *depdb_rdeps(depdb_t *db, const char *pkg); strarray_t *depdb_auto_installed(depdb_t *db); /* Bootstrap: populate depdb from pkgdb for untracked packages. * Never overwrites existing entries. Returns number added. */ int depdb_initdb(depdb_t *db, pkgdb_t *pkgdb); /* Helpers */ const char *reason_str(install_reason_t reason); install_reason_t str_reason(const char *str); #endif /* DEPDB_H */