do not ignore disabled/considered flags for src packages
[platform/upstream/libsolv.git] / src / repo.h
1 /*
2  * Copyright (c) 2007, Novell Inc.
3  *
4  * This program is licensed under the BSD license, read LICENSE.BSD
5  * for further information
6  */
7
8 /*
9  * repo.h
10  * 
11  */
12
13 #ifndef LIBSOLV_REPO_H
14 #define LIBSOLV_REPO_H
15
16 #include "pooltypes.h"
17 #include "pool.h"
18 #include "repodata.h"
19 #include "dataiterator.h"
20 #include "hash.h"
21
22
23
24 typedef struct _Repo {
25   const char *name;             /* name pointer */
26   Id repoid;                    /* our id */
27   void *appdata;                /* application private pointer */
28
29   Pool *pool;                   /* pool containing this repo */
30
31   int start;                    /* start of this repo solvables within pool->solvables */
32   int end;                      /* last solvable + 1 of this repo */
33   int nsolvables;               /* number of solvables repo is contributing to pool */
34
35   int disabled;                 /* ignore the solvables? */
36   int priority;                 /* priority of this repo */
37   int subpriority;              /* sub-priority of this repo, used just for sorting, not pruning */
38
39   Id *idarraydata;              /* array of metadata Ids, solvable dependencies are offsets into this array */
40   int idarraysize;
41
42   unsigned nrepodata;           /* number of our stores..  */
43
44   Id *rpmdbid;                  /* solvable side data: rpm database id */
45
46 #ifdef LIBSOLV_INTERNAL
47   Repodata *repodata;           /* our stores for non-solvable related data */
48   Offset lastoff;               /* start of last array in idarraydata */
49
50   Hashtable lastidhash;         /* hash to speed up repo_addid_dep */
51   Hashmask lastidhash_mask;
52   int lastidhash_idarraysize;
53   int lastmarker;
54   Offset lastmarkerpos;
55 #endif /* LIBSOLV_INTERNAL */
56 } Repo;
57
58 extern Repo *repo_create(Pool *pool, const char *name);
59 extern void repo_free(Repo *repo, int reuseids);
60 extern void repo_empty(Repo *repo, int reuseids);
61 extern void repo_freedata(Repo *repo);
62 extern Id repo_add_solvable(Repo *repo);
63 extern Id repo_add_solvable_block(Repo *repo, int count);
64 extern void repo_free_solvable(Repo *repo, Id p, int reuseids);
65 extern void repo_free_solvable_block(Repo *repo, Id start, int count, int reuseids);
66 extern void *repo_sidedata_create(Repo *repo, size_t size);
67 extern void *repo_sidedata_extend(Repo *repo, void *b, size_t size, Id p, int count);
68
69 extern Offset repo_addid(Repo *repo, Offset olddeps, Id id);
70 extern Offset repo_addid_dep(Repo *repo, Offset olddeps, Id id, Id marker);
71 extern Offset repo_reserve_ids(Repo *repo, Offset olddeps, int num);
72 extern Offset repo_fix_supplements(Repo *repo, Offset provides, Offset supplements, Offset freshens);
73 extern Offset repo_fix_conflicts(Repo *repo, Offset conflicts);
74
75 static inline const char *repo_name(const Repo *repo)
76 {
77   return repo->name;
78 }
79
80 /* those two functions are here because they need the Repo definition */
81
82 static inline Repo *pool_id2repo(Pool *pool, Id repoid)
83 {
84   return repoid < pool->nrepos ? pool->repos[repoid] : 0;
85 }
86
87 static inline int pool_disabled_solvable(const Pool *pool, Solvable *s)
88 {
89   if (s->repo && s->repo->disabled)
90     return 1;
91   if (pool->considered)
92     { 
93       Id id = s - pool->solvables;
94       if (!MAPTST(pool->considered, id))
95         return 1;
96     }
97   return 0;
98 }
99
100 static inline int pool_installable(const Pool *pool, Solvable *s)
101 {
102   if (!s->arch || s->arch == ARCH_SRC || s->arch == ARCH_NOSRC)
103     return 0;
104   if (s->repo && s->repo->disabled)
105     return 0;
106   if (pool->id2arch && (s->arch > pool->lastarch || !pool->id2arch[s->arch]))
107     return 0;
108   if (pool->considered)
109     { 
110       Id id = s - pool->solvables;
111       if (!MAPTST(pool->considered, id))
112         return 0;
113     }
114   return 1;
115 }
116
117 /* search callback values */
118 #define SEARCH_NEXT_KEY         1
119 #define SEARCH_NEXT_SOLVABLE    2
120 #define SEARCH_STOP             3
121 #define SEARCH_ENTERSUB         -1
122
123 /* standard flags used in the repo_add functions */
124 #define REPO_REUSE_REPODATA             (1 << 0)
125 #define REPO_NO_INTERNALIZE             (1 << 1)
126 #define REPO_LOCALPOOL                  (1 << 2)
127 #define REPO_USE_LOADING                (1 << 3)
128 #define REPO_EXTEND_SOLVABLES           (1 << 4)
129 #define REPO_USE_ROOTDIR                (1 << 5)
130 #define REPO_NO_LOCATION                (1 << 6)
131
132 Repodata *repo_add_repodata(Repo *repo, int flags);
133 Repodata *repo_id2repodata(Repo *repo, Id id);
134 Repodata *repo_last_repodata(Repo *repo);
135
136 void repo_search(Repo *repo, Id p, Id key, const char *match, int flags, int (*callback)(void *cbdata, Solvable *s, Repodata *data, Repokey *key, KeyValue *kv), void *cbdata);
137
138 /* returns the string value of the attribute, or NULL if not found */
139 Id repo_lookup_type(Repo *repo, Id entry, Id keyname);
140 const char *repo_lookup_str(Repo *repo, Id entry, Id keyname);
141 /* returns the integer value of the attribute, or notfound if not found */
142 unsigned long long repo_lookup_num(Repo *repo, Id entry, Id keyname, unsigned long long notfound);
143 Id repo_lookup_id(Repo *repo, Id entry, Id keyname);
144 int repo_lookup_idarray(Repo *repo, Id entry, Id keyname, Queue *q);
145 int repo_lookup_deparray(Repo *repo, Id entry, Id keyname, Queue *q, Id marker);
146 int repo_lookup_void(Repo *repo, Id entry, Id keyname);
147 const char *repo_lookup_checksum(Repo *repo, Id entry, Id keyname, Id *typep);
148 const unsigned char *repo_lookup_bin_checksum(Repo *repo, Id entry, Id keyname, Id *typep);
149
150 void repo_set_id(Repo *repo, Id p, Id keyname, Id id);
151 void repo_set_num(Repo *repo, Id p, Id keyname, unsigned long long num);
152 void repo_set_str(Repo *repo, Id p, Id keyname, const char *str);
153 void repo_set_poolstr(Repo *repo, Id p, Id keyname, const char *str);
154 void repo_add_poolstr_array(Repo *repo, Id p, Id keyname, const char *str);
155 void repo_add_idarray(Repo *repo, Id p, Id keyname, Id id);
156 void repo_add_deparray(Repo *repo, Id p, Id keyname, Id dep, Id marker);
157 void repo_set_idarray(Repo *repo, Id p, Id keyname, Queue *q);
158 void repo_set_deparray(Repo *repo, Id p, Id keyname, Queue *q, Id marker);
159 void repo_unset(Repo *repo, Id p, Id keyname);
160  
161 void repo_internalize(Repo *repo);
162 void repo_disable_paging(Repo *repo);
163
164 /* iterator macros */
165 #define FOR_REPO_SOLVABLES(r, p, s)                                             \
166   for (p = (r)->start, s = (r)->pool->solvables + p; p < (r)->end; p++, s = (r)->pool->solvables + p)   \
167     if (s->repo != (r))                                                         \
168       continue;                                                                 \
169     else
170
171 #ifdef LIBSOLV_INTERNAL
172 #define FOR_REPODATAS(repo, rdid, data) \
173         for (rdid = 1, data = repo->repodata + rdid; rdid < repo->nrepodata; rdid++, data++)
174 #else
175 #define FOR_REPODATAS(repo, rdid, data) \
176         for (rdid = 1; rdid < repo->nrepodata && (data = repo_id2repodata(repo, rdid)); rdid++)
177 #endif
178
179 #endif /* LIBSOLV_REPO_H */