pool.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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. * pool.h
  9. *
  10. */
  11. #ifndef LIBSOLV_POOL_H
  12. #define LIBSOLV_POOL_H
  13. #include <stdio.h>
  14. #include "solvversion.h"
  15. #include "pooltypes.h"
  16. #include "poolid.h"
  17. #include "solvable.h"
  18. #include "bitmap.h"
  19. #include "queue.h"
  20. #include "strpool.h"
  21. /* well known ids */
  22. #include "knownid.h"
  23. #ifdef __cplusplus
  24. extern "C" {
  25. #endif
  26. /* well known solvable */
  27. #define SYSTEMSOLVABLE 1
  28. /*----------------------------------------------- */
  29. struct s_Repo;
  30. struct s_Repodata;
  31. struct s_Repokey;
  32. struct s_KeyValue;
  33. typedef struct s_Datapos {
  34. struct s_Repo *repo;
  35. Id solvid;
  36. Id repodataid;
  37. Id schema;
  38. Id dp;
  39. } Datapos;
  40. #ifdef LIBSOLV_INTERNAL
  41. /* how many strings to maintain (round robin) */
  42. #define POOL_TMPSPACEBUF 16
  43. struct s_Pool_tmpspace {
  44. char *buf[POOL_TMPSPACEBUF];
  45. int len[POOL_TMPSPACEBUF];
  46. int n;
  47. };
  48. #endif
  49. struct s_Pool {
  50. void *appdata; /* application private pointer */
  51. struct s_Stringpool ss;
  52. Reldep *rels; /* table of rels: Id -> Reldep */
  53. int nrels; /* number of unique rels */
  54. struct s_Repo **repos;
  55. int nrepos; /* repos allocated */
  56. int urepos; /* repos in use */
  57. struct s_Repo *installed; /* packages considered installed */
  58. Solvable *solvables;
  59. int nsolvables; /* solvables allocated */
  60. const char **languages;
  61. int nlanguages;
  62. /* package manager type, deb/rpm */
  63. int disttype;
  64. Id *id2arch; /* map arch ids to scores */
  65. unsigned char *id2color; /* map arch ids to colors */
  66. Id lastarch; /* size of the id2arch/id2color arrays */
  67. Queue vendormap; /* map vendor to vendorclasses mask */
  68. const char **vendorclasses; /* vendor equivalence classes */
  69. /* providers data, as two-step indirect list
  70. * whatprovides[Id] -> Offset into whatprovidesdata for name
  71. * whatprovidesdata[Offset] -> 0-terminated list of solvables providing Id
  72. */
  73. Offset *whatprovides; /* Offset to providers of a specific name, Id -> Offset */
  74. Offset *whatprovides_rel; /* Offset to providers of a specific relation, Id -> Offset */
  75. Id *whatprovidesdata; /* Ids of solvable providing Id */
  76. Offset whatprovidesdataoff; /* next free slot within whatprovidesdata */
  77. int whatprovidesdataleft; /* number of 'free slots' within whatprovidesdata */
  78. /* If nonzero, then consider only the solvables with Ids set in this
  79. bitmap for solving. If zero, consider all solvables. */
  80. Map *considered;
  81. /* callback for REL_NAMESPACE dependencies handled by the application */
  82. Id (*nscallback)(struct s_Pool *, void *data, Id name, Id evr);
  83. void *nscallbackdata;
  84. /* debug mask and callback */
  85. int debugmask;
  86. void (*debugcallback)(struct s_Pool *, void *data, int type, const char *str);
  87. void *debugcallbackdata;
  88. /* load callback */
  89. int (*loadcallback)(struct s_Pool *, struct s_Repodata *, void *);
  90. void *loadcallbackdata;
  91. /* search position */
  92. Datapos pos;
  93. Queue pooljobs; /* fixed jobs, like USERINSTALLED/MULTIVERSION */
  94. #ifdef LIBSOLV_INTERNAL
  95. /* flags to tell the library how the installed package manager works */
  96. int promoteepoch; /* true: missing epoch is replaced by epoch of dependency */
  97. int havedistepoch; /* true: thr release part in the evr may contain a distepoch suffix */
  98. int obsoleteusesprovides; /* true: obsoletes are matched against provides, not names */
  99. int implicitobsoleteusesprovides; /* true: implicit obsoletes due to same name are matched against provides, not names */
  100. int obsoleteusescolors; /* true: obsoletes check arch color */
  101. int implicitobsoleteusescolors; /* true: implicit obsoletes check arch color */
  102. int noinstalledobsoletes; /* true: ignore obsoletes of installed packages */
  103. int forbidselfconflicts; /* true: packages which conflict with itself are not installable */
  104. int noobsoletesmultiversion; /* true: obsoletes are ignored for multiversion installs */
  105. Id noarchid; /* ARCH_NOARCH, ARCH_ALL, ARCH_ANY, ... */
  106. /* hash for rel unification */
  107. Hashtable relhashtbl; /* hashtable: (name,evr,op)Hash -> Id */
  108. Hashval relhashmask;
  109. Id *languagecache;
  110. int languagecacheother;
  111. /* our tmp space string space */
  112. struct s_Pool_tmpspace tmpspace;
  113. char *errstr; /* last error string */
  114. int errstra; /* allocated space for errstr */
  115. char *rootdir;
  116. int (*custom_vendorcheck)(struct s_Pool *, Solvable *, Solvable *);
  117. int addfileprovidesfiltered; /* 1: only use filtered file list for addfileprovides */
  118. int addedfileprovides; /* true: application called addfileprovides */
  119. Queue lazywhatprovidesq; /* queue to store old whatprovides offsets */
  120. int nowhatprovidesaux; /* don't allocate and use the whatprovides aux helper */
  121. Offset *whatprovidesaux;
  122. Offset whatprovidesauxoff;
  123. Id *whatprovidesauxdata;
  124. Offset whatprovidesauxdataoff;
  125. int whatprovideswithdisabled;
  126. #endif
  127. };
  128. #define DISTTYPE_RPM 0
  129. #define DISTTYPE_DEB 1
  130. #define DISTTYPE_ARCH 2
  131. #define DISTTYPE_HAIKU 3
  132. #define DISTTYPE_CONDA 4
  133. #define SOLV_FATAL (1<<0)
  134. #define SOLV_ERROR (1<<1)
  135. #define SOLV_WARN (1<<2)
  136. #define SOLV_DEBUG_STATS (1<<3)
  137. #define SOLV_DEBUG_RULE_CREATION (1<<4)
  138. #define SOLV_DEBUG_PROPAGATE (1<<5)
  139. #define SOLV_DEBUG_ANALYZE (1<<6)
  140. #define SOLV_DEBUG_UNSOLVABLE (1<<7)
  141. #define SOLV_DEBUG_SOLUTIONS (1<<8)
  142. #define SOLV_DEBUG_POLICY (1<<9)
  143. #define SOLV_DEBUG_RESULT (1<<10)
  144. #define SOLV_DEBUG_JOB (1<<11)
  145. #define SOLV_DEBUG_SOLVER (1<<12)
  146. #define SOLV_DEBUG_TRANSACTION (1<<13)
  147. #define SOLV_DEBUG_WATCHES (1<<14)
  148. #define SOLV_DEBUG_TO_STDERR (1<<30)
  149. #define POOL_FLAG_PROMOTEEPOCH 1
  150. #define POOL_FLAG_FORBIDSELFCONFLICTS 2
  151. #define POOL_FLAG_OBSOLETEUSESPROVIDES 3
  152. #define POOL_FLAG_IMPLICITOBSOLETEUSESPROVIDES 4
  153. #define POOL_FLAG_OBSOLETEUSESCOLORS 5
  154. #define POOL_FLAG_NOINSTALLEDOBSOLETES 6
  155. #define POOL_FLAG_HAVEDISTEPOCH 7
  156. #define POOL_FLAG_NOOBSOLETESMULTIVERSION 8
  157. #define POOL_FLAG_ADDFILEPROVIDESFILTERED 9
  158. #define POOL_FLAG_IMPLICITOBSOLETEUSESCOLORS 10
  159. #define POOL_FLAG_NOWHATPROVIDESAUX 11
  160. #define POOL_FLAG_WHATPROVIDESWITHDISABLED 12
  161. /* ----------------------------------------------- */
  162. /* mark dependencies with relation by setting bit31 */
  163. #define MAKERELDEP(id) ((id) | 0x80000000)
  164. #define ISRELDEP(id) (((id) & 0x80000000) != 0)
  165. #define GETRELID(id) ((id) ^ 0x80000000) /* returns Id */
  166. #define GETRELDEP(pool, id) ((pool)->rels + ((id) ^ 0x80000000)) /* returns Reldep* */
  167. #define REL_GT 1
  168. #define REL_EQ 2
  169. #define REL_LT 4
  170. #define REL_AND 16
  171. #define REL_OR 17
  172. #define REL_WITH 18
  173. #define REL_NAMESPACE 19
  174. #define REL_ARCH 20
  175. #define REL_FILECONFLICT 21
  176. #define REL_COND 22 /* OR_NOT */
  177. #define REL_COMPAT 23
  178. #define REL_KIND 24 /* for filters only */
  179. #define REL_MULTIARCH 25 /* debian multiarch annotation */
  180. #define REL_ELSE 26 /* only as evr part of REL_COND/REL_UNLESS */
  181. #define REL_ERROR 27 /* parse errors and the like */
  182. #define REL_WITHOUT 28
  183. #define REL_UNLESS 29 /* AND_NOT */
  184. #define REL_CONDA 30
  185. #if !defined(__GNUC__) && !defined(__attribute__)
  186. # define __attribute__(x)
  187. #endif
  188. extern Pool *pool_create(void);
  189. extern void pool_free(Pool *pool);
  190. extern void pool_freeallrepos(Pool *pool, int reuseids);
  191. extern void pool_setdebuglevel(Pool *pool, int level);
  192. extern int pool_setdisttype(Pool *pool, int disttype);
  193. extern int pool_set_flag(Pool *pool, int flag, int value);
  194. extern int pool_get_flag(Pool *pool, int flag);
  195. extern void pool_debug(Pool *pool, int type, const char *format, ...) __attribute__((format(printf, 3, 4)));
  196. extern void pool_setdebugcallback(Pool *pool, void (*debugcallback)(struct s_Pool *, void *data, int type, const char *str), void *debugcallbackdata);
  197. extern void pool_setdebugmask(Pool *pool, int mask);
  198. extern void pool_setloadcallback(Pool *pool, int (*cb)(struct s_Pool *, struct s_Repodata *, void *), void *loadcbdata);
  199. extern void pool_setnamespacecallback(Pool *pool, Id (*cb)(struct s_Pool *, void *, Id, Id), void *nscbdata);
  200. extern void pool_flush_namespaceproviders(Pool *pool, Id ns, Id evr);
  201. extern void pool_set_custom_vendorcheck(Pool *pool, int (*vendorcheck)(struct s_Pool *, Solvable *, Solvable *));
  202. extern int (*pool_get_custom_vendorcheck(Pool *pool))(struct s_Pool *, Solvable *, Solvable *);
  203. extern char *pool_alloctmpspace(Pool *pool, int len);
  204. extern void pool_freetmpspace(Pool *pool, const char *space);
  205. extern char *pool_tmpjoin(Pool *pool, const char *str1, const char *str2, const char *str3);
  206. extern char *pool_tmpappend(Pool *pool, const char *str1, const char *str2, const char *str3);
  207. extern const char *pool_bin2hex(Pool *pool, const unsigned char *buf, int len);
  208. extern void pool_set_installed(Pool *pool, struct s_Repo *repo);
  209. extern int pool_error(Pool *pool, int ret, const char *format, ...) __attribute__((format(printf, 3, 4)));
  210. extern char *pool_errstr(Pool *pool);
  211. extern void pool_set_rootdir(Pool *pool, const char *rootdir);
  212. extern const char *pool_get_rootdir(Pool *pool);
  213. extern char *pool_prepend_rootdir(Pool *pool, const char *dir);
  214. extern const char *pool_prepend_rootdir_tmp(Pool *pool, const char *dir);
  215. /**
  216. * Solvable management
  217. */
  218. extern Id pool_add_solvable(Pool *pool);
  219. extern Id pool_add_solvable_block(Pool *pool, int count);
  220. extern void pool_free_solvable_block(Pool *pool, Id start, int count, int reuseids);
  221. static inline Solvable *pool_id2solvable(const Pool *pool, Id p)
  222. {
  223. return pool->solvables + p;
  224. }
  225. static inline Id pool_solvable2id(const Pool *pool, Solvable *s)
  226. {
  227. return s - pool->solvables;
  228. }
  229. extern const char *pool_solvable2str(Pool *pool, Solvable *s);
  230. static inline const char *pool_solvid2str(Pool *pool, Id p)
  231. {
  232. return pool_solvable2str(pool, pool->solvables + p);
  233. }
  234. void pool_set_languages(Pool *pool, const char **languages, int nlanguages);
  235. Id pool_id2langid(Pool *pool, Id id, const char *lang, int create);
  236. int pool_intersect_evrs(Pool *pool, int pflags, Id pevr, int flags, Id evr);
  237. int pool_match_dep(Pool *pool, Id d1, Id d2);
  238. /* semi private, used in pool_match_nevr */
  239. int pool_match_nevr_rel(Pool *pool, Solvable *s, Id d);
  240. static inline int pool_match_nevr(Pool *pool, Solvable *s, Id d)
  241. {
  242. if (!ISRELDEP(d))
  243. return d == s->name;
  244. else
  245. return pool_match_nevr_rel(pool, s, d);
  246. }
  247. /**
  248. * Prepares a pool for solving
  249. */
  250. extern void pool_createwhatprovides(Pool *pool);
  251. extern void pool_addfileprovides(Pool *pool);
  252. extern void pool_addfileprovides_queue(Pool *pool, Queue *idq, Queue *idqinst);
  253. extern void pool_freewhatprovides(Pool *pool);
  254. extern Id pool_queuetowhatprovides(Pool *pool, Queue *q);
  255. extern Id pool_ids2whatprovides(Pool *pool, Id *ids, int count);
  256. extern Id pool_searchlazywhatprovidesq(Pool *pool, Id d);
  257. extern Id pool_addrelproviders(Pool *pool, Id d);
  258. static inline Id pool_whatprovides(Pool *pool, Id d)
  259. {
  260. if (!ISRELDEP(d))
  261. {
  262. if (pool->whatprovides[d])
  263. return pool->whatprovides[d];
  264. }
  265. else
  266. {
  267. Id v = GETRELID(d);
  268. if (pool->whatprovides_rel[v])
  269. return pool->whatprovides_rel[v];
  270. }
  271. return pool_addrelproviders(pool, d);
  272. }
  273. static inline Id *pool_whatprovides_ptr(Pool *pool, Id d)
  274. {
  275. Id off = pool_whatprovides(pool, d);
  276. return pool->whatprovidesdata + off;
  277. }
  278. void pool_whatmatchesdep(Pool *pool, Id keyname, Id dep, Queue *q, int marker);
  279. void pool_whatcontainsdep(Pool *pool, Id keyname, Id dep, Queue *q, int marker);
  280. void pool_whatmatchessolvable(Pool *pool, Id keyname, Id solvid, Queue *q, int marker);
  281. void pool_set_whatprovides(Pool *pool, Id id, Id providers);
  282. /* search the pool. the following filters are available:
  283. * p - search just this solvable
  284. * key - search only this key
  285. * match - key must match this string
  286. */
  287. void pool_search(Pool *pool, Id p, Id key, const char *match, int flags, int (*callback)(void *cbdata, Solvable *s, struct s_Repodata *data, struct s_Repokey *key, struct s_KeyValue *kv), void *cbdata);
  288. void pool_clear_pos(Pool *pool);
  289. /* lookup functions */
  290. const char *pool_lookup_str(Pool *pool, Id entry, Id keyname);
  291. Id pool_lookup_id(Pool *pool, Id entry, Id keyname);
  292. unsigned long long pool_lookup_num(Pool *pool, Id entry, Id keyname, unsigned long long notfound);
  293. int pool_lookup_void(Pool *pool, Id entry, Id keyname);
  294. const unsigned char *pool_lookup_bin_checksum(Pool *pool, Id entry, Id keyname, Id *typep);
  295. int pool_lookup_idarray(Pool *pool, Id entry, Id keyname, Queue *q);
  296. const char *pool_lookup_checksum(Pool *pool, Id entry, Id keyname, Id *typep);
  297. const char *pool_lookup_deltalocation(Pool *pool, Id entry, unsigned int *medianrp);
  298. #define DUCHANGES_ONLYADD 1
  299. typedef struct s_DUChanges {
  300. const char *path;
  301. long long kbytes;
  302. long long files;
  303. int flags;
  304. } DUChanges;
  305. void pool_create_state_maps(Pool *pool, Queue *installed, Map *installedmap, Map *conflictsmap);
  306. void pool_calc_duchanges(Pool *pool, Map *installedmap, DUChanges *mps, int nmps);
  307. long long pool_calc_installsizechange(Pool *pool, Map *installedmap);
  308. void pool_add_fileconflicts_deps(Pool *pool, Queue *conflicts);
  309. /* loop over all providers of d */
  310. #define FOR_PROVIDES(v, vp, d) \
  311. for (vp = pool_whatprovides(pool, d) ; (v = pool->whatprovidesdata[vp++]) != 0; )
  312. /* loop over all repositories */
  313. #define FOR_REPOS(repoid, r) \
  314. for (repoid = 1; repoid < pool->nrepos; repoid++) \
  315. if ((r = pool->repos[repoid]) == 0) \
  316. continue; \
  317. else
  318. #define FOR_POOL_SOLVABLES(p) \
  319. for (p = 2; p < pool->nsolvables; p++) \
  320. if (pool->solvables[p].repo == 0) \
  321. continue; \
  322. else
  323. #define POOL_DEBUG(type, ...) do {if ((pool->debugmask & (type)) != 0) pool_debug(pool, (type), __VA_ARGS__);} while (0)
  324. #define IF_POOLDEBUG(type) if ((pool->debugmask & (type)) != 0)
  325. /* weird suse stuff */
  326. void pool_trivial_installable_multiversionmap(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res, Map *multiversionmap);
  327. void pool_trivial_installable(Pool *pool, Map *installedmap, Queue *pkgs, Queue *res);
  328. #ifdef __cplusplus
  329. }
  330. #endif
  331. #endif /* LIBSOLV_POOL_H */