Add scriptlet-specific disablers for %pretrans and %posttrans
[platform/upstream/rpm.git] / lib / rpmts.h
1 #ifndef H_RPMTS
2 #define H_RPMTS
3
4 /** \ingroup rpmts
5  * \file lib/rpmts.h
6  * Structures and prototypes used for an "rpmts" transaction set.
7  */
8
9 #include <sys/types.h>
10
11 #include <rpm/rpmtypes.h>
12 #include <rpm/rpmte.h>
13 #include <rpm/rpmps.h>
14 #include <rpm/rpmsw.h>
15 #include <rpm/rpmpgp.h>
16 #include <rpm/rpmfi.h>
17 #include <rpm/rpmcallback.h>
18
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22
23 extern int _rpmts_stats;
24
25 /** \ingroup rpmts
26  * Bit(s) to control rpmtsRun() operation.
27  */
28 enum rpmtransFlags_e {
29     RPMTRANS_FLAG_NONE          = 0,
30     RPMTRANS_FLAG_TEST          = (1 <<  0),    /*!< from --test */
31     RPMTRANS_FLAG_BUILD_PROBS   = (1 <<  1),    /*!< don't process payload */
32     RPMTRANS_FLAG_NOSCRIPTS     = (1 <<  2),    /*!< from --noscripts */
33     RPMTRANS_FLAG_JUSTDB        = (1 <<  3),    /*!< from --justdb */
34     RPMTRANS_FLAG_NOTRIGGERS    = (1 <<  4),    /*!< from --notriggers */
35     RPMTRANS_FLAG_NODOCS        = (1 <<  5),    /*!< from --excludedocs */
36     RPMTRANS_FLAG_ALLFILES      = (1 <<  6),    /*!< from --allfiles */
37     /* bit 7 unused */
38     RPMTRANS_FLAG_NOCONTEXTS    = (1 <<  8),    /*!< from --nocontexts */
39     /* bits 9-15 unused */
40     RPMTRANS_FLAG_NOTRIGGERPREIN= (1 << 16),    /*!< from --notriggerprein */
41     RPMTRANS_FLAG_NOPRE         = (1 << 17),    /*!< from --nopre */
42     RPMTRANS_FLAG_NOPOST        = (1 << 18),    /*!< from --nopost */
43     RPMTRANS_FLAG_NOTRIGGERIN   = (1 << 19),    /*!< from --notriggerin */
44     RPMTRANS_FLAG_NOTRIGGERUN   = (1 << 20),    /*!< from --notriggerun */
45     RPMTRANS_FLAG_NOPREUN       = (1 << 21),    /*!< from --nopreun */
46     RPMTRANS_FLAG_NOPOSTUN      = (1 << 22),    /*!< from --nopostun */
47     RPMTRANS_FLAG_NOTRIGGERPOSTUN = (1 << 23),  /*!< from --notriggerpostun */
48     RPMTRANS_FLAG_NOPRETRANS    = (1 << 24),    /*!< from --nopretrans */
49     RPMTRANS_FLAG_NOPOSTTRANS   = (1 << 25),    /*!< from --noposttrans */
50     RPMTRANS_FLAG_NOCOLLECTIONS = (1 << 26),    /*!< from --nocollections */
51     RPMTRANS_FLAG_NOMD5         = (1 << 27),    /*!< from --nomd5 */
52     RPMTRANS_FLAG_NOFILEDIGEST  = (1 << 27),    /*!< from --nofiledigest (alias to --nomd5) */
53     /* bits 28-29 unused */
54     RPMTRANS_FLAG_NOCONFIGS     = (1 << 30),    /*!< from --noconfigs */
55     RPMTRANS_FLAG_DEPLOOPS      = (1 << 31)     /*!< from --deploops */
56 };
57
58 typedef rpmFlags rpmtransFlags;
59
60 #define _noTransScripts         \
61   ( RPMTRANS_FLAG_NOPRE |       \
62     RPMTRANS_FLAG_NOPOST |      \
63     RPMTRANS_FLAG_NOPREUN |     \
64     RPMTRANS_FLAG_NOPOSTUN |    \
65     RPMTRANS_FLAG_NOPRETRANS |  \
66     RPMTRANS_FLAG_NOPOSTTRANS \
67   )
68
69 #define _noTransTriggers        \
70   ( RPMTRANS_FLAG_NOTRIGGERPREIN | \
71     RPMTRANS_FLAG_NOTRIGGERIN | \
72     RPMTRANS_FLAG_NOTRIGGERUN | \
73     RPMTRANS_FLAG_NOTRIGGERPOSTUN \
74   )
75
76 /* Avoid unnecessary breakage for stuff referring to these unused flags */
77 #define RPMTRANS_FLAG_NOPAYLOAD 0
78 #define RPMTRANS_FLAG_APPLYONLY 0
79 #define RPMTRANS_FLAG_KEEPOBSOLETE 0
80 #define RPMTRANS_FLAG_DIRSTASH 0
81 #define RPMTRANS_FLAG_REPACKAGE 0
82 #define RPMTRANS_FLAG_PKGCOMMIT 0
83 #define RPMTRANS_FLAG_PKGUNDO 0
84 #define RPMTRANS_FLAG_COMMIT 0
85 #define RPMTRANS_FLAG_UNDO 0
86 #define RPMTRANS_FLAG_REVERSE 0
87 #define RPMTRANS_FLAG_NOSUGGEST 0
88 #define RPMTRANS_FLAG_ADDINDEPS 0
89
90 /** \ingroup rpmts
91  * Bit(s) to control digest and signature verification.
92  */
93 enum rpmVSFlags_e {
94     RPMVSF_DEFAULT      = 0,
95     RPMVSF_NOHDRCHK     = (1 <<  0),
96     RPMVSF_NEEDPAYLOAD  = (1 <<  1),
97     /* bit(s) 2-7 unused */
98     RPMVSF_NOSHA1HEADER = (1 <<  8),
99     RPMVSF_NOMD5HEADER  = (1 <<  9),    /* unimplemented */
100     RPMVSF_NODSAHEADER  = (1 << 10),
101     RPMVSF_NORSAHEADER  = (1 << 11),    /* unimplemented */
102     /* bit(s) 12-15 unused */
103     RPMVSF_NOSHA1       = (1 << 16),    /* unimplemented */
104     RPMVSF_NOMD5        = (1 << 17),
105     RPMVSF_NODSA        = (1 << 18),
106     RPMVSF_NORSA        = (1 << 19)
107     /* bit(s) 16-31 unused */
108 };
109
110 typedef rpmFlags rpmVSFlags;
111
112 #define _RPMVSF_NODIGESTS       \
113   ( RPMVSF_NOSHA1HEADER |       \
114     RPMVSF_NOMD5HEADER |        \
115     RPMVSF_NOSHA1 |             \
116     RPMVSF_NOMD5 )
117
118 #define _RPMVSF_NOSIGNATURES    \
119   ( RPMVSF_NODSAHEADER |        \
120     RPMVSF_NORSAHEADER |        \
121     RPMVSF_NODSA |              \
122     RPMVSF_NORSA )
123
124 #define _RPMVSF_NOHEADER        \
125   ( RPMVSF_NOSHA1HEADER |       \
126     RPMVSF_NOMD5HEADER |        \
127     RPMVSF_NODSAHEADER |        \
128     RPMVSF_NORSAHEADER )
129
130 #define _RPMVSF_NOPAYLOAD       \
131   ( RPMVSF_NOSHA1 |             \
132     RPMVSF_NOMD5 |              \
133     RPMVSF_NODSA |              \
134     RPMVSF_NORSA )
135
136 /** \ingroup rpmts
137  * Indices for timestamps.
138  */
139 typedef enum rpmtsOpX_e {
140     RPMTS_OP_TOTAL              =  0,
141     RPMTS_OP_CHECK              =  1,
142     RPMTS_OP_ORDER              =  2,
143     RPMTS_OP_FINGERPRINT        =  3,
144     RPMTS_OP_INSTALL            =  5,
145     RPMTS_OP_ERASE              =  6,
146     RPMTS_OP_SCRIPTLETS         =  7,
147     RPMTS_OP_COMPRESS           =  8,
148     RPMTS_OP_UNCOMPRESS         =  9,
149     RPMTS_OP_DIGEST             = 10,
150     RPMTS_OP_SIGNATURE          = 11,
151     RPMTS_OP_DBADD              = 12,
152     RPMTS_OP_DBREMOVE           = 13,
153     RPMTS_OP_DBGET              = 14,
154     RPMTS_OP_DBPUT              = 15,
155     RPMTS_OP_DBDEL              = 16,
156     RPMTS_OP_MAX                = 17
157 } rpmtsOpX;
158
159 /** \ingroup rpmts
160  * Perform dependency resolution on the transaction set.
161  *
162  * Any problems found by rpmtsCheck() can be examined by retrieving the 
163  * problem set with rpmtsProblems(), success here only means that
164  * the resolution was successfully attempted for all packages in the set.
165  *
166  * @param ts            transaction set
167  * @return              0 on success
168  */
169 int rpmtsCheck(rpmts ts);
170
171 /** \ingroup rpmts
172  * Determine package order in a transaction set according to dependencies.
173  *
174  * Order packages, returning error if circular dependencies cannot be
175  * eliminated by removing Requires's from the loop(s). Only dependencies from
176  * added or removed packages are used to determine ordering using a
177  * topological sort (Knuth vol. 1, p. 262). Use rpmtsCheck() to verify
178  * that all dependencies can be resolved.
179  *
180  * The final order ends up as installed packages followed by removed packages,
181  * with packages removed for upgrades immediately following the new package
182  * to be installed.
183  *
184  * @param ts            transaction set
185  * @return              no. of (added) packages that could not be ordered
186  */
187 int rpmtsOrder(rpmts ts);
188
189 /** \ingroup rpmts
190  * Process all package elements in a transaction set.  Before calling
191  * rpmtsRun be sure to have:
192  *
193  *    - setup the rpm root dir via rpmtsSetRoot().
194  *    - setup the rpm notify callback via rpmtsSetNotifyCallback().
195  *    - setup the rpm transaction flags via rpmtsSetFlags().
196  * 
197  * Additionally, though not required you may want to:
198  *
199  *    - setup the rpm verify signature flags via rpmtsSetVSFlags().
200  *       
201  * @param ts            transaction set
202  * @param okProbs       unused
203  * @param ignoreSet     bits to filter problem types
204  * @return              0 on success, -1 on error, >0 with newProbs set
205  */
206 int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet);
207
208 /** \ingroup rpmts
209  * Reference a transaction set instance.
210  * @param ts            transaction set
211  * @return              new transaction set reference
212  */
213 rpmts rpmtsLink (rpmts ts);
214
215 /** \ingroup rpmts
216  * Close the database used by the transaction.
217  * @param ts            transaction set
218  * @return              0 on success
219  */
220 int rpmtsCloseDB(rpmts ts);
221
222 /** \ingroup rpmts
223  * Open the database used by the transaction.
224  * @param ts            transaction set
225  * @param dbmode        O_RDONLY or O_RDWR
226  * @return              0 on success
227  */
228 int rpmtsOpenDB(rpmts ts, int dbmode);
229
230 /** \ingroup rpmts
231  * Initialize the database used by the transaction.
232  * @deprecated An explicit rpmdbInit() is almost never needed.
233  * @param ts            transaction set
234  * @param dbmode        O_RDONLY or O_RDWR
235  * @return              0 on success
236  */
237 int rpmtsInitDB(rpmts ts, int dbmode);
238
239 /** \ingroup rpmts
240  * Return the transaction database mode
241  * @param ts            transaction set
242  * @return              O_RDONLY, O_RDWR or -1 (lazy opens disabled)
243  */
244 int rpmtsGetDBMode(rpmts ts);
245
246 /** \ingroup rpmts
247  * Set the transaction database mode. Only permitted when when backing
248  * database hasn't been opened yet (ie rpmtsGetRdb(ts) == NULL)
249  * @param ts            transaction set
250  * @param dbmode        O_RDONLY, O_RDWR or -1 (disable lazy opens)
251  * @return              0 on success, 1 on error 
252  */
253 int rpmtsSetDBMode(rpmts ts, int dbmode);
254
255 /** \ingroup rpmts
256  * Rebuild the database used by the transaction.
257  * @param ts            transaction set
258  * @return              0 on success
259  */
260 int rpmtsRebuildDB(rpmts ts);
261
262 /** \ingroup rpmts
263  * Verify the database used by the transaction.
264  * @param ts            transaction set
265  * @return              0 on success
266  */
267 int rpmtsVerifyDB(rpmts ts);
268
269 /** \ingroup rpmts
270  * Return transaction database iterator.
271  * @param ts            transaction set
272  * @param rpmtag        database index tag
273  * @param keyp          key data (NULL for sequential access)
274  * @param keylen        key data length (0 will use strlen(keyp))
275  * @return              NULL on failure
276  */
277 rpmdbMatchIterator rpmtsInitIterator(const rpmts ts, rpmDbiTagVal rpmtag,
278                         const void * keyp, size_t keylen);
279
280 /** \ingroup rpmts
281  * Import public key packet(s).
282  * @todo Implicit --update policy for gpg-pubkey headers.
283  * @param ts            transaction set
284  * @param pkt           pgp pubkey packet(s)
285  * @param pktlen        pgp pubkey length
286  * @return              RPMRC_OK/RPMRC_FAIL
287  */
288 rpmRC rpmtsImportPubkey(rpmts ts, const unsigned char * pkt, size_t pktlen);
289
290 /** \ingroup rpmts
291  * Retrieve handle for keyring used for this transaction set
292  * @param ts            transaction set
293  * @param autoload      load default keyring if keyring is not set
294  * @return              keyring handle (or NULL)
295  */
296 rpmKeyring rpmtsGetKeyring(rpmts ts, int autoload);
297
298 /** \ingroup rpmts
299  * Set keyring to use for this transaction set.
300  * Keyring can be only changed while the underlying rpm database is not
301  * yet open.
302  * @param ts            transaction set
303  * @param keyring       keyring handle (NULL to free current keyring)
304  * @return              0 on success, -1 on error
305  */
306 int rpmtsSetKeyring(rpmts ts, rpmKeyring keyring);
307
308 /** \ingroup rpmts
309  * Set dependency solver callback.
310  * @param ts            transaction set
311  * @param (*solve)      dependency solver callback
312  * @param solveData     dependency solver callback data (opaque)
313  * @return              0 on success
314  */
315 int rpmtsSetSolveCallback(rpmts ts,
316                 int (*solve) (rpmts ts, rpmds ds, const void * data),
317                 const void * solveData);
318
319 /** \ingroup rpmts
320  * Return current transaction set problems.
321  * @param ts            transaction set
322  * @return              current problem set (or NULL if no problems)
323  */
324 rpmps rpmtsProblems(rpmts ts);
325
326 /** \ingroup rpmts
327  * Clean current transaction problem set.
328  * @param ts            transaction set
329  */
330 void rpmtsCleanProblems(rpmts ts);
331
332 /** \ingroup rpmts
333  * Free memory needed only for dependency checks and ordering.
334  * @param ts            transaction set
335  */
336 void rpmtsClean(rpmts ts);
337
338 /** \ingroup rpmts
339  * Re-create an empty transaction set.
340  * @param ts            transaction set
341  */
342 void rpmtsEmpty(rpmts ts);
343
344 /** \ingroup rpmts
345  * Destroy transaction set, closing the database as well.
346  * @param ts            transaction set
347  * @return              NULL always
348  */
349 rpmts rpmtsFree(rpmts ts);
350
351 /** \ingroup rpmts
352  * Get verify signatures flag(s).
353  * @param ts            transaction set
354  * @return              verify signatures flags
355  */
356 rpmVSFlags rpmtsVSFlags(rpmts ts);
357
358 /** \ingroup rpmts
359  * Set verify signatures flag(s).
360  * @param ts            transaction set
361  * @param vsflags       new verify signatures flags
362  * @return              previous value
363  */
364 rpmVSFlags rpmtsSetVSFlags(rpmts ts, rpmVSFlags vsflags);
365
366 /** \ingroup rpmts
367  * Get transaction rootDir, i.e. path to chroot(2).
368  * @param ts            transaction set
369  * @return              transaction rootDir
370  */
371 const char * rpmtsRootDir(rpmts ts);
372
373 /** \ingroup rpmts
374  * Set transaction rootDir, i.e. path to chroot(2).
375  * @param ts            transaction set
376  * @param rootDir       new transaction rootDir (or NULL)
377  * @return              0 on success, -1 on error (invalid rootDir)
378  */
379 int rpmtsSetRootDir(rpmts ts, const char * rootDir);
380
381 /** \ingroup rpmts
382  * Get transaction script file handle, i.e. stdout/stderr on scriptlet execution
383  * @param ts            transaction set
384  * @return              transaction script file handle
385  */
386 FD_t rpmtsScriptFd(rpmts ts);
387
388 /** \ingroup rpmts
389  * Set transaction script file handle, i.e. stdout/stderr on scriptlet execution
390  * @param ts            transaction set
391  * @param scriptFd      new script file handle (or NULL)
392  */
393 void rpmtsSetScriptFd(rpmts ts, FD_t scriptFd);
394
395 /** \ingroup rpmts
396  * Get transaction id, i.e. transaction time stamp.
397  * @param ts            transaction set
398  * @return              transaction id
399  */
400 rpm_tid_t rpmtsGetTid(rpmts ts);
401
402 /** \ingroup rpmts
403  * Set transaction id, i.e. transaction time stamp.
404  * @param ts            transaction set
405  * @param tid           new transaction id
406  * @return              previous transaction id
407  */
408 rpm_tid_t rpmtsSetTid(rpmts ts, rpm_tid_t tid);
409
410 /** \ingroup rpmts
411  * Get transaction set database handle.
412  * @param ts            transaction set
413  * @return              transaction database handle
414  */
415 rpmdb rpmtsGetRdb(rpmts ts);
416
417 /** \ingroup rpmts
418  * Perform transaction progress notify callback.
419  * @param ts            transaction set
420  * @param te            current transaction element
421  * @param what          type of call back
422  * @param amount        current value
423  * @param total         final value
424  * @return              callback dependent pointer
425  */
426 void * rpmtsNotify(rpmts ts, rpmte te,
427                 rpmCallbackType what, rpm_loff_t amount, rpm_loff_t total);
428
429 int rpmtsSuspendResumeDBLock(rpmts ts, int mode);
430
431 /** \ingroup rpmts
432  * Return number of (ordered) transaction set elements.
433  * @param ts            transaction set
434  * @return              no. of transaction set elements
435  */
436 int rpmtsNElements(rpmts ts);
437
438 /** \ingroup rpmts
439  * Return (ordered) transaction set element.
440  * @param ts            transaction set
441  * @param ix            transaction element index
442  * @return              transaction element (or NULL)
443  */
444 rpmte rpmtsElement(rpmts ts, int ix);
445
446 /** \ingroup rpmts
447  * Get problem ignore bit mask, i.e. bits to filter encountered problems.
448  * @param ts            transaction set
449  * @return              ignore bit mask
450  */
451 rpmprobFilterFlags rpmtsFilterFlags(rpmts ts);
452
453 /** \ingroup rpmts
454  * Get transaction flags, i.e. bits that control rpmtsRun().
455  * @param ts            transaction set
456  * @return              transaction flags
457  */
458 rpmtransFlags rpmtsFlags(rpmts ts);
459
460 /** \ingroup rpmts
461  * Set transaction flags, i.e. bits that control rpmtsRun().
462  * @param ts            transaction set
463  * @param transFlags    new transaction flags
464  * @return              previous transaction flags
465  */
466 rpmtransFlags rpmtsSetFlags(rpmts ts, rpmtransFlags transFlags);
467
468 /** \ingroup rpmts
469  * Retrieve color bits of transaction set.
470  * @param ts            transaction set
471  * @return              color bits
472  */
473 rpm_color_t rpmtsColor(rpmts ts);
474
475 /** \ingroup rpmts
476  * Retrieve prefered file color
477  * @param ts            transaction set
478  * @return              color bits
479  */
480 rpm_color_t rpmtsPrefColor(rpmts ts);
481
482 /** \ingroup rpmts
483  * Set color bits of transaction set.
484  * @param ts            transaction set
485  * @param color         new color bits
486  * @return              previous color bits
487  */
488 rpm_color_t rpmtsSetColor(rpmts ts, rpm_color_t color);
489
490 /** \ingroup rpmts
491  * Set prefered file color
492  * @param ts            transaction set
493  * @param color         new color bits
494  * @return              previous color bits
495  */
496 rpm_color_t rpmtsSetPrefColor(rpmts ts, rpm_color_t color);
497
498 /** \ingroup rpmts
499  * Retrieve operation timestamp from a transaction set.
500  * @param ts            transaction set
501  * @param opx           operation timestamp index
502  * @return              pointer to operation timestamp.
503  */
504 rpmop rpmtsOp(rpmts ts, rpmtsOpX opx);
505
506 /** \ingroup rpmts
507  * Get the plugins associated with a transaction set
508  * @param ts            transaction set
509  * @return              plugins
510  */
511 rpmPlugins rpmtsPlugins(rpmts ts);
512
513 /** \ingroup rpmts
514  * Set transaction notify callback function and argument.
515  *
516  * @warning This call must be made before rpmtsRun() for
517  *      install/upgrade/freshen to function correctly.
518  *
519  * @param ts            transaction set
520  * @param notify        progress callback
521  * @param notifyData    progress callback private data
522  * @return              0 on success
523  */
524 int rpmtsSetNotifyCallback(rpmts ts,
525                 rpmCallbackFunction notify,
526                 rpmCallbackData notifyData);
527
528 /** \ingroup rpmts
529  * Create an empty transaction set.
530  * @return              new transaction set
531  */
532 rpmts rpmtsCreate(void);
533
534 /** \ingroup rpmts
535  * Add package to be installed to transaction set.
536  *
537  * The transaction set is checked for duplicate package names.
538  * If found, the package with the "newest" EVR will be replaced.
539  *
540  * @param ts            transaction set
541  * @param h             header
542  * @param key           package retrieval key (e.g. file name)
543  * @param upgrade       is package being upgraded?
544  * @param relocs        package file relocations
545  * @return              0 on success, 1 on I/O error, 2 needs capabilities
546  */
547 int rpmtsAddInstallElement(rpmts ts, Header h,
548                 const fnpyKey key, int upgrade,
549                 rpmRelocation * relocs);
550
551 /** \ingroup rpmts
552  * Add package to be erased to transaction set.
553  * @param ts            transaction set
554  * @param h             header
555  * @param dboffset      ununsed
556  * @return              0 on success, 1 on error (not installed)
557  */
558 int rpmtsAddEraseElement(rpmts ts, Header h, int dboffset);
559
560 /** \ingroup rpmte
561  * Destroy transaction element iterator.
562  * @param tsi           transaction element iterator
563  * @return              NULL always
564  */
565 rpmtsi rpmtsiFree(rpmtsi tsi);
566
567 /** \ingroup rpmte
568  * Create transaction element iterator.
569  * @param ts            transaction set
570  * @return              transaction element iterator
571  */
572 rpmtsi rpmtsiInit(rpmts ts);
573
574 /** \ingroup rpmte
575  * Return next transaction element of type.
576  * @param tsi           transaction element iterator
577  * @param types         transaction element type selector (0 for any)
578  * @return              next transaction element of type, NULL on termination
579  */
580 rpmte rpmtsiNext(rpmtsi tsi, rpmElementTypes types);
581
582 #ifdef __cplusplus
583 }
584 #endif
585
586
587 #endif  /* H_RPMTS */