6 * Structures and prototypes used for an "rpmts" transaction set.
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>
23 extern int _rpmts_stats;
26 * Bit(s) to control rpmtsRun() operation.
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 RPMTRANS_FLAG_NOPLUGINS = (1 << 7), /*!< from --noplugins */
38 RPMTRANS_FLAG_NOCONTEXTS = (1 << 8), /*!< from --nocontexts */
39 RPMTRANS_FLAG_NOCAPS = (1 << 9), /*!< from --nocaps */
40 /* bits 10-15 unused */
41 RPMTRANS_FLAG_NOTRIGGERPREIN= (1 << 16), /*!< from --notriggerprein */
42 RPMTRANS_FLAG_NOPRE = (1 << 17), /*!< from --nopre */
43 RPMTRANS_FLAG_NOPOST = (1 << 18), /*!< from --nopost */
44 RPMTRANS_FLAG_NOTRIGGERIN = (1 << 19), /*!< from --notriggerin */
45 RPMTRANS_FLAG_NOTRIGGERUN = (1 << 20), /*!< from --notriggerun */
46 RPMTRANS_FLAG_NOPREUN = (1 << 21), /*!< from --nopreun */
47 RPMTRANS_FLAG_NOPOSTUN = (1 << 22), /*!< from --nopostun */
48 RPMTRANS_FLAG_NOTRIGGERPOSTUN = (1 << 23), /*!< from --notriggerpostun */
49 RPMTRANS_FLAG_NOPRETRANS = (1 << 24), /*!< from --nopretrans */
50 RPMTRANS_FLAG_NOPOSTTRANS = (1 << 25), /*!< from --noposttrans */
52 RPMTRANS_FLAG_NOMD5 = (1 << 27), /*!< from --nomd5 */
53 RPMTRANS_FLAG_NOFILEDIGEST = (1 << 27), /*!< from --nofiledigest (alias to --nomd5) */
54 /* bits 28-29 unused */
55 RPMTRANS_FLAG_NOCONFIGS = (1 << 30), /*!< from --noconfigs */
56 RPMTRANS_FLAG_DEPLOOPS = (1 << 31) /*!< from --deploops */
59 typedef rpmFlags rpmtransFlags;
61 #define _noTransScripts \
62 ( RPMTRANS_FLAG_NOPRE | \
63 RPMTRANS_FLAG_NOPOST | \
64 RPMTRANS_FLAG_NOPREUN | \
65 RPMTRANS_FLAG_NOPOSTUN | \
66 RPMTRANS_FLAG_NOPRETRANS | \
67 RPMTRANS_FLAG_NOPOSTTRANS \
70 #define _noTransTriggers \
71 ( RPMTRANS_FLAG_NOTRIGGERPREIN | \
72 RPMTRANS_FLAG_NOTRIGGERIN | \
73 RPMTRANS_FLAG_NOTRIGGERUN | \
74 RPMTRANS_FLAG_NOTRIGGERPOSTUN \
77 /* Avoid unnecessary breakage for stuff referring to these unused flags */
78 #define RPMTRANS_FLAG_NOPAYLOAD 0
79 #define RPMTRANS_FLAG_APPLYONLY 0
80 #define RPMTRANS_FLAG_KEEPOBSOLETE 0
81 #define RPMTRANS_FLAG_DIRSTASH 0
82 #define RPMTRANS_FLAG_REPACKAGE 0
83 #define RPMTRANS_FLAG_PKGCOMMIT 0
84 #define RPMTRANS_FLAG_PKGUNDO 0
85 #define RPMTRANS_FLAG_COMMIT 0
86 #define RPMTRANS_FLAG_UNDO 0
87 #define RPMTRANS_FLAG_REVERSE 0
88 #define RPMTRANS_FLAG_NOSUGGEST 0
89 #define RPMTRANS_FLAG_ADDINDEPS 0
92 * Bit(s) to control digest and signature verification.
96 RPMVSF_NOHDRCHK = (1 << 0),
97 RPMVSF_NEEDPAYLOAD = (1 << 1),
98 /* bit(s) 2-7 unused */
99 RPMVSF_NOSHA1HEADER = (1 << 8),
100 RPMVSF_NOSHA256HEADER = (1 << 9),
101 RPMVSF_NODSAHEADER = (1 << 10),
102 RPMVSF_NORSAHEADER = (1 << 11),
103 /* bit(s) 12-15 unused */
104 RPMVSF_NOPAYLOAD = (1 << 16),
105 RPMVSF_NOMD5 = (1 << 17),
106 RPMVSF_NODSA = (1 << 18),
107 RPMVSF_NORSA = (1 << 19)
108 /* bit(s) 16-31 unused */
111 typedef rpmFlags rpmVSFlags;
113 #define _RPMVSF_NODIGESTS \
114 ( RPMVSF_NOSHA1HEADER | \
115 RPMVSF_NOSHA256HEADER | \
119 #define _RPMVSF_NOSIGNATURES \
120 ( RPMVSF_NODSAHEADER | \
121 RPMVSF_NORSAHEADER | \
125 #define _RPMVSF_NOHEADER \
126 ( RPMVSF_NOSHA1HEADER | \
127 RPMVSF_NOSHA256HEADER | \
128 RPMVSF_NODSAHEADER | \
131 #define _RPMVSF_NOPAYLOAD \
138 * Indices for timestamps.
140 typedef enum rpmtsOpX_e {
144 RPMTS_OP_FINGERPRINT = 3,
145 RPMTS_OP_INSTALL = 5,
147 RPMTS_OP_SCRIPTLETS = 7,
148 RPMTS_OP_COMPRESS = 8,
149 RPMTS_OP_UNCOMPRESS = 9,
150 RPMTS_OP_DIGEST = 10,
151 RPMTS_OP_SIGNATURE = 11,
153 RPMTS_OP_DBREMOVE = 13,
161 RPMTXN_READ = (1 << 0),
162 RPMTXN_WRITE = (1 << 1),
164 typedef rpmFlags rpmtxnFlags;
167 * Perform dependency resolution on the transaction set.
169 * Any problems found by rpmtsCheck() can be examined by retrieving the
170 * problem set with rpmtsProblems(), success here only means that
171 * the resolution was successfully attempted for all packages in the set.
173 * @param ts transaction set
174 * @return 0 on success
176 int rpmtsCheck(rpmts ts);
179 * Determine package order in a transaction set according to dependencies.
181 * Order packages, returning error if circular dependencies cannot be
182 * eliminated by removing Requires's from the loop(s). Only dependencies from
183 * added or removed packages are used to determine ordering using a
184 * topological sort (Knuth vol. 1, p. 262). Use rpmtsCheck() to verify
185 * that all dependencies can be resolved.
187 * The final order ends up as installed packages followed by removed packages,
188 * with packages removed for upgrades immediately following the new package
191 * @param ts transaction set
192 * @return no. of (added) packages that could not be ordered
194 int rpmtsOrder(rpmts ts);
197 * Process all package elements in a transaction set. Before calling
198 * rpmtsRun be sure to have:
200 * - setup the rpm root dir via rpmtsSetRoot().
201 * - setup the rpm notify callback via rpmtsSetNotifyCallback().
202 * - setup the rpm transaction flags via rpmtsSetFlags().
204 * Additionally, though not required you may want to:
206 * - setup the rpm verify signature flags via rpmtsSetVSFlags().
208 * @param ts transaction set
209 * @param okProbs unused
210 * @param ignoreSet bits to filter problem types
211 * @return 0 on success, -1 on error, >0 with newProbs set
213 int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet);
216 * Reference a transaction set instance.
217 * @param ts transaction set
218 * @return new transaction set reference
220 rpmts rpmtsLink (rpmts ts);
223 * Close the database used by the transaction.
224 * @param ts transaction set
225 * @return 0 on success
227 int rpmtsCloseDB(rpmts ts);
230 * Open the database used by the transaction.
231 * @param ts transaction set
232 * @param dbmode O_RDONLY or O_RDWR
233 * @return 0 on success
235 int rpmtsOpenDB(rpmts ts, int dbmode);
238 * Initialize the database used by the transaction.
239 * @deprecated An explicit rpmdbInit() is almost never needed.
240 * @param ts transaction set
241 * @param dbmode O_RDONLY or O_RDWR
242 * @return 0 on success
244 int rpmtsInitDB(rpmts ts, int dbmode);
247 * Return the transaction database mode
248 * @param ts transaction set
249 * @return O_RDONLY, O_RDWR or -1 (lazy opens disabled)
251 int rpmtsGetDBMode(rpmts ts);
254 * Set the transaction database mode. Only permitted when when backing
255 * database hasn't been opened yet (ie rpmtsGetRdb(ts) == NULL)
256 * @param ts transaction set
257 * @param dbmode O_RDONLY, O_RDWR or -1 (disable lazy opens)
258 * @return 0 on success, 1 on error
260 int rpmtsSetDBMode(rpmts ts, int dbmode);
263 * Rebuild the database used by the transaction.
264 * @param ts transaction set
265 * @return 0 on success
267 int rpmtsRebuildDB(rpmts ts);
270 * Verify the database used by the transaction.
271 * @param ts transaction set
272 * @return 0 on success
274 int rpmtsVerifyDB(rpmts ts);
277 * Return transaction database iterator.
278 * @param ts transaction set
279 * @param rpmtag database index tag
280 * @param keyp key data (NULL for sequential access)
281 * @param keylen key data length (0 will use strlen(keyp))
282 * @return NULL on failure
284 rpmdbMatchIterator rpmtsInitIterator(const rpmts ts, rpmDbiTagVal rpmtag,
285 const void * keyp, size_t keylen);
288 * Import a header into the rpmdb
289 * @param txn transaction handle
291 * @param flags (unused)
292 * @return RPMRC_OK/RPMRC_FAIL
294 rpmRC rpmtsImportHeader(rpmtxn txn, Header h, rpmFlags flags);
297 * Import public key packet(s).
298 * @todo Implicit --update policy for gpg-pubkey headers.
299 * @param ts transaction set
300 * @param pkt pgp pubkey packet(s)
301 * @param pktlen pgp pubkey length
302 * @return RPMRC_OK/RPMRC_FAIL
304 rpmRC rpmtsImportPubkey(rpmts ts, const unsigned char * pkt, size_t pktlen);
307 * Retrieve handle for keyring used for this transaction set
308 * @param ts transaction set
309 * @param autoload load default keyring if keyring is not set
310 * @return keyring handle (or NULL)
312 rpmKeyring rpmtsGetKeyring(rpmts ts, int autoload);
315 * Set keyring to use for this transaction set.
316 * Keyring can be only changed while the underlying rpm database is not
318 * @param ts transaction set
319 * @param keyring keyring handle (NULL to free current keyring)
320 * @return 0 on success, -1 on error
322 int rpmtsSetKeyring(rpmts ts, rpmKeyring keyring);
325 * Set dependency solver callback.
326 * @param ts transaction set
327 * @param (*solve) dependency solver callback
328 * @param solveData dependency solver callback data (opaque)
329 * @return 0 on success
331 int rpmtsSetSolveCallback(rpmts ts,
332 int (*solve) (rpmts ts, rpmds ds, const void * data),
333 const void * solveData);
336 * Return current transaction set problems.
337 * @param ts transaction set
338 * @return current problem set (or NULL if no problems)
340 rpmps rpmtsProblems(rpmts ts);
343 * Clean current transaction problem set.
344 * @param ts transaction set
346 void rpmtsCleanProblems(rpmts ts);
349 * Free memory needed only for dependency checks and ordering.
350 * @param ts transaction set
352 void rpmtsClean(rpmts ts);
355 * Re-create an empty transaction set.
356 * @param ts transaction set
358 void rpmtsEmpty(rpmts ts);
361 * Destroy transaction set, closing the database as well.
362 * @param ts transaction set
363 * @return NULL always
365 rpmts rpmtsFree(rpmts ts);
368 * Get verify signatures flag(s).
369 * @param ts transaction set
370 * @return verify signatures flags
372 rpmVSFlags rpmtsVSFlags(rpmts ts);
375 * Set verify signatures flag(s).
376 * @param ts transaction set
377 * @param vsflags new verify signatures flags
378 * @return previous value
380 rpmVSFlags rpmtsSetVSFlags(rpmts ts, rpmVSFlags vsflags);
383 * Get transaction rootDir, i.e. path to chroot(2).
384 * @param ts transaction set
385 * @return transaction rootDir
387 const char * rpmtsRootDir(rpmts ts);
390 * Set transaction rootDir, i.e. path to chroot(2).
391 * @param ts transaction set
392 * @param rootDir new transaction rootDir (or NULL)
393 * @return 0 on success, -1 on error (invalid rootDir)
395 int rpmtsSetRootDir(rpmts ts, const char * rootDir);
398 * Get transaction script file handle, i.e. stdout/stderr on scriptlet execution
399 * @param ts transaction set
400 * @return transaction script file handle
402 FD_t rpmtsScriptFd(rpmts ts);
405 * Set transaction script file handle, i.e. stdout/stderr on scriptlet execution
406 * @param ts transaction set
407 * @param scriptFd new script file handle (or NULL)
409 void rpmtsSetScriptFd(rpmts ts, FD_t scriptFd);
412 * Get transaction id, i.e. transaction time stamp.
413 * @param ts transaction set
414 * @return transaction id
416 rpm_tid_t rpmtsGetTid(rpmts ts);
419 * Set transaction id, i.e. transaction time stamp.
420 * @param ts transaction set
421 * @param tid new transaction id
422 * @return previous transaction id
424 rpm_tid_t rpmtsSetTid(rpmts ts, rpm_tid_t tid);
427 * Get transaction set database handle.
428 * @param ts transaction set
429 * @return transaction database handle
431 rpmdb rpmtsGetRdb(rpmts ts);
434 * Perform transaction progress notify callback.
435 * @param ts transaction set
436 * @param te current transaction element
437 * @param what type of call back
438 * @param amount current value
439 * @param total final value
440 * @return callback dependent pointer
442 void * rpmtsNotify(rpmts ts, rpmte te,
443 rpmCallbackType what, rpm_loff_t amount, rpm_loff_t total);
445 int rpmtsSuspendResumeDBLock(rpmts ts, int mode);
448 * Return number of (ordered) transaction set elements.
449 * @param ts transaction set
450 * @return no. of transaction set elements
452 int rpmtsNElements(rpmts ts);
455 * Return (ordered) transaction set element.
456 * @param ts transaction set
457 * @param ix transaction element index
458 * @return transaction element (or NULL)
460 rpmte rpmtsElement(rpmts ts, int ix);
463 * Get problem ignore bit mask, i.e. bits to filter encountered problems.
464 * @param ts transaction set
465 * @return ignore bit mask
467 rpmprobFilterFlags rpmtsFilterFlags(rpmts ts);
470 * Get transaction flags, i.e. bits that control rpmtsRun().
471 * @param ts transaction set
472 * @return transaction flags
474 rpmtransFlags rpmtsFlags(rpmts ts);
477 * Set transaction flags, i.e. bits that control rpmtsRun().
478 * @param ts transaction set
479 * @param transFlags new transaction flags
480 * @return previous transaction flags
482 rpmtransFlags rpmtsSetFlags(rpmts ts, rpmtransFlags transFlags);
485 * Retrieve color bits of transaction set.
486 * @param ts transaction set
489 rpm_color_t rpmtsColor(rpmts ts);
492 * Retrieve preferred file color
493 * @param ts transaction set
496 rpm_color_t rpmtsPrefColor(rpmts ts);
499 * Set color bits of transaction set.
500 * @param ts transaction set
501 * @param color new color bits
502 * @return previous color bits
504 rpm_color_t rpmtsSetColor(rpmts ts, rpm_color_t color);
507 * Set preferred file color
508 * @param ts transaction set
509 * @param color new color bits
510 * @return previous color bits
512 rpm_color_t rpmtsSetPrefColor(rpmts ts, rpm_color_t color);
515 * Retrieve operation timestamp from a transaction set.
516 * @param ts transaction set
517 * @param opx operation timestamp index
518 * @return pointer to operation timestamp.
520 rpmop rpmtsOp(rpmts ts, rpmtsOpX opx);
523 * Get the plugins associated with a transaction set
524 * @param ts transaction set
527 rpmPlugins rpmtsPlugins(rpmts ts);
530 * Set transaction notify callback function and argument.
532 * @warning This call must be made before rpmtsRun() for
533 * install/upgrade/freshen to function correctly.
535 * @param ts transaction set
536 * @param notify progress callback
537 * @param notifyData progress callback private data
538 * @return 0 on success
540 int rpmtsSetNotifyCallback(rpmts ts,
541 rpmCallbackFunction notify,
542 rpmCallbackData notifyData);
545 * Create an empty transaction set.
546 * @return new transaction set
548 rpmts rpmtsCreate(void);
551 * Add package to be installed to transaction set.
553 * The transaction set is checked for duplicate package names.
554 * If found, the package with the "newest" EVR will be replaced.
556 * @param ts transaction set
558 * @param key package retrieval key (e.g. file name)
559 * @param upgrade is package being upgraded?
560 * @param relocs package file relocations
561 * @return 0 on success, 1 on I/O error, 2 needs capabilities
563 int rpmtsAddInstallElement(rpmts ts, Header h,
564 const fnpyKey key, int upgrade,
565 rpmRelocation * relocs);
568 * Add package to be reinstalled to transaction set.
570 * @param ts transaction set
572 * @param key package retrieval key (e.g. file name)
573 * @return 0 on success
575 int rpmtsAddReinstallElement(rpmts ts, Header h, const fnpyKey key);
578 * Add package to be erased to transaction set.
579 * @param ts transaction set
581 * @param dboffset ununsed
582 * @return 0 on success, 1 on error (not installed)
584 int rpmtsAddEraseElement(rpmts ts, Header h, int dboffset);
587 * Create a transaction (lock) handle
588 * @param ts transaction set
590 * @return transaction handle
592 rpmtxn rpmtxnBegin(rpmts ts, rpmtxnFlags flags);
595 * Destroy transaction (lock) handle
596 * @param txn transaction handle
597 * @return NULL always
599 rpmtxn rpmtxnEnd(rpmtxn txn);
602 * Destroy transaction element iterator.
603 * @param tsi transaction element iterator
604 * @return NULL always
606 rpmtsi rpmtsiFree(rpmtsi tsi);
609 * Create transaction element iterator.
610 * @param ts transaction set
611 * @return transaction element iterator
613 rpmtsi rpmtsiInit(rpmts ts);
616 * Return next transaction element of type.
617 * @param tsi transaction element iterator
618 * @param types transaction element type selector (0 for any)
619 * @return next transaction element of type, NULL on termination
621 rpmte rpmtsiNext(rpmtsi tsi, rpmElementTypes types);