File: | lib/transaction.c |
Warning: | line 1051, column 2 Value stored to 'mi' is never read |
1 | /** \ingroup rpmts |
2 | * \file lib/transaction.c |
3 | */ |
4 | |
5 | #include "system.h" |
6 | |
7 | #include <inttypes.h> |
8 | #include <libgen.h> |
9 | |
10 | #include <rpm/rpmlib.h> /* rpmMachineScore, rpmReadPackageFile */ |
11 | #include <rpm/rpmmacro.h> /* XXX for rpmExpand */ |
12 | #include <rpm/rpmlog.h> |
13 | #include <rpm/rpmdb.h> |
14 | #include <rpm/rpmds.h> |
15 | #include <rpm/rpmfileutil.h> |
16 | #include <rpm/rpmstring.h> |
17 | #include <rpm/rpmsq.h> |
18 | |
19 | #include "lib/fprint.h" |
20 | #include "lib/misc.h" |
21 | #include "lib/rpmchroot.h" |
22 | #include "lib/rpmlock.h" |
23 | #include "lib/rpmds_internal.h" |
24 | #include "lib/rpmfi_internal.h" /* only internal apis */ |
25 | #include "lib/rpmte_internal.h" /* only internal apis */ |
26 | #include "lib/rpmts_internal.h" |
27 | #include "rpmio/rpmhook.h" |
28 | #include "lib/rpmtriggers.h" |
29 | |
30 | #include "lib/rpmplugins.h" |
31 | |
32 | /* XXX FIXME: merge with existing (broken?) tests in system.h */ |
33 | /* portability fiddles */ |
34 | #if STATFS_IN_SYS_STATVFS1 |
35 | #include <sys/statvfs.h> |
36 | |
37 | #else |
38 | # if STATFS_IN_SYS_VFS |
39 | # include <sys/vfs.h> |
40 | # else |
41 | # if STATFS_IN_SYS_MOUNT |
42 | # include <sys/mount.h> |
43 | # else |
44 | # if STATFS_IN_SYS_STATFS |
45 | # include <sys/statfs.h> |
46 | # endif |
47 | # endif |
48 | # endif |
49 | #endif |
50 | |
51 | #include "debug.h" |
52 | |
53 | struct diskspaceInfo_s { |
54 | char * mntPoint; /*!< File system mount point */ |
55 | dev_t dev; /*!< File system device number. */ |
56 | int64_t bneeded; /*!< No. of blocks needed. */ |
57 | int64_t ineeded; /*!< No. of inodes needed. */ |
58 | int64_t bsize; /*!< File system block size. */ |
59 | int64_t bavail; /*!< No. of blocks available. */ |
60 | int64_t iavail; /*!< No. of inodes available. */ |
61 | int64_t obneeded; /*!< Bookkeeping to avoid duplicate reports */ |
62 | int64_t oineeded; /*!< Bookkeeping to avoid duplicate reports */ |
63 | int64_t bdelta; /*!< Delta for temporary space need on updates */ |
64 | int64_t idelta; /*!< Delta for temporary inode need on updates */ |
65 | }; |
66 | |
67 | /* Adjust for root only reserved space. On linux e2fs, this is 5%. */ |
68 | #define adj_fs_blocks(_nb)(((_nb) * 21) / 20) (((_nb) * 21) / 20) |
69 | #define BLOCK_ROUND(size, block)(((size) + (block) - 1) / (block)) (((size) + (block) - 1) / (block)) |
70 | |
71 | static char *getMntPoint(const char *dirName, dev_t dev) |
72 | { |
73 | char mntPoint[PATH_MAX4096]; |
74 | char *resolved_path = realpath(dirName, mntPoint); |
75 | char *end = NULL((void*)0); |
76 | struct stat sb; |
77 | char *res = NULL((void*)0); |
78 | |
79 | if (!resolved_path) { |
80 | strncpy(mntPoint, dirName, PATH_MAX4096); |
81 | mntPoint[PATH_MAX4096-1] = '\0'; |
82 | } |
83 | |
84 | while (end != mntPoint) { |
85 | end = strrchr(mntPoint, '/'); |
86 | if (end == mntPoint) { /* reached "/" */ |
87 | stat("/", &sb); |
88 | if (dev != sb.st_dev) { |
89 | res = xstrdup(mntPoint)rstrdup((mntPoint)); |
90 | } else { |
91 | res = xstrdup("/")rstrdup(("/")); |
92 | } |
93 | break; |
94 | } else if (end) { |
95 | *end = '\0'; |
96 | } else { /* dirName doesn't start with / - should not happen */ |
97 | res = xstrdup(dirName)rstrdup((dirName)); |
98 | break; |
99 | } |
100 | stat(mntPoint, &sb); |
101 | if (dev != sb.st_dev) { |
102 | *end = '/'; |
103 | res = xstrdup(mntPoint)rstrdup((mntPoint)); |
104 | break; |
105 | } |
106 | } |
107 | return res; |
108 | } |
109 | |
110 | static int rpmtsInitDSI(const rpmts ts) |
111 | { |
112 | if (rpmtsFilterFlags(ts) & RPMPROB_FILTER_DISKSPACE) |
113 | return 0; |
114 | ts->dsi = _free(ts->dsi)rfree((ts->dsi)); |
115 | ts->dsi = xcalloc(1, sizeof(*ts->dsi))rcalloc((1), (sizeof(*ts->dsi))); |
116 | return 0; |
117 | } |
118 | |
119 | static rpmDiskSpaceInfo rpmtsCreateDSI(const rpmts ts, dev_t dev, |
120 | const char * dirName, int count) |
121 | { |
122 | rpmDiskSpaceInfo dsi; |
123 | struct stat sb; |
124 | int rc; |
125 | |
126 | #if STATFS_IN_SYS_STATVFS1 |
127 | struct statvfs sfb; |
128 | memset(&sfb, 0, sizeof(sfb)); |
129 | rc = statvfs(dirName, &sfb); |
130 | #else |
131 | struct statfs sfb; |
132 | memset(&sfb, 0, sizeof(sfb)); |
133 | # if STAT_STATFS4 |
134 | /* This platform has the 4-argument version of the statfs call. The last two |
135 | * should be the size of struct statfs and 0, respectively. The 0 is the |
136 | * filesystem type, and is always 0 when statfs is called on a mounted |
137 | * filesystem, as we're doing. |
138 | */ |
139 | rc = statfs(dirName, &sfb, sizeof(sfb), 0); |
140 | # else |
141 | rc = statfs(dirName, &sfb); |
142 | # endif |
143 | #endif |
144 | if (rc) |
145 | return NULL((void*)0); |
146 | |
147 | rc = stat(dirName, &sb); |
148 | if (rc) |
149 | return NULL((void*)0); |
150 | if (sb.st_dev != dev) |
151 | return NULL((void*)0); |
152 | |
153 | ts->dsi = xrealloc(ts->dsi, (count + 2) * sizeof(*ts->dsi))rrealloc((ts->dsi), ((count + 2) * sizeof(*ts->dsi))); |
154 | dsi = ts->dsi + count; |
155 | memset(dsi, 0, 2 * sizeof(*dsi)); |
156 | |
157 | dsi->dev = sb.st_dev; |
158 | dsi->bsize = sfb.f_bsize; |
159 | if (!dsi->bsize) |
160 | dsi->bsize = 512; /* we need a bsize */ |
161 | dsi->bneeded = 0; |
162 | dsi->ineeded = 0; |
163 | #ifdef STATFS_HAS_F_BAVAIL1 |
164 | dsi->bavail = (sfb.f_flag & ST_RDONLYST_RDONLY) ? 0 : sfb.f_bavail; |
165 | #else |
166 | /* FIXME: the statfs struct doesn't have a member to tell how many blocks are |
167 | * available for non-superusers. f_blocks - f_bfree is probably too big, but |
168 | * it's about all we can do. |
169 | */ |
170 | dsi->bavail = sfb.f_blocks - sfb.f_bfree; |
171 | #endif |
172 | /* XXX Avoid FAT and other file systems that have not inodes. */ |
173 | /* XXX assigning negative value to unsigned type */ |
174 | dsi->iavail = !(sfb.f_ffree == 0 && sfb.f_files == 0) |
175 | ? sfb.f_ffree : -1; |
176 | |
177 | /* Find mount point belonging to this device number */ |
178 | dsi->mntPoint = getMntPoint(dirName, dsi->dev); |
179 | |
180 | /* normalize block size to 4096 bytes if it is too big. */ |
181 | if (dsi->bsize > 4096) { |
182 | uint64_t old_size = dsi->bavail * dsi->bsize; |
183 | rpmlog(RPMLOG_DEBUG, |
184 | "dubious blocksize % " PRId64"l" "d" " on %s, normalizing to 4096\n", |
185 | dsi->bsize, dsi->mntPoint); |
186 | dsi->bsize = 4096; /* Assume 4k block size */ |
187 | dsi->bavail = old_size / dsi->bsize; |
188 | } |
189 | |
190 | rpmlog(RPMLOG_DEBUG, |
191 | "0x%08x %8" PRId64"l" "d" " %12" PRId64"l" "d" " %12" PRId64"l" "d"" %s\n", |
192 | (unsigned) dsi->dev, dsi->bsize, |
193 | dsi->bavail, dsi->iavail, |
194 | dsi->mntPoint); |
195 | return dsi; |
196 | } |
197 | |
198 | static rpmDiskSpaceInfo rpmtsGetDSI(const rpmts ts, dev_t dev, |
199 | const char *dirName) { |
200 | rpmDiskSpaceInfo dsi; |
201 | dsi = ts->dsi; |
202 | if (dsi) { |
203 | while (dsi->bsize && dsi->dev != dev) |
204 | dsi++; |
205 | if (dsi->bsize == 0) { |
206 | /* create new entry */ |
207 | dsi = rpmtsCreateDSI(ts, dev, dirName, dsi - ts->dsi); |
208 | } |
209 | } |
210 | return dsi; |
211 | } |
212 | |
213 | static void rpmtsUpdateDSI(const rpmts ts, dev_t dev, const char *dirName, |
214 | rpm_loff_t fileSize, rpm_loff_t prevSize, rpm_loff_t fixupSize, |
215 | rpmFileAction action) |
216 | { |
217 | int64_t bneeded; |
218 | rpmDiskSpaceInfo dsi = rpmtsGetDSI(ts, dev, dirName); |
219 | if (dsi == NULL((void*)0)) |
220 | return; |
221 | |
222 | bneeded = BLOCK_ROUND(fileSize, dsi->bsize)(((fileSize) + (dsi->bsize) - 1) / (dsi->bsize)); |
223 | |
224 | switch (action) { |
225 | case FA_BACKUP: |
226 | case FA_SAVE: |
227 | case FA_ALTNAME: |
228 | dsi->ineeded++; |
229 | dsi->bneeded += bneeded; |
230 | break; |
231 | |
232 | case FA_CREATE: |
233 | dsi->bneeded += bneeded; |
234 | dsi->ineeded++; |
235 | if (prevSize) { |
236 | dsi->bdelta += BLOCK_ROUND(prevSize, dsi->bsize)(((prevSize) + (dsi->bsize) - 1) / (dsi->bsize)); |
237 | dsi->idelta++; |
238 | } |
239 | if (fixupSize) { |
240 | dsi->bdelta += BLOCK_ROUND(fixupSize, dsi->bsize)(((fixupSize) + (dsi->bsize) - 1) / (dsi->bsize)); |
241 | dsi->idelta++; |
242 | } |
243 | |
244 | break; |
245 | |
246 | case FA_ERASE: |
247 | dsi->ineeded--; |
248 | dsi->bneeded -= bneeded; |
249 | break; |
250 | |
251 | default: |
252 | break; |
253 | } |
254 | |
255 | /* adjust bookkeeping when requirements shrink */ |
256 | if (dsi->bneeded < dsi->obneeded) dsi->obneeded = dsi->bneeded; |
257 | if (dsi->ineeded < dsi->oineeded) dsi->oineeded = dsi->ineeded; |
258 | } |
259 | |
260 | static void rpmtsCheckDSIProblems(const rpmts ts, const rpmte te) |
261 | { |
262 | rpmDiskSpaceInfo dsi = ts->dsi; |
263 | |
264 | if (dsi == NULL((void*)0) || !dsi->bsize) |
265 | return; |
266 | |
267 | for (; dsi->bsize; dsi++) { |
268 | |
269 | if (dsi->bavail >= 0 && adj_fs_blocks(dsi->bneeded)(((dsi->bneeded) * 21) / 20) > dsi->bavail) { |
270 | if (dsi->bneeded > dsi->obneeded) { |
271 | rpmteAddProblem(te, RPMPROB_DISKSPACE, NULL((void*)0), dsi->mntPoint, |
272 | (adj_fs_blocks(dsi->bneeded)(((dsi->bneeded) * 21) / 20) - dsi->bavail) * dsi->bsize); |
273 | dsi->obneeded = dsi->bneeded; |
274 | } |
275 | } |
276 | |
277 | if (dsi->iavail >= 0 && adj_fs_blocks(dsi->ineeded)(((dsi->ineeded) * 21) / 20) > dsi->iavail) { |
278 | if (dsi->ineeded > dsi->oineeded) { |
279 | rpmteAddProblem(te, RPMPROB_DISKNODES, NULL((void*)0), dsi->mntPoint, |
280 | (adj_fs_blocks(dsi->ineeded)(((dsi->ineeded) * 21) / 20) - dsi->iavail)); |
281 | dsi->oineeded = dsi->ineeded; |
282 | } |
283 | } |
284 | |
285 | /* Adjust for temporary -> final disk consumption */ |
286 | dsi->bneeded -= dsi->bdelta; |
287 | dsi->bdelta = 0; |
288 | dsi->ineeded -= dsi->idelta; |
289 | dsi->idelta = 0; |
290 | } |
291 | } |
292 | |
293 | static void rpmtsFreeDSI(rpmts ts) |
294 | { |
295 | rpmDiskSpaceInfo dsi; |
296 | if (ts == NULL((void*)0)) |
297 | return; |
298 | dsi = ts->dsi; |
299 | while (dsi && dsi->bsize != 0) { |
300 | dsi->mntPoint = _free(dsi->mntPoint)rfree((dsi->mntPoint)); |
301 | dsi++; |
302 | } |
303 | |
304 | ts->dsi = _free(ts->dsi)rfree((ts->dsi)); |
305 | } |
306 | |
307 | |
308 | /* Calculate total number of files involved in transaction */ |
309 | static uint64_t countFiles(rpmts ts) |
310 | { |
311 | uint64_t fc = 0; |
312 | rpmtsi pi = rpmtsiInit(ts); |
313 | rpmte p; |
314 | rpmfiles files; |
315 | while ((p = rpmtsiNext(pi, 0)) != NULL((void*)0)) { |
316 | files = rpmteFiles(p); |
317 | fc += rpmfilesFC(files); |
318 | rpmfilesFree(files); |
319 | } |
320 | rpmtsiFree(pi); |
321 | return fc; |
322 | } |
323 | |
324 | static int handleRemovalConflict(rpmfiles fi, int fx, rpmfiles ofi, int ofx) |
325 | { |
326 | int rConflicts = 0; /* Removed files don't conflict, normally */ |
327 | rpmFileTypes ft = rpmfiWhatis(rpmfilesFMode(fi, fx)); |
328 | rpmFileTypes oft = rpmfiWhatis(rpmfilesFMode(ofi, ofx)); |
329 | struct stat sb; |
330 | char *fn = NULL((void*)0); |
331 | |
332 | if (oft == XDIR) { |
333 | /* We can't handle directory changing to anything else */ |
334 | if (ft != XDIR) |
335 | rConflicts = 1; |
336 | } else if (oft == LINK) { |
337 | /* We can't correctly handle directory symlink changing to directory */ |
338 | if (ft == XDIR) { |
339 | fn = rpmfilesFN(fi, fx); |
340 | if (stat(fn, &sb) == 0 && S_ISDIR(sb.st_mode)((((sb.st_mode)) & 0170000) == (0040000))) |
341 | rConflicts = 1; |
342 | } |
343 | } |
344 | |
345 | /* |
346 | * ...but if the conflicting item is either not on disk, or has |
347 | * already been changed to the new type, we should be ok afterall. |
348 | */ |
349 | if (rConflicts) { |
350 | if (fn == NULL((void*)0)) |
351 | fn = rpmfilesFN(fi, fx); |
352 | if (lstat(fn, &sb) || rpmfiWhatis(sb.st_mode) == ft) |
353 | rConflicts = 0; |
354 | } |
355 | |
356 | free(fn); |
357 | return rConflicts; |
358 | } |
359 | |
360 | /* |
361 | * Elf files can be "colored", and if enabled in the transaction, the |
362 | * color can be used to resolve conflicts between elf-64bit and elf-32bit |
363 | * files to the hosts preferred type, by default 64bit. The non-preferred |
364 | * type is overwritten or never installed at all and thus the conflict |
365 | * magically disappears. This is infamously nasty "rpm magic" and entirely |
366 | * unnecessary with careful packaging. |
367 | */ |
368 | static int handleColorConflict(rpmts ts, |
369 | rpmfs fs, rpmfiles fi, int fx, |
370 | rpmfs ofs, rpmfiles ofi, int ofx) |
371 | { |
372 | int rConflicts = 1; |
373 | rpm_color_t tscolor = rpmtsColor(ts); |
374 | |
375 | if (tscolor != 0) { |
376 | rpm_color_t fcolor = rpmfilesFColor(fi, fx) & tscolor; |
377 | rpm_color_t ofcolor = rpmfilesFColor(ofi, ofx) & tscolor; |
378 | |
379 | if (fcolor != 0 && ofcolor != 0 && fcolor != ofcolor) { |
380 | rpm_color_t prefcolor = rpmtsPrefColor(ts); |
381 | |
382 | if (fcolor & prefcolor) { |
383 | if (ofs && !XFA_SKIPPING(rpmfsGetAction(fs, fx))((rpmfsGetAction(fs, fx)) == FA_SKIP || (rpmfsGetAction(fs, fx )) == FA_SKIPNSTATE || (rpmfsGetAction(fs, fx)) == FA_SKIPNETSHARED || (rpmfsGetAction(fs, fx)) == FA_SKIPCOLOR)) |
384 | rpmfsSetAction(ofs, ofx, FA_SKIPCOLOR); |
385 | rpmfsSetAction(fs, fx, FA_CREATE); |
386 | rConflicts = 0; |
387 | } else if (ofcolor & prefcolor) { |
388 | if (ofs && XFA_SKIPPING(rpmfsGetAction(fs, fx))((rpmfsGetAction(fs, fx)) == FA_SKIP || (rpmfsGetAction(fs, fx )) == FA_SKIPNSTATE || (rpmfsGetAction(fs, fx)) == FA_SKIPNETSHARED || (rpmfsGetAction(fs, fx)) == FA_SKIPCOLOR)) |
389 | rpmfsSetAction(ofs, ofx, FA_CREATE); |
390 | rpmfsSetAction(fs, fx, FA_SKIPCOLOR); |
391 | rConflicts = 0; |
392 | } |
393 | } |
394 | } |
395 | |
396 | return rConflicts; |
397 | } |
398 | |
399 | /** |
400 | * handleInstInstalledFiles. |
401 | * @param ts transaction set |
402 | * @param p current transaction element |
403 | * @param fi file info set |
404 | * @param fx file index |
405 | * @param otherHeader header containing the matching file |
406 | * @param otherFi matching file info set |
407 | * @param ofx matching file index |
408 | * @param beingRemoved file being removed (installed otherwise) |
409 | */ |
410 | /* XXX only ts->{probs,rpmdb} modified */ |
411 | static void handleInstInstalledFile(const rpmts ts, rpmte p, rpmfiles fi, int fx, |
412 | Header otherHeader, rpmfiles otherFi, int ofx, |
413 | int beingRemoved) |
414 | { |
415 | rpmfs fs = rpmteGetFileStates(p); |
416 | int isCfgFile = ((rpmfilesFFlags(otherFi, ofx) | rpmfilesFFlags(fi, fx)) & RPMFILE_CONFIG); |
417 | |
418 | if (XFA_SKIPPING(rpmfsGetAction(fs, fx))((rpmfsGetAction(fs, fx)) == FA_SKIP || (rpmfsGetAction(fs, fx )) == FA_SKIPNSTATE || (rpmfsGetAction(fs, fx)) == FA_SKIPNETSHARED || (rpmfsGetAction(fs, fx)) == FA_SKIPCOLOR)) |
419 | return; |
420 | |
421 | if (rpmfilesCompare(otherFi, ofx, fi, fx)) { |
422 | int rConflicts = 1; |
423 | char rState = RPMFILE_STATE_REPLACED; |
424 | |
425 | /* |
426 | * There are some removal conflicts we can't handle. However |
427 | * if the package has a %pretrans scriptlet, it might be able to |
428 | * fix the conflict. Let it through on test-transaction to allow |
429 | * eg yum to get past it, if the conflict is present on the actual |
430 | * transaction we'll abort. Behaving differently on test is nasty, |
431 | * but its still better than barfing in middle of large transaction. |
432 | */ |
433 | if (beingRemoved) { |
434 | rConflicts = handleRemovalConflict(fi, fx, otherFi, ofx); |
435 | if (rConflicts && rpmteHaveTransScript(p, RPMTAG_PRETRANS)) { |
436 | if (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST) |
437 | rConflicts = 0; |
438 | } |
439 | } |
440 | |
441 | if (rConflicts) { |
442 | /* If enabled, resolve colored conflicts to preferred type */ |
443 | rConflicts = handleColorConflict(ts, fs, fi, fx, |
444 | NULL((void*)0), otherFi, ofx); |
445 | /* If resolved, we need to adjust in-rpmdb state too */ |
446 | if (rConflicts == 0 && rpmfsGetAction(fs, fx) == FA_CREATE) |
447 | rState = RPMFILE_STATE_WRONGCOLOR; |
448 | } |
449 | |
450 | /* Somebody used The Force, lets shut up... */ |
451 | if (rpmtsFilterFlags(ts) & RPMPROB_FILTER_REPLACEOLDFILES) |
452 | rConflicts = 0; |
453 | |
454 | if (rConflicts) { |
455 | char *altNEVR = headerGetAsString(otherHeader, RPMTAG_NEVRA); |
456 | char *fn = rpmfilesFN(fi, fx); |
457 | rpmteAddProblem(p, RPMPROB_FILE_CONFLICT, altNEVR, fn, |
458 | headerGetInstance(otherHeader)); |
459 | free(fn); |
460 | free(altNEVR); |
461 | } |
462 | |
463 | /* Save file identifier to mark as state REPLACED. */ |
464 | if ( !(isCfgFile || XFA_SKIPPING(rpmfsGetAction(fs, fx))((rpmfsGetAction(fs, fx)) == FA_SKIP || (rpmfsGetAction(fs, fx )) == FA_SKIPNSTATE || (rpmfsGetAction(fs, fx)) == FA_SKIPNETSHARED || (rpmfsGetAction(fs, fx)) == FA_SKIPCOLOR)) ) { |
465 | if (!beingRemoved) |
466 | rpmfsAddReplaced(rpmteGetFileStates(p), fx, rState, |
467 | headerGetInstance(otherHeader), ofx); |
468 | } |
469 | } |
470 | |
471 | /* Determine config file disposition, skipping missing files (if any). */ |
472 | if (isCfgFile) { |
473 | int skipMissing = ((rpmtsFlags(ts) & RPMTRANS_FLAG_ALLFILES) ? 0 : 1); |
474 | rpmFileAction action; |
475 | action = rpmfilesDecideFate(otherFi, ofx, fi, fx, skipMissing); |
476 | rpmfsSetAction(fs, fx, action); |
477 | } |
478 | |
479 | /* Skip already existing files - if 'minimize_writes' is set. */ |
480 | if ((!isCfgFile) && (rpmfsGetAction(fs, fx) == FA_UNKNOWN) && ts->min_writes) { |
481 | if (rpmfileContentsEqual(otherFi, ofx, fi, fx)) { |
482 | rpmfsSetAction(fs, fx, FA_TOUCH); |
483 | } |
484 | } |
485 | |
486 | rpmfilesSetFReplacedSize(fi, fx, rpmfilesFSize(otherFi, ofx)); |
487 | } |
488 | |
489 | /** |
490 | * Update disk space needs on each partition for this package's files. |
491 | */ |
492 | /* XXX only ts->{probs,di} modified */ |
493 | static void handleOverlappedFiles(rpmts ts, fingerPrintCache fpc, rpmte p, rpmfiles fi) |
494 | { |
495 | rpm_loff_t fixupSize = 0; |
496 | int i, j; |
497 | rpmfs fs = rpmteGetFileStates(p); |
498 | rpmfs otherFs; |
499 | rpm_count_t fc = rpmfilesFC(fi); |
500 | int reportConflicts = !(rpmtsFilterFlags(ts) & RPMPROB_FILTER_REPLACENEWFILES); |
501 | fingerPrint * fpList = rpmfilesFps(fi); |
502 | |
503 | for (i = 0; i < fc; i++) { |
504 | struct fingerPrint_s * fiFps; |
505 | int otherPkgNum, otherFileNum; |
506 | rpmfiles otherFi; |
507 | rpmte otherTe; |
508 | rpmfileAttrs FFlags; |
509 | struct rpmffi_s * recs; |
510 | int numRecs; |
511 | |
512 | if (XFA_SKIPPING(rpmfsGetAction(fs, i))((rpmfsGetAction(fs, i)) == FA_SKIP || (rpmfsGetAction(fs, i) ) == FA_SKIPNSTATE || (rpmfsGetAction(fs, i)) == FA_SKIPNETSHARED || (rpmfsGetAction(fs, i)) == FA_SKIPCOLOR)) |
513 | continue; |
514 | |
515 | FFlags = rpmfilesFFlags(fi, i); |
516 | |
517 | fixupSize = 0; |
518 | |
519 | /* |
520 | * Retrieve all records that apply to this file. Note that the |
521 | * file info records were built in the same order as the packages |
522 | * will be installed and removed so the records for an overlapped |
523 | * files will be sorted in exactly the same order. |
524 | */ |
525 | fiFps = fpCacheGetByFp(fpc, fpList, i, &recs, &numRecs); |
526 | |
527 | /* |
528 | * If this package is being added, look only at other packages |
529 | * being added -- removed packages dance to a different tune. |
530 | * |
531 | * If both this and the other package are being added, overlapped |
532 | * files must be identical (or marked as a conflict). The |
533 | * disposition of already installed config files leads to |
534 | * a small amount of extra complexity. |
535 | * |
536 | * If this package is being removed, then there are two cases that |
537 | * need to be worried about: |
538 | * If the other package is being added, then skip any overlapped files |
539 | * so that this package removal doesn't nuke the overlapped files |
540 | * that were just installed. |
541 | * If both this and the other package are being removed, then each |
542 | * file removal from preceding packages needs to be skipped so that |
543 | * the file removal occurs only on the last occurrence of an overlapped |
544 | * file in the transaction set. |
545 | * |
546 | */ |
547 | |
548 | /* |
549 | * Locate this overlapped file in the set of added/removed packages, |
550 | * including the package owning it: a package can have self-conflicting |
551 | * files when directory symlinks are present. Don't compare a file |
552 | * with itself though... |
553 | */ |
554 | for (j = 0; j < numRecs && !(recs[j].p == p && recs[j].fileno == i); j++) |
555 | {}; |
556 | |
557 | /* Find what the previous disposition of this file was. */ |
558 | otherFileNum = -1; /* keep gcc quiet */ |
559 | otherFi = NULL((void*)0); |
560 | otherTe = NULL((void*)0); |
561 | otherFs = NULL((void*)0); |
562 | |
563 | for (otherPkgNum = j - 1; otherPkgNum >= 0; otherPkgNum--) { |
564 | otherTe = recs[otherPkgNum].p; |
565 | otherFileNum = recs[otherPkgNum].fileno; |
566 | otherFs = rpmteGetFileStates(otherTe); |
567 | |
568 | /* Added packages need only look at other added packages. */ |
569 | if (rpmteType(p) == TR_ADDED && rpmteType(otherTe) != TR_ADDED) |
570 | continue; |
571 | |
572 | /* XXX Happens iff fingerprint for incomplete package install. */ |
573 | if (rpmfsGetAction(otherFs, otherFileNum) != FA_UNKNOWN) { |
574 | otherFi = rpmteFiles(otherTe); |
575 | break; |
576 | } |
577 | } |
578 | |
579 | switch (rpmteType(p)) { |
580 | case TR_ADDED: |
581 | if (otherPkgNum < 0) { |
582 | /* XXX is this test still necessary? */ |
583 | rpmFileAction action; |
584 | if (rpmfsGetAction(fs, i) != FA_UNKNOWN) |
585 | break; |
586 | if (rpmfilesConfigConflict(fi, i)) { |
587 | /* Here is a non-overlapped pre-existing config file. */ |
588 | action = (FFlags & RPMFILE_NOREPLACE) ? |
589 | FA_ALTNAME : FA_BACKUP; |
590 | } else { |
591 | action = FA_CREATE; |
592 | } |
593 | rpmfsSetAction(fs, i, action); |
594 | break; |
595 | } |
596 | |
597 | assert(otherFi != NULL)({ if (otherFi != ((void*)0)) ; else __assert_fail ("otherFi != NULL" , "transaction.c", 597, __PRETTY_FUNCTION__); }); |
598 | /* Mark added overlapped non-identical files as a conflict. */ |
599 | if (rpmfilesCompare(otherFi, otherFileNum, fi, i)) { |
600 | int rConflicts; |
601 | |
602 | /* If enabled, resolve colored conflicts to preferred type */ |
603 | rConflicts = handleColorConflict(ts, fs, fi, i, |
604 | otherFs, otherFi, otherFileNum); |
605 | |
606 | if (rConflicts && reportConflicts) { |
607 | char *fn = rpmfilesFN(fi, i); |
608 | rpmteAddProblem(p, RPMPROB_NEW_FILE_CONFLICT, |
609 | rpmteNEVRA(otherTe), fn, 0); |
610 | free(fn); |
611 | } |
612 | } else { |
613 | /* Skip create on all but the first instance of a shared file */ |
614 | rpmFileAction oaction = rpmfsGetAction(otherFs, otherFileNum); |
615 | if (oaction != FA_UNKNOWN && !XFA_SKIPPING(oaction)((oaction) == FA_SKIP || (oaction) == FA_SKIPNSTATE || (oaction ) == FA_SKIPNETSHARED || (oaction) == FA_SKIPCOLOR)) { |
616 | rpmfileAttrs oflags; |
617 | /* ...but ghosts aren't really created so... */ |
618 | oflags = rpmfilesFFlags(otherFi, otherFileNum); |
619 | if (!(oflags & RPMFILE_GHOST)) { |
620 | rpmfsSetAction(fs, i, FA_SKIP); |
621 | } |
622 | /* if the other file is color skipped then skip this file too */ |
623 | } else if (oaction == FA_SKIPCOLOR) { |
624 | rpmfsSetAction(fs, i, FA_SKIPCOLOR); |
625 | } |
626 | } |
627 | |
628 | /* Skipped files dont need fixup size or backups, %config or not */ |
629 | if (XFA_SKIPPING(rpmfsGetAction(fs, i))((rpmfsGetAction(fs, i)) == FA_SKIP || (rpmfsGetAction(fs, i) ) == FA_SKIPNSTATE || (rpmfsGetAction(fs, i)) == FA_SKIPNETSHARED || (rpmfsGetAction(fs, i)) == FA_SKIPCOLOR)) |
630 | break; |
631 | |
632 | /* Try to get the disk accounting correct even if a conflict. */ |
633 | fixupSize = rpmfilesFSize(otherFi, otherFileNum); |
634 | |
635 | if (rpmfilesConfigConflict(fi, i)) { |
636 | /* Here is an overlapped pre-existing config file. */ |
637 | rpmFileAction action; |
638 | action = (FFlags & RPMFILE_NOREPLACE) ? FA_ALTNAME : FA_SKIP; |
639 | rpmfsSetAction(fs, i, action); |
640 | } else { |
641 | /* If not decided yet, create it */ |
642 | if (rpmfsGetAction(fs, i) == FA_UNKNOWN) |
643 | rpmfsSetAction(fs, i, FA_CREATE); |
644 | } |
645 | break; |
646 | |
647 | case TR_REMOVED: |
648 | if (otherPkgNum >= 0) { |
649 | assert(otherFi != NULL)({ if (otherFi != ((void*)0)) ; else __assert_fail ("otherFi != NULL" , "transaction.c", 649, __PRETTY_FUNCTION__); }); |
650 | /* Here is an overlapped added file we don't want to nuke. */ |
651 | if (rpmfsGetAction(otherFs, otherFileNum) != FA_ERASE) { |
652 | /* On updates, don't remove files. */ |
653 | rpmfsSetAction(fs, i, FA_SKIP); |
654 | break; |
655 | } |
656 | /* Here is an overlapped removed file: skip in previous. */ |
657 | rpmfsSetAction(otherFs, otherFileNum, FA_SKIP); |
658 | } |
659 | if (XFA_SKIPPING(rpmfsGetAction(fs, i))((rpmfsGetAction(fs, i)) == FA_SKIP || (rpmfsGetAction(fs, i) ) == FA_SKIPNSTATE || (rpmfsGetAction(fs, i)) == FA_SKIPNETSHARED || (rpmfsGetAction(fs, i)) == FA_SKIPCOLOR)) |
660 | break; |
661 | if (rpmfilesFState(fi, i) != RPMFILE_STATE_NORMAL) |
662 | break; |
663 | |
664 | /* Pre-existing modified config files need to be saved. */ |
665 | if (rpmfilesConfigConflict(fi, i)) { |
666 | rpmfsSetAction(fs, i, FA_SAVE); |
667 | break; |
668 | } |
669 | |
670 | /* Otherwise, we can just erase. */ |
671 | rpmfsSetAction(fs, i, FA_ERASE); |
672 | break; |
673 | } |
674 | rpmfilesFree(otherFi); |
675 | |
676 | /* Update disk space info for a file. */ |
677 | rpmtsUpdateDSI(ts, fpEntryDev(fpc, fiFps), fpEntryDir(fpc, fiFps), |
678 | rpmfilesFSize(fi, i), rpmfilesFReplacedSize(fi, i), |
679 | fixupSize, rpmfsGetAction(fs, i)); |
680 | |
681 | } |
682 | } |
683 | |
684 | /** |
685 | * Ensure that current package is newer than installed package. |
686 | * @param tspool transaction string pool |
687 | * @param p current transaction element |
688 | * @param h installed header |
689 | */ |
690 | static void ensureOlder(rpmstrPool tspool, const rpmte p, const Header h) |
691 | { |
692 | rpmsenseFlags reqFlags = (RPMSENSE_LESS | RPMSENSE_EQUAL); |
693 | rpmds req; |
694 | |
695 | req = rpmdsSinglePool(tspool, RPMTAG_REQUIRENAME, |
696 | rpmteN(p), rpmteEVR(p), reqFlags); |
697 | if (rpmdsMatches(tspool, h, -1, req, 1, _rpmds_nopromote) == 0) { |
698 | char * altNEVR = headerGetAsString(h, RPMTAG_NEVRA); |
699 | rpmteAddProblem(p, RPMPROB_OLDPACKAGE, altNEVR, NULL((void*)0), |
700 | headerGetInstance(h)); |
701 | free(altNEVR); |
702 | } |
703 | rpmdsFree(req); |
704 | } |
705 | |
706 | /** |
707 | * Check if the curent file in the file iterator is in the |
708 | * netshardpath and though should be excluded. |
709 | * @param ts transaction set |
710 | * @param fi file info set |
711 | * @returns 1 if path is net shared path, otherwise 0 |
712 | */ |
713 | static int matchNetsharedpath(const rpmts ts, rpmfi fi) |
714 | { |
715 | char ** nsp; |
716 | const char * dn, * bn; |
717 | size_t dnlen, bnlen; |
718 | char * s; |
719 | bn = rpmfiBN(fi); |
720 | bnlen = strlen(bn); |
721 | dn = rpmfiDN(fi); |
722 | dnlen = strlen(dn); |
723 | for (nsp = ts->netsharedPaths; nsp && *nsp; nsp++) { |
724 | size_t len; |
725 | |
726 | len = strlen(*nsp); |
727 | if (dnlen >= len) { |
728 | if (!rstreqn(dn, *nsp, len)) |
729 | continue; |
730 | /* Only directories or complete file paths can be net shared */ |
731 | if (!(dn[len] == '/' || dn[len] == '\0')) |
732 | continue; |
733 | } else { |
734 | if (len < (dnlen + bnlen)) |
735 | continue; |
736 | if (!rstreqn(dn, *nsp, dnlen)) |
737 | continue; |
738 | /* Insure that only the netsharedpath basename is compared. */ |
739 | if ((s = strchr((*nsp) + dnlen, '/')) != NULL((void*)0) && s[1] != '\0') |
740 | continue; |
741 | if (!rstreqn(bn, (*nsp) + dnlen, bnlen)) |
742 | continue; |
743 | len = dnlen + bnlen; |
744 | /* Only directories or complete file paths can be net shared */ |
745 | if (!((*nsp)[len] == '/' || (*nsp)[len] == '\0')) |
746 | continue; |
747 | } |
748 | |
749 | break; |
750 | } |
751 | return (nsp != NULL((void*)0) && *nsp != NULL((void*)0)); |
752 | } |
753 | |
754 | static void skipEraseFiles(const rpmts ts, rpmfiles files, rpmfs fs) |
755 | { |
756 | int i; |
757 | /* |
758 | * Skip net shared paths. |
759 | * Net shared paths are not relative to the current root (though |
760 | * they do need to take package relocations into account). |
761 | */ |
762 | if (ts->netsharedPaths) { |
763 | rpmfi fi = rpmfilesIter(files, RPMFI_ITER_FWD); |
764 | while ((i = rpmfiNext(fi)) >= 0) |
765 | { |
766 | if (matchNetsharedpath(ts, fi)) |
767 | rpmfsSetAction(fs, i, FA_SKIPNETSHARED); |
768 | } |
769 | rpmfiFree(fi); |
770 | } |
771 | } |
772 | |
773 | |
774 | /** |
775 | * Skip any files that do not match install policies. |
776 | * @param ts transaction set |
777 | * @param files file info set |
778 | * @param fs file states |
779 | */ |
780 | static void skipInstallFiles(const rpmts ts, rpmfiles files, rpmfs fs) |
781 | { |
782 | rpm_color_t tscolor = rpmtsColor(ts); |
783 | rpm_color_t FColor; |
784 | int noConfigs = (rpmtsFlags(ts) & RPMTRANS_FLAG_NOCONFIGS); |
785 | int noDocs = (rpmtsFlags(ts) & RPMTRANS_FLAG_NODOCS); |
786 | int * drc; |
787 | char * dff; |
788 | int dc; |
789 | int i, j, ix; |
790 | rpmfi fi = rpmfilesIter(files, RPMFI_ITER_FWD); |
791 | |
792 | if (!noDocs) |
793 | noDocs = rpmExpandNumeric("%{_excludedocs}"); |
794 | |
795 | /* Compute directory refcount, skip directory if now empty. */ |
796 | dc = rpmfiDC(fi); |
797 | drc = xcalloc(dc, sizeof(*drc))rcalloc((dc), (sizeof(*drc))); |
798 | dff = xcalloc(dc, sizeof(*dff))rcalloc((dc), (sizeof(*dff))); |
799 | |
800 | fi = rpmfiInit(fi, 0); |
801 | while ((i = rpmfiNext(fi)) >= 0) { |
802 | const char *flangs; |
803 | |
804 | ix = rpmfiDX(fi); |
805 | drc[ix]++; |
806 | |
807 | /* Don't bother with skipped files */ |
808 | /* XXX FIXME: --excludepath on %license should not be permitted */ |
809 | if (XFA_SKIPPING(rpmfsGetAction(fs, i))((rpmfsGetAction(fs, i)) == FA_SKIP || (rpmfsGetAction(fs, i) ) == FA_SKIPNSTATE || (rpmfsGetAction(fs, i)) == FA_SKIPNETSHARED || (rpmfsGetAction(fs, i)) == FA_SKIPCOLOR)) { |
810 | drc[ix]--; dff[ix] = 1; |
811 | continue; |
812 | } |
813 | |
814 | /* Ignore colored files not in our rainbow. */ |
815 | FColor = rpmfiFColor(fi); |
816 | if (tscolor && FColor && !(tscolor & FColor)) { |
817 | drc[ix]--; dff[ix] = 1; |
818 | rpmfsSetAction(fs, i, FA_SKIPCOLOR); |
819 | continue; |
820 | } |
821 | |
822 | /* |
823 | * Skip net shared paths. |
824 | * Net shared paths are not relative to the current root (though |
825 | * they do need to take package relocations into account). |
826 | */ |
827 | if (ts->netsharedPaths) { |
828 | if (matchNetsharedpath(ts, fi)) { |
829 | drc[ix]--; dff[ix] = 1; |
830 | rpmfsSetAction(fs, i, FA_SKIPNETSHARED); |
831 | continue; |
832 | } |
833 | } |
834 | |
835 | /* |
836 | * In general, excluding license files is not permitted. In case |
837 | * of SKIPNETSHARED and SKIPCOLOR the file is expected to be |
838 | * there via other means however so that is ok. |
839 | */ |
840 | if (rpmfiFFlags(fi) & RPMFILE_LICENSE) |
841 | continue; |
842 | |
843 | /* |
844 | * Skip i18n language specific files. |
845 | */ |
846 | flangs = (ts->installLangs != NULL((void*)0)) ? rpmfiFLangs(fi) : NULL((void*)0); |
847 | if (flangs != NULL((void*)0) && *flangs != '\0') { |
848 | const char *l, *le; |
849 | char **lang; |
850 | for (lang = ts->installLangs; *lang != NULL((void*)0); lang++) { |
851 | for (l = flangs; *l != '\0'; l = le) { |
852 | for (le = l; *le != '\0' && *le != '|'; le++) |
853 | {}; |
854 | if ((le-l) > 0 && rstreqn(*lang, l, (le-l))) |
855 | break; |
856 | if (*le == '|') le++; /* skip over | */ |
857 | } |
858 | if (*l != '\0') |
859 | break; |
860 | } |
861 | if (*lang == NULL((void*)0)) { |
862 | drc[ix]--; dff[ix] = 1; |
863 | rpmfsSetAction(fs, i, FA_SKIPNSTATE); |
864 | continue; |
865 | } |
866 | } |
867 | |
868 | /* |
869 | * Skip config files if requested. |
870 | */ |
871 | if (noConfigs && (rpmfiFFlags(fi) & RPMFILE_CONFIG)) { |
872 | drc[ix]--; dff[ix] = 1; |
873 | rpmfsSetAction(fs, i, FA_SKIPNSTATE); |
874 | continue; |
875 | } |
876 | |
877 | /* |
878 | * Skip documentation if requested. |
879 | */ |
880 | if (noDocs && (rpmfiFFlags(fi) & RPMFILE_DOC)) { |
881 | drc[ix]--; dff[ix] = 1; |
882 | rpmfsSetAction(fs, i, FA_SKIPNSTATE); |
883 | continue; |
884 | } |
885 | } |
886 | |
887 | /* Skip (now empty) directories that had skipped files. */ |
888 | /* Iterate over dirs in reversed order to solve subdirs at first */ |
889 | for (j = dc - 1; j >= 0; j--) { |
890 | const char * dn, * bn; |
891 | size_t dnlen, bnlen; |
892 | |
893 | if (drc[j]) continue; /* dir still has files. */ |
894 | if (!dff[j]) continue; /* dir was not emptied here. */ |
895 | |
896 | /* Find parent directory and basename. */ |
897 | dn = rpmfilesDN(files, j); dnlen = strlen(dn) - 1; |
898 | bn = dn + dnlen; bnlen = 0; |
899 | while (bn > dn && bn[-1] != '/') { |
900 | bnlen++; |
901 | dnlen--; |
902 | bn--; |
903 | } |
904 | |
905 | /* If explicitly included in the package, skip the directory. */ |
906 | fi = rpmfiInit(fi, 0); |
907 | while ((i = rpmfiNext(fi)) >= 0) { |
908 | const char * fdn, * fbn; |
909 | rpm_mode_t fFMode; |
910 | |
911 | if (XFA_SKIPPING(rpmfsGetAction(fs, i))((rpmfsGetAction(fs, i)) == FA_SKIP || (rpmfsGetAction(fs, i) ) == FA_SKIPNSTATE || (rpmfsGetAction(fs, i)) == FA_SKIPNETSHARED || (rpmfsGetAction(fs, i)) == FA_SKIPCOLOR)) |
912 | continue; |
913 | |
914 | fFMode = rpmfiFMode(fi); |
915 | |
916 | if (rpmfiWhatis(fFMode) != XDIR) |
917 | continue; |
918 | fdn = rpmfiDN(fi); |
919 | if (strlen(fdn) != dnlen) |
920 | continue; |
921 | if (!rstreqn(fdn, dn, dnlen)) |
922 | continue; |
923 | fbn = rpmfiBN(fi); |
924 | if (strlen(fbn) != bnlen) |
925 | continue; |
926 | if (!rstreqn(fbn, bn, bnlen)) |
927 | continue; |
928 | rpmlog(RPMLOG_DEBUG, "excluding directory %s\n", dn); |
929 | rpmfsSetAction(fs, i, FA_SKIPNSTATE); |
930 | ix = rpmfiDX(fi); |
931 | /* Decrease count of files for parent directory */ |
932 | drc[ix]--; |
933 | /* Mark directory because something was removed from them */ |
934 | dff[ix] = 1; |
935 | break; |
936 | } |
937 | } |
938 | |
939 | free(drc); |
940 | free(dff); |
941 | rpmfiFree(fi); |
942 | } |
943 | |
944 | #undef HASHTYPErpmStringSet |
945 | #undef HTKEYTYPErpmsid |
946 | #undef HTDATATYPE |
947 | |
948 | #define HASHTYPErpmStringSet rpmStringSet |
949 | #define HTKEYTYPErpmsid rpmsid |
950 | #include "lib/rpmhash.H" |
951 | #include "lib/rpmhash.C" |
952 | |
953 | static unsigned int sidHash(rpmsid sid) |
954 | { |
955 | return sid; |
956 | } |
957 | |
958 | static int sidCmp(rpmsid a, rpmsid b) |
959 | { |
960 | return (a != b); |
961 | } |
962 | |
963 | /* Get a rpmdbMatchIterator containing all files in |
964 | * the rpmdb that share the basename with one from |
965 | * the transaction. |
966 | * @param ts transaction set |
967 | * @return rpmdbMatchIterator sorted |
968 | by (package, fileNum) |
969 | */ |
970 | static |
971 | rpmdbMatchIterator rpmFindBaseNamesInDB(rpmts ts, uint64_t fileCount) |
972 | { |
973 | tsMembers tsmem = rpmtsMembers(ts); |
974 | rpmstrPool tspool = rpmtsPool(ts); |
975 | rpmtsi pi; rpmte p; |
976 | rpmfiles files; |
977 | rpmfi fi; |
978 | rpmdbMatchIterator mi; |
979 | int oc = 0; |
980 | const char * baseName; |
981 | rpmsid baseNameId; |
982 | |
983 | rpmStringSet baseNames = rpmStringSetCreate(fileCount, |
984 | sidHash, sidCmp, NULL((void*)0)); |
985 | |
986 | mi = rpmdbNewIterator(rpmtsGetRdb(ts), RPMDBI_BASENAMES); |
987 | |
988 | pi = rpmtsiInit(ts); |
989 | while ((p = rpmtsiNext(pi, 0)) != NULL((void*)0)) { |
990 | (void) rpmsqPoll(); |
991 | |
992 | rpmtsNotify(ts, NULL((void*)0), RPMCALLBACK_TRANS_PROGRESS, oc++, tsmem->orderCount); |
993 | |
994 | /* Gather all installed headers with matching basename's. */ |
995 | files = rpmteFiles(p); |
996 | fi = rpmfilesIter(files, RPMFI_ITER_FWD); |
997 | while (rpmfiNext(fi) >= 0) { |
998 | size_t keylen; |
999 | |
1000 | baseNameId = rpmfiBNId(fi); |
1001 | |
1002 | if (rpmStringSetHasEntry(baseNames, baseNameId)) |
1003 | continue; |
1004 | |
1005 | keylen = rpmstrPoolStrlen(tspool, baseNameId); |
1006 | baseName = rpmstrPoolStr(tspool, baseNameId); |
1007 | if (keylen == 0) |
1008 | keylen++; /* XXX "/" fixup. */ |
1009 | rpmdbExtendIterator(mi, baseName, keylen); |
1010 | rpmStringSetAddEntry(baseNames, baseNameId); |
1011 | } |
1012 | rpmfiFree(fi); |
1013 | rpmfilesFree(files); |
1014 | } |
1015 | rpmtsiFree(pi); |
1016 | rpmStringSetFree(baseNames); |
1017 | |
1018 | rpmdbSortIterator(mi); |
1019 | /* iterator is now sorted by (recnum, filenum) */ |
1020 | return mi; |
1021 | } |
1022 | |
1023 | /* Check files in the transactions against the rpmdb |
1024 | * Lookup all files with the same basename in the rpmdb |
1025 | * and then check for matching finger prints |
1026 | * @param ts transaction set |
1027 | * @param fpc global finger print cache |
1028 | */ |
1029 | static |
1030 | void checkInstalledFiles(rpmts ts, uint64_t fileCount, fingerPrintCache fpc) |
1031 | { |
1032 | tsMembers tsmem = rpmtsMembers(ts); |
1033 | rpmte p; |
1034 | rpmfiles fi; |
1035 | rpmfs fs; |
1036 | int j; |
1037 | unsigned int fileNum; |
1038 | |
1039 | rpmdbMatchIterator mi; |
1040 | Header h, newheader; |
1041 | |
1042 | rpmlog(RPMLOG_DEBUG, "computing file dispositions\n"); |
1043 | |
1044 | mi = rpmFindBaseNamesInDB(ts, fileCount); |
1045 | |
1046 | /* For all installed headers with matching basename's ... */ |
1047 | if (mi == NULL((void*)0)) |
1048 | return; |
1049 | |
1050 | if (rpmdbGetIteratorCount(mi) == 0) { |
1051 | mi = rpmdbFreeIterator(mi); |
Value stored to 'mi' is never read | |
1052 | return; |
1053 | } |
1054 | |
1055 | /* Loop over all packages from the rpmdb */ |
1056 | h = newheader = rpmdbNextIterator(mi); |
1057 | while (h != NULL((void*)0)) { |
1058 | headerGetFlags hgflags = HEADERGET_MINMEM; |
1059 | struct rpmtd_s bnames, dnames, dindexes, ostates; |
1060 | fingerPrint *fpp = NULL((void*)0); |
1061 | unsigned int installedPkg; |
1062 | int beingRemoved = 0; |
1063 | rpmfiles otherFi = NULL((void*)0); |
1064 | rpmte *removedPkg = NULL((void*)0); |
1065 | |
1066 | /* Is this package being removed? */ |
1067 | installedPkg = rpmdbGetIteratorOffset(mi); |
1068 | if (packageHashGetEntry(tsmem->removedPackages, installedPkg, |
1069 | &removedPkg, NULL((void*)0), NULL((void*)0))) { |
1070 | beingRemoved = 1; |
1071 | otherFi = rpmteFiles(removedPkg[0]); |
1072 | } |
1073 | |
1074 | h = headerLink(h); |
1075 | /* For packages being removed we can use its rpmfi to avoid all this */ |
1076 | if (!beingRemoved) { |
1077 | headerGet(h, RPMTAG_BASENAMES, &bnames, hgflags); |
1078 | headerGet(h, RPMTAG_DIRNAMES, &dnames, hgflags); |
1079 | headerGet(h, RPMTAG_DIRINDEXES, &dindexes, hgflags); |
1080 | headerGet(h, RPMTAG_FILESTATES, &ostates, hgflags); |
1081 | } |
1082 | |
1083 | /* loop over all interesting files in that package */ |
1084 | do { |
1085 | int fpIx; |
1086 | struct rpmffi_s * recs; |
1087 | int numRecs; |
1088 | const char * dirName; |
1089 | const char * baseName; |
1090 | |
1091 | /* lookup finger print for this file */ |
1092 | fileNum = rpmdbGetIteratorFileNum(mi); |
1093 | if (!beingRemoved) { |
1094 | rpmtdSetIndex(&bnames, fileNum); |
1095 | rpmtdSetIndex(&dindexes, fileNum); |
1096 | rpmtdSetIndex(&dnames, *rpmtdGetUint32(&dindexes)); |
1097 | rpmtdSetIndex(&ostates, fileNum); |
1098 | |
1099 | dirName = rpmtdGetString(&dnames); |
1100 | baseName = rpmtdGetString(&bnames); |
1101 | |
1102 | fpLookup(fpc, dirName, baseName, &fpp); |
1103 | fpIx = 0; |
1104 | } else { |
1105 | fpp = rpmfilesFps(otherFi); |
1106 | fpIx = fileNum; |
1107 | } |
1108 | |
1109 | /* search for files in the transaction with same finger print */ |
1110 | fpCacheGetByFp(fpc, fpp, fpIx, &recs, &numRecs); |
1111 | |
1112 | for (j = 0; j < numRecs; j++) { |
1113 | p = recs[j].p; |
1114 | fi = rpmteFiles(p); |
1115 | fs = rpmteGetFileStates(p); |
1116 | |
1117 | /* Determine the fate of each file. */ |
1118 | switch (rpmteType(p)) { |
1119 | case TR_ADDED: |
1120 | if (!otherFi) { |
1121 | /* XXX What to do if this fails? */ |
1122 | otherFi = rpmfilesNew(NULL((void*)0), h, RPMTAG_BASENAMES, RPMFI_KEEPHEADER); |
1123 | } |
1124 | handleInstInstalledFile(ts, p, fi, recs[j].fileno, |
1125 | h, otherFi, fileNum, beingRemoved); |
1126 | break; |
1127 | case TR_REMOVED: |
1128 | if (!beingRemoved) { |
1129 | if (*rpmtdGetChar(&ostates) == RPMFILE_STATE_NORMAL) |
1130 | rpmfsSetAction(fs, recs[j].fileno, FA_SKIP); |
1131 | } |
1132 | break; |
1133 | } |
1134 | rpmfilesFree(fi); |
1135 | } |
1136 | |
1137 | newheader = rpmdbNextIterator(mi); |
1138 | |
1139 | } while (newheader==h); |
1140 | |
1141 | otherFi = rpmfilesFree(otherFi); |
1142 | if (!beingRemoved) { |
1143 | rpmtdFreeData(&ostates); |
1144 | rpmtdFreeData(&bnames); |
1145 | rpmtdFreeData(&dnames); |
1146 | rpmtdFreeData(&dindexes); |
1147 | free(fpp); |
1148 | } |
1149 | headerFree(h); |
1150 | h = newheader; |
1151 | } |
1152 | |
1153 | rpmdbFreeIterator(mi); |
1154 | } |
1155 | |
1156 | #define badArch(_a)(rpmMachineScore(RPM_MACHTABLE_INSTARCH, (_a)) == 0) (rpmMachineScore(RPM_MACHTABLE_INSTARCH, (_a)) == 0) |
1157 | #define badOs(_a)(rpmMachineScore(RPM_MACHTABLE_INSTOS, (_a)) == 0) (rpmMachineScore(RPM_MACHTABLE_INSTOS, (_a)) == 0) |
1158 | |
1159 | /* |
1160 | * For packages being installed: |
1161 | * - verify package arch/os. |
1162 | * - verify package epoch:version-release is newer. |
1163 | */ |
1164 | static rpmps checkProblems(rpmts ts) |
1165 | { |
1166 | rpm_color_t tscolor = rpmtsColor(ts); |
1167 | rpmprobFilterFlags probFilter = rpmtsFilterFlags(ts); |
1168 | rpmstrPool tspool = rpmtsPool(ts); |
1169 | rpmtsi pi = rpmtsiInit(ts); |
1170 | rpmte p; |
1171 | |
1172 | /* The ordering doesn't matter here */ |
1173 | /* XXX Only added packages need be checked. */ |
1174 | rpmlog(RPMLOG_DEBUG, "sanity checking %d elements\n", rpmtsNElements(ts)); |
1175 | while ((p = rpmtsiNext(pi, TR_ADDED)) != NULL((void*)0)) { |
1176 | |
1177 | if (!(probFilter & RPMPROB_FILTER_IGNOREARCH) && badArch(rpmteA(p))(rpmMachineScore(RPM_MACHTABLE_INSTARCH, (rpmteA(p))) == 0)) |
1178 | rpmteAddProblem(p, RPMPROB_BADARCH, rpmteA(p), NULL((void*)0), 0); |
1179 | |
1180 | if (!(probFilter & RPMPROB_FILTER_IGNOREOS) && badOs(rpmteO(p))(rpmMachineScore(RPM_MACHTABLE_INSTOS, (rpmteO(p))) == 0)) |
1181 | rpmteAddProblem(p, RPMPROB_BADOS, rpmteO(p), NULL((void*)0), 0); |
1182 | |
1183 | if (!(probFilter & RPMPROB_FILTER_OLDPACKAGE)) { |
1184 | Header h; |
1185 | rpmdbMatchIterator mi; |
1186 | mi = rpmtsInitIterator(ts, RPMDBI_NAME, rpmteN(p), 0); |
1187 | while ((h = rpmdbNextIterator(mi)) != NULL((void*)0)) |
1188 | ensureOlder(tspool, p, h); |
1189 | rpmdbFreeIterator(mi); |
1190 | } |
1191 | |
1192 | if (!(probFilter & RPMPROB_FILTER_REPLACEPKG)) { |
1193 | Header h; |
1194 | rpmdbMatchIterator mi; |
1195 | mi = rpmtsPrunedIterator(ts, RPMDBI_NAME, rpmteN(p), 1); |
1196 | rpmdbSetIteratorRE(mi, RPMTAG_EPOCH, RPMMIRE_STRCMP, rpmteE(p)); |
1197 | rpmdbSetIteratorRE(mi, RPMTAG_VERSION, RPMMIRE_STRCMP, rpmteV(p)); |
1198 | rpmdbSetIteratorRE(mi, RPMTAG_RELEASE, RPMMIRE_STRCMP, rpmteR(p)); |
1199 | if (tscolor) { |
1200 | rpmdbSetIteratorRE(mi, RPMTAG_ARCH, RPMMIRE_STRCMP, rpmteA(p)); |
1201 | rpmdbSetIteratorRE(mi, RPMTAG_OS, RPMMIRE_STRCMP, rpmteO(p)); |
1202 | } |
1203 | |
1204 | if ((h = rpmdbNextIterator(mi)) != NULL((void*)0)) { |
1205 | rpmteAddProblem(p, RPMPROB_PKG_INSTALLED, NULL((void*)0), NULL((void*)0), |
1206 | headerGetInstance(h)); |
1207 | } |
1208 | rpmdbFreeIterator(mi); |
1209 | } |
1210 | |
1211 | if (!(probFilter & RPMPROB_FILTER_FORCERELOCATE)) |
1212 | rpmteAddRelocProblems(p); |
1213 | } |
1214 | rpmtsiFree(pi); |
1215 | return rpmtsProblems(ts); |
1216 | } |
1217 | |
1218 | /* |
1219 | * Run pre/post transaction scripts for transaction set |
1220 | * param ts Transaction set |
1221 | * param goal PKG_PRETRANS/PKG_POSTTRANS |
1222 | * return 0 on success |
1223 | */ |
1224 | static int runTransScripts(rpmts ts, pkgGoal goal) |
1225 | { |
1226 | int rc = 0; |
1227 | rpmte p; |
1228 | rpmtsi pi = rpmtsiInit(ts); |
1229 | rpmElementTypes types = TR_ADDED; |
1230 | int i = 0; |
1231 | if (goal == PKG_TRANSFILETRIGGERUN) |
1232 | types = TR_REMOVED; |
1233 | |
1234 | while ((p = rpmtsiNext(pi, types)) != NULL((void*)0)) { |
1235 | rc += rpmteProcess(p, goal, i++); |
1236 | } |
1237 | rpmtsiFree(pi); |
1238 | return rc; |
1239 | } |
1240 | |
1241 | static int rpmtsSetup(rpmts ts, rpmprobFilterFlags ignoreSet) |
1242 | { |
1243 | rpm_tid_t tid = (rpm_tid_t) time(NULL((void*)0)); |
1244 | int dbmode = (rpmtsFlags(ts) & RPMTRANS_FLAG_TEST) ? O_RDONLY00 : (O_RDWR02|O_CREAT0100); |
1245 | |
1246 | if (rpmtsFlags(ts) & RPMTRANS_FLAG_NOSCRIPTS) |
1247 | (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | _noTransScripts( RPMTRANS_FLAG_NOPRE | RPMTRANS_FLAG_NOPOST | RPMTRANS_FLAG_NOPREUN | RPMTRANS_FLAG_NOPOSTUN | RPMTRANS_FLAG_NOPRETRANS | RPMTRANS_FLAG_NOPOSTTRANS ) | _noTransTriggers( RPMTRANS_FLAG_NOTRIGGERPREIN | RPMTRANS_FLAG_NOTRIGGERIN | RPMTRANS_FLAG_NOTRIGGERUN | RPMTRANS_FLAG_NOTRIGGERPOSTUN ))); |
1248 | if (rpmtsFlags(ts) & RPMTRANS_FLAG_NOTRIGGERS) |
1249 | (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | _noTransTriggers( RPMTRANS_FLAG_NOTRIGGERPREIN | RPMTRANS_FLAG_NOTRIGGERIN | RPMTRANS_FLAG_NOTRIGGERUN | RPMTRANS_FLAG_NOTRIGGERPOSTUN ))); |
1250 | |
1251 | if (rpmtsFlags(ts) & (RPMTRANS_FLAG_JUSTDB | RPMTRANS_FLAG_TEST)) |
1252 | (void) rpmtsSetFlags(ts, (rpmtsFlags(ts) | _noTransScripts( RPMTRANS_FLAG_NOPRE | RPMTRANS_FLAG_NOPOST | RPMTRANS_FLAG_NOPREUN | RPMTRANS_FLAG_NOPOSTUN | RPMTRANS_FLAG_NOPRETRANS | RPMTRANS_FLAG_NOPOSTTRANS ) | _noTransTriggers( RPMTRANS_FLAG_NOTRIGGERPREIN | RPMTRANS_FLAG_NOTRIGGERIN | RPMTRANS_FLAG_NOTRIGGERUN | RPMTRANS_FLAG_NOTRIGGERPOSTUN ))); |
1253 | |
1254 | /* |
1255 | * Make sure the database is open RDWR for package install/erase. |
1256 | * Note that we initialize chroot state here even if it's just "/" as |
1257 | * this ensures we can successfully perform open(".") which is |
1258 | * required to reliably restore cwd after Lua scripts. |
1259 | */ |
1260 | if (rpmtsOpenDB(ts, dbmode) || rpmChrootSet(rpmtsRootDir(ts))) |
1261 | return -1; |
1262 | |
1263 | ts->ignoreSet = ignoreSet; |
1264 | (void) rpmtsSetTid(ts, tid); |
1265 | |
1266 | /* Get available space on mounted file systems. */ |
1267 | (void) rpmtsInitDSI(ts); |
1268 | |
1269 | return 0; |
1270 | } |
1271 | |
1272 | static int rpmtsFinish(rpmts ts) |
1273 | { |
1274 | return rpmChrootSet(NULL((void*)0)); |
1275 | } |
1276 | |
1277 | static int rpmtsPrepare(rpmts ts) |
1278 | { |
1279 | tsMembers tsmem = rpmtsMembers(ts); |
1280 | rpmtsi pi; |
1281 | rpmte p; |
1282 | int rc = 0; |
1283 | uint64_t fileCount = countFiles(ts); |
1284 | const char *dbhome = NULL((void*)0); |
1285 | struct stat dbstat; |
1286 | |
1287 | fingerPrintCache fpc = fpCacheCreate(fileCount/2 + 10001, rpmtsPool(ts)); |
1288 | |
1289 | rpmlog(RPMLOG_DEBUG, "computing %" PRIu64"l" "u" " file fingerprints\n", fileCount); |
1290 | |
1291 | /* Reset actions, set skip for netshared paths and excluded files */ |
1292 | pi = rpmtsiInit(ts); |
1293 | while ((p = rpmtsiNext(pi, 0)) != NULL((void*)0)) { |
1294 | rpmfiles files = rpmteFiles(p); |
1295 | if (rpmfilesFC(files) > 0) { |
1296 | rpmfs fs = rpmteGetFileStates(p); |
1297 | /* Ensure clean state, this could get called more than once. */ |
1298 | rpmfsResetActions(fs); |
1299 | if (rpmteType(p) == TR_ADDED) { |
1300 | skipInstallFiles(ts, files, fs); |
1301 | } else { |
1302 | skipEraseFiles(ts, files, fs); |
1303 | } |
1304 | } |
1305 | rpmfilesFree(files); |
1306 | } |
1307 | rpmtsiFree(pi); |
1308 | |
1309 | /* Open rpmdb & enter chroot for fingerprinting if necessary */ |
1310 | if (rpmdbOpenAll(ts->rdb) || rpmChrootIn()) { |
1311 | rc = -1; |
1312 | goto exit; |
1313 | } |
1314 | |
1315 | rpmtsNotify(ts, NULL((void*)0), RPMCALLBACK_TRANS_START, 6, tsmem->orderCount); |
1316 | /* Add fingerprint for each file not skipped. */ |
1317 | fpCachePopulate(fpc, ts, fileCount); |
1318 | /* check against files in the rpmdb */ |
1319 | checkInstalledFiles(ts, fileCount, fpc); |
1320 | |
1321 | dbhome = rpmdbHome(rpmtsGetRdb(ts)); |
1322 | /* If we can't stat, ignore db growth. Probably not right but... */ |
1323 | if (dbhome && stat(dbhome, &dbstat)) |
1324 | dbhome = NULL((void*)0); |
1325 | |
1326 | pi = rpmtsiInit(ts); |
1327 | while ((p = rpmtsiNext(pi, 0)) != NULL((void*)0)) { |
1328 | rpmfiles files = rpmteFiles(p);; |
1329 | if (files == NULL((void*)0)) |
1330 | continue; /* XXX can't happen */ |
1331 | |
1332 | (void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_FINGERPRINT), 0); |
1333 | /* check files in ts against each other and update disk space |
1334 | needs on each partition for this package. */ |
1335 | handleOverlappedFiles(ts, fpc, p, files); |
1336 | |
1337 | /* Check added package has sufficient space on each partition used. */ |
1338 | if (rpmteType(p) == TR_ADDED) { |
1339 | /* |
1340 | * Try to estimate space needed for rpmdb growth: guess that the |
1341 | * db grows 4 times the header size (indexes and all). |
1342 | */ |
1343 | if (dbhome) { |
1344 | int64_t hsize = rpmteHeaderSize(p) * 4; |
1345 | rpmtsUpdateDSI(ts, dbstat.st_dev, dbhome, |
1346 | hsize, 0, 0, FA_CREATE); |
1347 | } |
1348 | |
1349 | rpmtsCheckDSIProblems(ts, p); |
1350 | } |
1351 | (void) rpmswExit(rpmtsOp(ts, RPMTS_OP_FINGERPRINT), 0); |
1352 | rpmfilesFree(files); |
1353 | } |
1354 | rpmtsiFree(pi); |
1355 | rpmtsNotify(ts, NULL((void*)0), RPMCALLBACK_TRANS_STOP, 6, tsmem->orderCount); |
1356 | |
1357 | /* return from chroot if done earlier */ |
1358 | if (rpmChrootOut()) |
1359 | rc = -1; |
1360 | |
1361 | /* On actual transaction, file info sets are not needed after this */ |
1362 | if (!(rpmtsFlags(ts) & (RPMTRANS_FLAG_TEST|RPMTRANS_FLAG_BUILD_PROBS))) { |
1363 | pi = rpmtsiInit(ts); |
1364 | while ((p = rpmtsiNext(pi, 0)) != NULL((void*)0)) { |
1365 | rpmteCleanFiles(p); |
1366 | } |
1367 | rpmtsiFree(pi); |
1368 | } |
1369 | |
1370 | exit: |
1371 | fpCacheFree(fpc); |
1372 | rpmtsFreeDSI(ts); |
1373 | return rc; |
1374 | } |
1375 | |
1376 | /* |
1377 | * Transaction main loop: install and remove packages |
1378 | */ |
1379 | static int rpmtsProcess(rpmts ts) |
1380 | { |
1381 | rpmtsi pi; rpmte p; |
1382 | int rc = 0; |
1383 | int i = 0; |
1384 | |
1385 | pi = rpmtsiInit(ts); |
1386 | while ((p = rpmtsiNext(pi, 0)) != NULL((void*)0)) { |
1387 | int failed; |
1388 | |
1389 | rpmlog(RPMLOG_DEBUG, "========== +++ %s %s-%s 0x%x\n", |
1390 | rpmteNEVR(p), rpmteA(p), rpmteO(p), rpmteColor(p)); |
1391 | |
1392 | failed = rpmteProcess(p, rpmteType(p), i++); |
1393 | if (failed) { |
1394 | rpmlog(RPMLOG_ERR, "%s: %s %s\n", rpmteNEVRA(p), |
1395 | rpmteTypeString(p), failed > 1 ? _("skipped")dcgettext ("rpm", "skipped", 5) : _("failed")dcgettext ("rpm", "failed", 5)); |
1396 | rc++; |
1397 | } |
1398 | } |
1399 | rpmtsiFree(pi); |
1400 | return rc; |
1401 | } |
1402 | |
1403 | rpmRC rpmtsSetupTransactionPlugins(rpmts ts) |
1404 | { |
1405 | rpmRC rc = RPMRC_OK; |
1406 | ARGV_t files = NULL((void*)0); |
1407 | int nfiles = 0; |
1408 | char *dsoPath = NULL((void*)0); |
1409 | |
1410 | /* |
1411 | * Assume allocated equals initialized. There are some oddball cases |
1412 | * (verification of non-installed package) where this is not true |
1413 | * currently but that's not a new issue. |
1414 | */ |
1415 | if ((rpmtsFlags(ts) & RPMTRANS_FLAG_NOPLUGINS) || ts->plugins != NULL((void*)0)) |
1416 | return RPMRC_OK; |
1417 | |
1418 | dsoPath = rpmExpand("%{__plugindir}/*.so", NULL((void*)0)); |
1419 | if (rpmGlob(dsoPath, &nfiles, &files) == 0) { |
1420 | rpmPlugins tsplugins = rpmtsPlugins(ts); |
1421 | for (int i = 0; i < nfiles; i++) { |
1422 | char *bn = basename__xpg_basename(files[i]); |
1423 | bn[strlen(bn)-strlen(".so")] = '\0'; |
1424 | if (rpmpluginsAddPlugin(tsplugins, "transaction", bn) == RPMRC_FAIL) |
1425 | rc = RPMRC_FAIL; |
1426 | } |
1427 | files = argvFree(files); |
1428 | } |
1429 | free(dsoPath); |
1430 | |
1431 | return rc; |
1432 | } |
1433 | /** |
1434 | * Run a scriptlet with args. |
1435 | * |
1436 | * Run a script with an interpreter. If the interpreter is not specified, |
1437 | * /bin/sh will be used. If the interpreter is /bin/sh, then the args from |
1438 | * the header will be ignored, passing instead arg1 and arg2. |
1439 | * |
1440 | * @param ts transaction set |
1441 | * @param te transaction element |
1442 | * @param prefixes install prefixes |
1443 | * @param script scriptlet from header |
1444 | * @param arg1 no. instances of package installed after scriptlet exec |
1445 | * (-1 is no arg) |
1446 | * @param arg2 ditto, but for the target package |
1447 | * @return 0 on success |
1448 | */ |
1449 | rpmRC runScript(rpmts ts, rpmte te, ARGV_const_t prefixes, |
1450 | rpmScript script, int arg1, int arg2) |
1451 | { |
1452 | rpmRC stoprc, rc = RPMRC_OK; |
1453 | rpmTagVal stag = rpmScriptTag(script); |
1454 | FD_t sfd = NULL((void*)0); |
1455 | int warn_only = (stag != RPMTAG_PREIN && |
1456 | stag != RPMTAG_PREUN && |
1457 | stag != RPMTAG_PRETRANS && |
1458 | stag != RPMTAG_VERIFYSCRIPT); |
1459 | |
1460 | sfd = rpmtsNotify(ts, te, RPMCALLBACK_SCRIPT_START, stag, 0); |
1461 | if (sfd == NULL((void*)0)) |
1462 | sfd = rpmtsScriptFd(ts); |
1463 | |
1464 | rpmswEnter(rpmtsOp(ts, RPMTS_OP_SCRIPTLETS), 0); |
1465 | rc = rpmScriptRun(script, arg1, arg2, sfd, |
1466 | prefixes, warn_only, rpmtsPlugins(ts)); |
1467 | rpmswExit(rpmtsOp(ts, RPMTS_OP_SCRIPTLETS), 0); |
1468 | |
1469 | /* Map warn-only errors to "notfound" for script stop callback */ |
1470 | stoprc = (rc != RPMRC_OK && warn_only) ? RPMRC_NOTFOUND : rc; |
1471 | rpmtsNotify(ts, te, RPMCALLBACK_SCRIPT_STOP, stag, stoprc); |
1472 | |
1473 | /* |
1474 | * Notify callback for all errors. "total" abused for warning/error, |
1475 | * rc only reflects whether the condition prevented install/erase |
1476 | * (which is only happens with %prein and %preun scriptlets) or not. |
1477 | */ |
1478 | if (rc != RPMRC_OK) { |
1479 | if (warn_only) { |
1480 | rc = RPMRC_OK; |
1481 | } |
1482 | rpmtsNotify(ts, te, RPMCALLBACK_SCRIPT_ERROR, stag, rc); |
1483 | } |
1484 | |
1485 | return rc; |
1486 | } |
1487 | |
1488 | int rpmtsRun(rpmts ts, rpmps okProbs, rpmprobFilterFlags ignoreSet) |
1489 | { |
1490 | int rc = -1; /* assume failure */ |
1491 | tsMembers tsmem = rpmtsMembers(ts); |
1492 | rpmtxn txn = NULL((void*)0); |
1493 | rpmps tsprobs = NULL((void*)0); |
1494 | int TsmPreDone = 0; /* TsmPre hook hasn't been called */ |
1495 | /* Ignore SIGPIPE for the duration of transaction */ |
1496 | rpmsqAction_t oact = rpmsqSetAction(SIGPIPE13, RPMSQ_IGN((rpmsqAction_t)1)); |
1497 | |
1498 | /* Force default 022 umask during transaction for consistent results */ |
1499 | mode_t oldmask = umask(022); |
1500 | |
1501 | /* Empty transaction, nothing to do */ |
1502 | if (rpmtsNElements(ts) <= 0) { |
1503 | rc = 0; |
1504 | goto exit; |
1505 | } |
1506 | |
1507 | /* If we are in test mode, then there's no need for transaction lock. */ |
1508 | if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)) { |
1509 | if (!(txn = rpmtxnBegin(ts, RPMTXN_WRITE))) { |
1510 | goto exit; |
1511 | } |
1512 | } |
1513 | |
1514 | /* Setup flags and such, open the DB */ |
1515 | if (rpmtsSetup(ts, ignoreSet)) { |
1516 | goto exit; |
1517 | } |
1518 | |
1519 | /* Check package set for problems */ |
1520 | tsprobs = checkProblems(ts); |
1521 | |
1522 | /* Run pre transaction hook for all plugins */ |
1523 | TsmPreDone = 1; |
1524 | if (rpmpluginsCallTsmPre(rpmtsPlugins(ts), ts) == RPMRC_FAIL) { |
1525 | goto exit; |
1526 | } |
1527 | |
1528 | if (!(rpmtsFlags(ts) & (RPMTRANS_FLAG_BUILD_PROBS|RPMTRANS_FLAG_NOPRETRANS| |
1529 | RPMTRANS_FLAG_NOTRIGGERUN) || rpmpsNumProblems(tsprobs))) { |
1530 | |
1531 | /* Run file triggers in this package other package(s) set off. */ |
1532 | runFileTriggers(ts, NULL((void*)0), RPMSENSE_TRIGGERUN, |
1533 | RPMSCRIPT_TRANSFILETRIGGER, 0); |
1534 | /* Run file triggers in other package(s) this package sets off. */ |
1535 | runTransScripts(ts, PKG_TRANSFILETRIGGERUN); |
1536 | } |
1537 | |
1538 | /* Run pre-transaction scripts, but only if there are no known |
1539 | * problems up to this point and not disabled otherwise. */ |
1540 | if (!((rpmtsFlags(ts) & (RPMTRANS_FLAG_BUILD_PROBS|RPMTRANS_FLAG_NOPRETRANS)) |
1541 | || (rpmpsNumProblems(tsprobs)))) { |
1542 | rpmlog(RPMLOG_DEBUG, "running pre-transaction scripts\n"); |
1543 | runTransScripts(ts, PKG_PRETRANS); |
1544 | } |
1545 | tsprobs = rpmpsFree(tsprobs); |
1546 | |
1547 | /* Compute file disposition for each package in transaction set. */ |
1548 | if (rpmtsPrepare(ts)) { |
1549 | goto exit; |
1550 | } |
1551 | /* Check again for problems (now including file conflicts, duh */ |
1552 | tsprobs = rpmtsProblems(ts); |
1553 | |
1554 | /* If unfiltered problems exist, free memory and return. */ |
1555 | if ((rpmtsFlags(ts) & RPMTRANS_FLAG_BUILD_PROBS) || (rpmpsNumProblems(tsprobs))) { |
1556 | rc = tsmem->orderCount; |
1557 | goto exit; |
1558 | } |
1559 | |
1560 | /* Free up memory taken by problem sets */ |
1561 | tsprobs = rpmpsFree(tsprobs); |
1562 | rpmtsCleanProblems(ts); |
1563 | |
1564 | /* |
1565 | * Free up the global string pool unless we expect it to be needed |
1566 | * again. During the transaction, private pools will be used for |
1567 | * rpmfi's etc. |
1568 | */ |
1569 | if (!(rpmtsFlags(ts) & (RPMTRANS_FLAG_TEST|RPMTRANS_FLAG_BUILD_PROBS))) |
1570 | tsmem->pool = rpmstrPoolFree(tsmem->pool); |
1571 | |
1572 | |
1573 | /* Actually install and remove packages, get final exit code */ |
1574 | rc = rpmtsProcess(ts) ? -1 : 0; |
1575 | |
1576 | /* Run post-transaction scripts unless disabled */ |
1577 | if (!(rpmtsFlags(ts) & (RPMTRANS_FLAG_NOPOSTTRANS))) { |
1578 | rpmlog(RPMLOG_DEBUG, "running post-transaction scripts\n"); |
1579 | runTransScripts(ts, PKG_POSTTRANS); |
1580 | } |
1581 | |
1582 | /* Run file triggers in other package(s) this package sets off. */ |
1583 | if (!(rpmtsFlags(ts) & (RPMTRANS_FLAG_NOPOSTTRANS|RPMTRANS_FLAG_NOTRIGGERIN))) { |
1584 | runFileTriggers(ts, NULL((void*)0), RPMSENSE_TRIGGERIN, RPMSCRIPT_TRANSFILETRIGGER, 0); |
1585 | } |
1586 | if (!(rpmtsFlags(ts) & (RPMTRANS_FLAG_NOPOSTTRANS|RPMTRANS_FLAG_NOTRIGGERPOSTUN))) { |
1587 | runPostUnTransFileTrigs(ts); |
1588 | } |
1589 | |
1590 | /* Run file triggers in this package other package(s) set off. */ |
1591 | if (!(rpmtsFlags(ts) & (RPMTRANS_FLAG_NOPOSTTRANS|RPMTRANS_FLAG_NOTRIGGERIN))) { |
1592 | runTransScripts(ts, PKG_TRANSFILETRIGGERIN); |
1593 | } |
1594 | exit: |
1595 | /* Run post transaction hook for all plugins */ |
1596 | if (TsmPreDone) /* If TsmPre hook has been called, call the TsmPost hook */ |
1597 | rpmpluginsCallTsmPost(rpmtsPlugins(ts), ts, rc); |
1598 | |
1599 | /* Finish up... */ |
1600 | (void) umask(oldmask); |
1601 | (void) rpmtsFinish(ts); |
1602 | rpmpsFree(tsprobs); |
1603 | rpmtxnEnd(txn); |
1604 | /* Restore SIGPIPE *after* unblocking signals in rpmtxnEnd() */ |
1605 | rpmsqSetAction(SIGPIPE13, oact); |
1606 | return rc; |
1607 | } |