/* * pkg - Repository scanner * https://rawnix.org * * Copyright (c) 2025 zorz@gmx.com * SPDX-License-Identifier: BSD-2-Clause */ #ifndef REPO_H #define REPO_H #include "pkg.h" /* A port directory containing MAKEPKG */ typedef struct { char *name; char *path; char *collection; package_t *pkg; /* lazy loaded */ bool bad_name; /* recipe name= differs from the directory */ } port_t; /* Hash table entry */ typedef struct repo_hash { char *key; port_t *port; struct repo_hash *next; } repo_hash_t; /* Provides index entry: virtual name -> list of provider port names */ typedef struct provides_hash { char *key; /* virtual package name */ strarray_t providers; /* port names with key in provides=() */ struct provides_hash *next; } provides_hash_t; /* Repository */ typedef struct { repo_hash_t **buckets; size_t bucket_count; size_t size; /* lazily built provides index (see repo_providers) */ provides_hash_t **provides_buckets; bool provides_built; } repo_t; /* Repository management */ repo_t *repo_new(void); void repo_free(repo_t *repo); /* Scanning */ int repo_scan(repo_t *repo, const char *dir, const char *collection); int repo_scan_all(repo_t *repo, char **dirs, size_t count); /* Queries */ port_t *repo_find(repo_t *repo, const char *name); strarray_t *repo_list(repo_t *repo); strarray_t *repo_find_variants(repo_t *repo, const char *name); /* Check if any installed package provides a virtual package */ bool repo_provides(repo_t *repo, const char *name); /* * O(1) provider lookup. Returns the internal list of port names * that declare 'name' in provides=(), or NULL if none. The array * is owned by the repo — do NOT free or modify it. * First call builds the index (loads every port once); subsequent * calls are hash lookups. */ strarray_t *repo_providers(repo_t *repo, const char *name); /* Port functions */ port_t *port_new(const char *name, const char *path, const char *collection); void port_free(port_t *port); int port_load(port_t *port); /* True if the port has a MAKEPKG.lock (read by port_load and mkpkg * in preference to MAKEPKG) */ bool port_recipe_locked(const port_t *port); #endif /* REPO_H */