summaryrefslogtreecommitdiff
path: root/repo.h
blob: 446940b7b37671923e5886342822c771a31ca728 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*
 * 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 */