initial autorollback feature.
[platform/upstream/rpm.git] / lib / rpmte.h
1 #ifndef H_RPMTE
2 #define H_RPMTE
3
4 /** \ingroup rpmts rpmte
5  * \file lib/rpmte.h
6  * Structures used for an "rpmte" transaction element.
7  */
8
9 /**
10  */
11 /*@-exportlocal@*/
12 /*@unchecked@*/
13 extern int _rpmte_debug;
14 /*@=exportlocal@*/
15
16 /**
17  * Transaction element ordering chain linkage.
18  */
19 typedef /*@abstract@*/ struct tsortInfo_s *             tsortInfo;
20
21 /**
22  * Transaction element iterator.
23  */
24 typedef /*@abstract@*/ struct rpmtsi_s *                rpmtsi;
25
26 /** \ingroup rpmte
27  * Transaction element type.
28  */
29 typedef enum rpmElementType_e {
30     TR_ADDED            = (1 << 0),     /*!< Package will be installed. */
31     TR_REMOVED          = (1 << 1)      /*!< Package will be removed. */
32 } rpmElementType;
33
34 #if     defined(_RPMTE_INTERNAL)
35 /** \ingroup rpmte
36  * Dependncy ordering information.
37  */
38 /*@-fielduse@*/ /* LCL: confused by union? */
39 struct tsortInfo_s {
40     union {
41         int     count;
42         /*@exposed@*/ /*@dependent@*/ /*@null@*/
43         rpmte   suc;
44     } tsi_u;
45 #define tsi_count       tsi_u.count
46 #define tsi_suc         tsi_u.suc
47 /*@owned@*/ /*@null@*/
48     struct tsortInfo_s * tsi_next;
49 /*@exposed@*/ /*@dependent@*/ /*@null@*/
50     rpmte tsi_chain;
51     int         tsi_reqx;
52     int         tsi_qcnt;
53 };
54 /*@=fielduse@*/
55
56 /** \ingroup rpmte
57  * A single package instance to be installed/removed atomically.
58  */
59 struct rpmte_s {
60     rpmElementType type;        /*!< Package disposition (installed/removed). */
61
62 /*@refcounted@*/ /*@relnull@*/
63     Header h;                   /*!< Package header. */
64 /*@only@*/
65     const char * NEVR;          /*!< Package name-version-release. */
66 /*@only@*/
67     const char * NEVRA;         /*!< Package name-version-release.arch. */
68 /*@owned@*/
69     const char * name;          /*!< Name: */
70 /*@only@*/ /*@null@*/
71     char * epoch;
72 /*@dependent@*/ /*@null@*/
73     char * version;             /*!< Version: */
74 /*@dependent@*/ /*@null@*/
75     char * release;             /*!< Release: */
76 /*@only@*/ /*@null@*/
77     const char * arch;          /*!< Architecture hint. */
78 /*@only@*/ /*@null@*/
79     const char * os;            /*!< Operating system hint. */
80     int archScore;              /*!< (TR_ADDED) Arch score. */
81     int osScore;                /*!< (TR_ADDED) Os score. */
82
83     rpmte parent;               /*!< Parent transaction element. */
84     int degree;                 /*!< No. of immediate children. */
85     int depth;                  /*!< Max. depth in dependency tree. */
86     int npreds;                 /*!< No. of predecessors. */
87     int tree;                   /*!< Tree index. */
88     unsigned int db_instance;   /*!< Database Instance after add */
89 /*@owned@*/
90     tsortInfo tsi;              /*!< Dependency ordering chains. */
91
92 /*@refcounted@*/ /*@null@*/
93     rpmds this;                 /*!< This package's provided NEVR. */
94 /*@refcounted@*/ /*@null@*/
95     rpmds provides;             /*!< Provides: dependencies. */
96 /*@refcounted@*/ /*@null@*/
97     rpmds requires;             /*!< Requires: dependencies. */
98 /*@refcounted@*/ /*@null@*/
99     rpmds conflicts;            /*!< Conflicts: dependencies. */
100 /*@refcounted@*/ /*@null@*/
101     rpmds obsoletes;            /*!< Obsoletes: dependencies. */
102 /*@refcounted@*/ /*@null@*/
103     rpmfi fi;                   /*!< File information. */
104
105     uint_32 color;              /*!< Color bit(s) from package dependencies. */
106     uint_32 pkgFileSize;        /*!< No. of bytes in package file (approx). */
107
108 /*@exposed@*/ /*@dependent@*/ /*@null@*/
109     fnpyKey key;                /*!< (TR_ADDED) Retrieval key. */
110 /*@owned@*/ /*@null@*/
111     rpmRelocation * relocs;     /*!< (TR_ADDED) Payload file relocations. */
112     int nrelocs;                /*!< (TR_ADDED) No. of relocations. */
113     int autorelocatex;          /*!< (TR_ADDED) Auto relocation entry index. */
114 /*@refcounted@*/ /*@null@*/     
115     FD_t fd;                    /*!< (TR_ADDED) Payload file descriptor. */
116
117 /*@-fielduse@*/ /* LCL: confused by union? */
118     union { 
119 /*@exposed@*/ /*@dependent@*/ /*@null@*/
120         alKey addedKey;
121         struct {
122 /*@exposed@*/ /*@dependent@*/ /*@null@*/
123             alKey dependsOnKey;
124             int dboffset;
125         } removed;
126     } u;
127 /*@=fielduse@*/
128
129 };
130
131 /**
132  * Iterator across transaction elements, forward on install, backward on erase.
133  */
134 struct rpmtsi_s {
135 /*@refcounted@*/
136     rpmts ts;           /*!< transaction set. */
137     int reverse;        /*!< reversed traversal? */
138     int ocsave;         /*!< last returned iterator index. */
139     int oc;             /*!< iterator index. */
140 };
141
142 #endif  /* _RPMTE_INTERNAL */
143
144 #ifdef __cplusplus
145 extern "C" {
146 #endif
147
148 /**
149  * Destroy a transaction element.
150  * @param te            transaction element
151  * @return              NULL always
152  */
153 /*@null@*/
154 rpmte rpmteFree(/*@only@*/ /*@null@*/ rpmte te)
155         /*@globals fileSystem @*/
156         /*@modifies te, fileSystem @*/;
157
158 /**
159  * Create a transaction element.
160  * @param ts            transaction set
161  * @param h             header
162  * @param type          TR_ADDED/TR_REMOVED
163  * @param key           (TR_ADDED) package retrieval key (e.g. file name)
164  * @param relocs        (TR_ADDED) package file relocations
165  * @param dboffset      (TR_REMOVED) rpmdb instance
166  * @param pkgKey        associated added package (if any)
167  * @return              new transaction element
168  */
169 /*@only@*/ /*@null@*/
170 rpmte rpmteNew(const rpmts ts, Header h, rpmElementType type,
171                 /*@exposed@*/ /*@dependent@*/ /*@null@*/ fnpyKey key,
172                 /*@null@*/ rpmRelocation * relocs,
173                 int dboffset,
174                 /*@exposed@*/ /*@dependent@*/ /*@null@*/ alKey pkgKey)
175         /*@globals rpmGlobalMacroContext, h_errno, fileSystem @*/
176         /*@modifies ts, h, rpmGlobalMacroContext, fileSystem @*/;
177
178 /**
179  * Retrieve type of transaction element.
180  * @param te            transaction element
181  * @return              type
182  */
183 rpmElementType rpmteType(rpmte te)
184         /*@*/;
185
186 /**
187  * Retrieve name string of transaction element.
188  * @param te            transaction element
189  * @return              name string
190  */
191 /*@observer@*/
192 extern const char * rpmteN(rpmte te)
193         /*@*/;
194
195 /**
196  * Retrieve epoch string of transaction element.
197  * @param te            transaction element
198  * @return              epoch string
199  */
200 /*@observer@*/ /*@null@*/
201 extern const char * rpmteE(rpmte te)
202         /*@*/;
203
204 /**
205  * Retrieve version string of transaction element.
206  * @param te            transaction element
207  * @return              version string
208  */
209 /*@observer@*/ /*@null@*/
210 extern const char * rpmteV(rpmte te)
211         /*@*/;
212
213 /**
214  * Retrieve release string of transaction element.
215  * @param te            transaction element
216  * @return              release string
217  */
218 /*@observer@*/ /*@null@*/
219 extern const char * rpmteR(rpmte te)
220         /*@*/;
221
222 /**
223  * Retrieve arch string of transaction element.
224  * @param te            transaction element
225  * @return              arch string
226  */
227 /*@observer@*/ /*@null@*/
228 extern const char * rpmteA(rpmte te)
229         /*@*/;
230
231 /**
232  * Retrieve os string of transaction element.
233  * @param te            transaction element
234  * @return              os string
235  */
236 /*@observer@*/ /*@null@*/
237 extern const char * rpmteO(rpmte te)
238         /*@*/;
239
240 /**
241  * Retrieve color bits of transaction element.
242  * @param te            transaction element
243  * @return              color bits
244  */
245 uint_32 rpmteColor(rpmte te)
246         /*@*/;
247
248 /**
249  * Set color bits of transaction element.
250  * @param te            transaction element
251  * @param color         new color bits
252  * @return              previous color bits
253  */
254 uint_32 rpmteSetColor(rpmte te, uint_32 color)
255         /*@modifies te @*/;
256
257 /**
258  * Retrieve last instance installed to the database.
259  * @param te            transaction element
260  * @return              last install instance.
261  */
262 unsigned int rpmteDBInstance(rpmte te);
263
264 /**
265  * Set last instance installed to the database.
266  * @param te            transaction element
267  * @param instance      Database instance of last install element.
268  * @return              last install instance.
269  */
270 void rpmteSetDBInstance(rpmte te, unsigned int instance);
271
272 /**
273  * Retrieve size in bytes of package file.
274  * @todo Signature header is estimated at 256b.
275  * @param te            transaction element
276  * @return              size in bytes of package file.
277  */
278 uint_32 rpmtePkgFileSize(rpmte te)
279         /*@*/;
280
281 /**
282  * Retrieve tsort tree depth of transaction element.
283  * @param te            transaction element
284  * @return              depth
285  */
286 int rpmteDepth(rpmte te)
287         /*@*/;
288
289 /**
290  * Set tsort tree depth of transaction element.
291  * @param te            transaction element
292  * @param ndepth        new depth
293  * @return              previous depth
294  */
295 int rpmteSetDepth(rpmte te, int ndepth)
296         /*@modifies te @*/;
297
298 /**
299  * Retrieve tsort no. of predecessors of transaction element.
300  * @param te            transaction element
301  * @return              no. of predecessors
302  */
303 int rpmteNpreds(rpmte te)
304         /*@*/;
305
306 /**
307  * Set tsort no. of predecessors of transaction element.
308  * @param te            transaction element
309  * @param npreds        new no. of predecessors
310  * @return              previous no. of predecessors
311  */
312 int rpmteSetNpreds(rpmte te, int npreds)
313         /*@modifies te @*/;
314
315 /**
316  * Retrieve tree index of transaction element.
317  * @param te            transaction element
318  * @return              tree index
319  */
320 int rpmteTree(rpmte te)
321         /*@*/;
322
323 /**
324  * Set tree index of transaction element.
325  * @param te            transaction element
326  * @param ntree         new tree index
327  * @return              previous tree index
328  */
329 int rpmteSetTree(rpmte te, int ntree)
330         /*@modifies te @*/;
331
332 /**
333  * Retrieve parent transaction element.
334  * @param te            transaction element
335  * @return              parent transaction element
336  */
337 /*@observer@*/ /*@unused@*/
338 rpmte rpmteParent(rpmte te)
339         /*@*/;
340
341 /**
342  * Set parent transaction element.
343  * @param te            transaction element
344  * @param pte           new parent transaction element
345  * @return              previous parent transaction element
346  */
347 /*@null@*/
348 rpmte rpmteSetParent(rpmte te, rpmte pte)
349         /*@modifies te @*/;
350
351 /**
352  * Retrieve number of children of transaction element.
353  * @param te            transaction element
354  * @return              tree index
355  */
356 int rpmteDegree(rpmte te)
357         /*@*/;
358
359 /**
360  * Set number of children of transaction element.
361  * @param te            transaction element
362  * @param ndegree       new number of children
363  * @return              previous number of children
364  */
365 int rpmteSetDegree(rpmte te, int ndegree)
366         /*@modifies te @*/;
367
368 /**
369  * Retrieve tsort info for transaction element.
370  * @param te            transaction element
371  * @return              tsort info
372  */
373 tsortInfo rpmteTSI(rpmte te)
374         /*@*/;
375
376 /**
377  * Destroy tsort info of transaction element.
378  * @param te            transaction element
379  */
380 void rpmteFreeTSI(rpmte te)
381         /*@modifies te @*/;
382
383 /**
384  * Initialize tsort info of transaction element.
385  * @param te            transaction element
386  */
387 void rpmteNewTSI(rpmte te)
388         /*@modifies te @*/;
389
390 /**
391  * Destroy dependency set info of transaction element.
392  * @param te            transaction element
393  */
394 /*@unused@*/
395 void rpmteCleanDS(rpmte te)
396         /*@modifies te @*/;
397
398 /**
399  * Retrieve pkgKey of TR_ADDED transaction element.
400  * @param te            transaction element
401  * @return              pkgKey
402  */
403 /*@exposed@*/ /*@dependent@*/ /*@null@*/
404 alKey rpmteAddedKey(rpmte te)
405         /*@*/;
406
407 /**
408  * Set pkgKey of TR_ADDED transaction element.
409  * @param te            transaction element
410  * @param npkgKey       new pkgKey
411  * @return              previous pkgKey
412  */
413 /*@exposed@*/ /*@dependent@*/ /*@null@*/
414 alKey rpmteSetAddedKey(rpmte te,
415                 /*@exposed@*/ /*@dependent@*/ /*@null@*/ alKey npkgKey)
416         /*@modifies te @*/;
417
418 /**
419  * Retrieve dependent pkgKey of TR_REMOVED transaction element.
420  * @param te            transaction element
421  * @return              dependent pkgKey
422  */
423 /*@exposed@*/ /*@dependent@*/ /*@null@*/
424 alKey rpmteDependsOnKey(rpmte te)
425         /*@*/;
426
427 /**
428  * Retrieve rpmdb instance of TR_REMOVED transaction element.
429  * @param te            transaction element
430  * @return              rpmdb instance
431  */
432 int rpmteDBOffset(rpmte te)
433         /*@*/;
434
435 /**
436  * Retrieve name-version-release string from transaction element.
437  * @param te            transaction element
438  * @return              name-version-release string
439  */
440 /*@observer@*/
441 extern const char * rpmteNEVR(rpmte te)
442         /*@*/;
443
444 /**
445  * Retrieve name-version-release.arch string from transaction element.
446  * @param te            transaction element
447  * @return              name-version-release.arch string
448  */
449 /*@-exportlocal@*/
450 /*@observer@*/
451 extern const char * rpmteNEVRA(rpmte te)
452         /*@*/;
453 /*@=exportlocal@*/
454
455 /**
456  * Retrieve file handle from transaction element.
457  * @param te            transaction element
458  * @return              file handle
459  */
460 FD_t rpmteFd(rpmte te)
461         /*@*/;
462
463 /**
464  * Retrieve key from transaction element.
465  * @param te            transaction element
466  * @return              key
467  */
468 /*@exposed@*/
469 fnpyKey rpmteKey(rpmte te)
470         /*@*/;
471
472 /**
473  * Retrieve dependency tag set from transaction element.
474  * @param te            transaction element
475  * @param tag           dependency tag
476  * @return              dependency tag set
477  */
478 rpmds rpmteDS(rpmte te, rpmTag tag)
479         /*@*/;
480
481 /**
482  * Retrieve file info tag set from transaction element.
483  * @param te            transaction element
484  * @param tag           file info tag (RPMTAG_BASENAMES)
485  * @return              file info tag set
486  */
487 rpmfi rpmteFI(rpmte te, rpmTag tag)
488         /*@*/;
489
490 /**
491  * Calculate transaction element dependency colors/refs from file info.
492  * @param te            transaction element
493  * @param tag           dependency tag (RPMTAG_PROVIDENAME, RPMTAG_REQUIRENAME)
494  */
495 /*@-exportlocal@*/
496 void rpmteColorDS(rpmte te, rpmTag tag)
497         /*@modifies te @*/;
498 /*@=exportlocal@*/
499
500 /**
501  * Return transaction element index.
502  * @param tsi           transaction element iterator
503  * @return              transaction element index
504  */
505 int rpmtsiOc(rpmtsi tsi)
506         /*@*/;
507
508 /**
509  * Destroy transaction element iterator.
510  * @param tsi           transaction element iterator
511  * @return              NULL always
512  */
513 /*@unused@*/ /*@null@*/
514 rpmtsi rpmtsiFree(/*@only@*//*@null@*/ rpmtsi tsi)
515         /*@globals fileSystem @*/
516         /*@modifies fileSystem @*/;
517
518 /**
519  * Destroy transaction element iterator.
520  * @param tsi           transaction element iterator
521  * @param fn
522  * @param ln
523  * @return              NULL always
524  */
525 /*@null@*/
526 rpmtsi XrpmtsiFree(/*@only@*//*@null@*/ rpmtsi tsi,
527                 const char * fn, unsigned int ln)
528         /*@globals fileSystem @*/
529         /*@modifies fileSystem @*/;
530 #define rpmtsiFree(_tsi)        XrpmtsiFree(_tsi, __FILE__, __LINE__)
531
532 /**
533  * Create transaction element iterator.
534  * @param ts            transaction set
535  * @return              transaction element iterator
536  */
537 /*@unused@*/ /*@only@*/
538 rpmtsi rpmtsiInit(rpmts ts)
539         /*@modifies ts @*/;
540
541 /**
542  * Create transaction element iterator.
543  * @param ts            transaction set
544  * @param fn
545  * @param ln
546  * @return              transaction element iterator
547  */
548 /*@unused@*/ /*@only@*/
549 rpmtsi XrpmtsiInit(rpmts ts,
550                 const char * fn, unsigned int ln)
551         /*@modifies ts @*/;
552 #define rpmtsiInit(_ts)         XrpmtsiInit(_ts, __FILE__, __LINE__)
553
554 /**
555  * Return next transaction element of type.
556  * @param tsi           transaction element iterator
557  * @param type          transaction element type selector (0 for any)
558  * @return              next transaction element of type, NULL on termination
559  */
560 /*@dependent@*/ /*@null@*/
561 rpmte rpmtsiNext(rpmtsi tsi, rpmElementType type)
562         /*@modifies tsi @*/;
563
564 #ifdef __cplusplus
565 }
566 #endif
567
568 #endif  /* H_RPMTE */