| File: | lib/rpminstall.c |
| Warning: | line 445, column 6 Value stored to 'fn' is never read |
| 1 | /** \ingroup rpmcli |
| 2 | * \file lib/rpminstall.c |
| 3 | */ |
| 4 | |
| 5 | #include "system.h" |
| 6 | |
| 7 | #include <rpm/rpmcli.h> |
| 8 | #include <rpm/rpmtag.h> |
| 9 | #include <rpm/rpmlib.h> /* rpmReadPackageFile, vercmp etc */ |
| 10 | #include <rpm/rpmdb.h> |
| 11 | #include <rpm/rpmds.h> |
| 12 | #include <rpm/rpmts.h> |
| 13 | #include <rpm/rpmsq.h> |
| 14 | #include <rpm/rpmlog.h> |
| 15 | #include <rpm/rpmfileutil.h> |
| 16 | |
| 17 | #include "lib/rpmgi.h" |
| 18 | #include "lib/manifest.h" |
| 19 | #include "debug.h" |
| 20 | |
| 21 | static int rpmcliPackagesTotal = 0; |
| 22 | static int rpmcliHashesCurrent = 0; |
| 23 | static int rpmcliHashesTotal = 0; |
| 24 | static int rpmcliProgressCurrent = 0; |
| 25 | static int rpmcliProgressTotal = 0; |
| 26 | static int rpmcliProgressState = 0; |
| 27 | |
| 28 | /** |
| 29 | * Print a CLI progress bar. |
| 30 | * @todo Unsnarl isatty(STDOUT_FILENO) from the control flow. |
| 31 | * @param amount current |
| 32 | * @param total final |
| 33 | */ |
| 34 | static void printHash(const rpm_loff_t amount, const rpm_loff_t total) |
| 35 | { |
| 36 | int hashesNeeded; |
| 37 | |
| 38 | rpmcliHashesTotal = (isatty (STDOUT_FILENO1) ? 34 : 40); |
| 39 | |
| 40 | if (rpmcliHashesCurrent != rpmcliHashesTotal) { |
| 41 | float pct = (total ? (((float) amount) / total) : 1.0); |
| 42 | hashesNeeded = (rpmcliHashesTotal * pct) + 0.5; |
| 43 | while (hashesNeeded > rpmcliHashesCurrent) { |
| 44 | if (isatty (STDOUT_FILENO1)) { |
| 45 | int i; |
| 46 | for (i = 0; i < rpmcliHashesCurrent; i++) |
| 47 | (void) putchar ('#'); |
| 48 | for (; i < rpmcliHashesTotal; i++) |
| 49 | (void) putchar (' '); |
| 50 | fprintf(stdoutstdout, "(%3d%%)", (int)((100 * pct) + 0.5)); |
| 51 | for (i = 0; i < (rpmcliHashesTotal + 6); i++) |
| 52 | (void) putchar ('\b'); |
| 53 | } else |
| 54 | fprintf(stdoutstdout, "#"); |
| 55 | |
| 56 | rpmcliHashesCurrent++; |
| 57 | } |
| 58 | (void) fflush(stdoutstdout); |
| 59 | |
| 60 | if (rpmcliHashesCurrent == rpmcliHashesTotal) { |
| 61 | int i; |
| 62 | rpmcliProgressCurrent++; |
| 63 | if (isatty(STDOUT_FILENO1)) { |
| 64 | for (i = 1; i < rpmcliHashesCurrent; i++) |
| 65 | (void) putchar ('#'); |
| 66 | pct = (rpmcliProgressTotal |
| 67 | ? (((float) rpmcliProgressCurrent) / rpmcliProgressTotal) |
| 68 | : 1); |
| 69 | fprintf(stdoutstdout, " [%3d%%]", (int)((100 * pct) + 0.5)); |
| 70 | } |
| 71 | fprintf(stdoutstdout, "\n"); |
| 72 | } |
| 73 | (void) fflush(stdoutstdout); |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | static rpmVSFlags setvsFlags(struct rpmInstallArguments_s * ia) |
| 78 | { |
| 79 | rpmVSFlags vsflags; |
| 80 | |
| 81 | if (ia->installInterfaceFlags & (INSTALL_UPGRADE | INSTALL_ERASE)) |
| 82 | vsflags = rpmExpandNumeric("%{?_vsflags_erase}"); |
| 83 | else |
| 84 | vsflags = rpmExpandNumeric("%{?_vsflags_install}"); |
| 85 | |
| 86 | if (rpmcliQueryFlags & VERIFY_DIGEST) |
| 87 | vsflags |= _RPMVSF_NODIGESTS( RPMVSF_NOSHA1HEADER | RPMVSF_NOSHA256HEADER | RPMVSF_NOPAYLOAD | RPMVSF_NOMD5 ); |
| 88 | if (rpmcliQueryFlags & VERIFY_SIGNATURE) |
| 89 | vsflags |= _RPMVSF_NOSIGNATURES( RPMVSF_NODSAHEADER | RPMVSF_NORSAHEADER | RPMVSF_NODSA | RPMVSF_NORSA ); |
| 90 | if (rpmcliQueryFlags & VERIFY_HDRCHK) |
| 91 | vsflags |= RPMVSF_NOHDRCHK; |
| 92 | |
| 93 | return vsflags; |
| 94 | } |
| 95 | |
| 96 | void * rpmShowProgress(const void * arg, |
| 97 | const rpmCallbackType what, |
| 98 | const rpm_loff_t amount, |
| 99 | const rpm_loff_t total, |
| 100 | fnpyKey key, |
| 101 | void * data) |
| 102 | { |
| 103 | Header h = (Header) arg; |
| 104 | int flags = (int) ((long)data); |
| 105 | void * rc = NULL((void*)0); |
| 106 | const char * filename = (const char *)key; |
| 107 | static FD_t fd = NULL((void*)0); |
| 108 | |
| 109 | switch (what) { |
| 110 | case RPMCALLBACK_INST_OPEN_FILE: |
| 111 | if (filename == NULL((void*)0) || filename[0] == '\0') |
| 112 | return NULL((void*)0); |
| 113 | fd = Fopen(filename, "r.ufdio"); |
| 114 | /* FIX: still necessary? */ |
| 115 | if (fd == NULL((void*)0) || Ferror(fd)) { |
| 116 | rpmlog(RPMLOG_ERR, _("open of %s failed: %s\n")dcgettext ("rpm", "open of %s failed: %s\n", 5), filename, |
| 117 | Fstrerror(fd)); |
| 118 | if (fd != NULL((void*)0)) { |
| 119 | Fclose(fd); |
| 120 | fd = NULL((void*)0); |
| 121 | } |
| 122 | } else |
| 123 | fd = fdLink(fd); |
| 124 | return (void *)fd; |
| 125 | break; |
| 126 | |
| 127 | case RPMCALLBACK_INST_CLOSE_FILE: |
| 128 | /* FIX: still necessary? */ |
| 129 | fd = fdFree(fd); |
| 130 | if (fd != NULL((void*)0)) { |
| 131 | Fclose(fd); |
| 132 | fd = NULL((void*)0); |
| 133 | } |
| 134 | break; |
| 135 | |
| 136 | case RPMCALLBACK_INST_START: |
| 137 | case RPMCALLBACK_UNINST_START: |
| 138 | if (rpmcliProgressState != what) { |
| 139 | rpmcliProgressState = what; |
| 140 | if (flags & INSTALL_HASH) { |
| 141 | if (what == RPMCALLBACK_INST_START) { |
| 142 | fprintf(stdoutstdout, _("Updating / installing...\n")dcgettext ("rpm", "Updating / installing...\n", 5)); |
| 143 | } else { |
| 144 | fprintf(stdoutstdout, _("Cleaning up / removing...\n")dcgettext ("rpm", "Cleaning up / removing...\n", 5)); |
| 145 | } |
| 146 | fflush(stdoutstdout); |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | rpmcliHashesCurrent = 0; |
| 151 | if (h == NULL((void*)0) || !(flags & INSTALL_LABEL)) |
| 152 | break; |
| 153 | if (flags & INSTALL_HASH) { |
| 154 | char *s = headerGetAsString(h, RPMTAG_NEVR); |
| 155 | if (isatty (STDOUT_FILENO1)) |
| 156 | fprintf(stdoutstdout, "%4d:%-33.33s", rpmcliProgressCurrent + 1, s); |
| 157 | else |
| 158 | fprintf(stdoutstdout, "%-38.38s", s); |
| 159 | (void) fflush(stdoutstdout); |
| 160 | free(s); |
| 161 | } else { |
| 162 | char *s = headerGetAsString(h, RPMTAG_NEVRA); |
| 163 | fprintf(stdoutstdout, "%s\n", s); |
| 164 | (void) fflush(stdoutstdout); |
| 165 | free(s); |
| 166 | } |
| 167 | break; |
| 168 | |
| 169 | case RPMCALLBACK_INST_STOP: |
| 170 | break; |
| 171 | |
| 172 | case RPMCALLBACK_TRANS_PROGRESS: |
| 173 | case RPMCALLBACK_INST_PROGRESS: |
| 174 | case RPMCALLBACK_UNINST_PROGRESS: |
| 175 | if (flags & INSTALL_PERCENT) |
| 176 | fprintf(stdoutstdout, "%%%% %f\n", (double) (total |
| 177 | ? ((((float) amount) / total) * 100) |
| 178 | : 100.0)); |
| 179 | else if (flags & INSTALL_HASH) |
| 180 | printHash(amount, total); |
| 181 | (void) fflush(stdoutstdout); |
| 182 | break; |
| 183 | |
| 184 | case RPMCALLBACK_TRANS_START: |
| 185 | rpmcliHashesCurrent = 0; |
| 186 | rpmcliProgressTotal = 1; |
| 187 | rpmcliProgressCurrent = 0; |
| 188 | rpmcliPackagesTotal = total; |
| 189 | rpmcliProgressState = what; |
| 190 | if (!(flags & INSTALL_LABEL)) |
| 191 | break; |
| 192 | if (flags & INSTALL_HASH) |
| 193 | fprintf(stdoutstdout, "%-38s", _("Preparing...")dcgettext ("rpm", "Preparing...", 5)); |
| 194 | else |
| 195 | fprintf(stdoutstdout, "%s\n", _("Preparing packages...")dcgettext ("rpm", "Preparing packages...", 5)); |
| 196 | (void) fflush(stdoutstdout); |
| 197 | break; |
| 198 | |
| 199 | case RPMCALLBACK_TRANS_STOP: |
| 200 | if (flags & INSTALL_HASH) |
| 201 | printHash(1, 1); /* Fixes "preparing..." progress bar */ |
| 202 | rpmcliProgressTotal = rpmcliPackagesTotal; |
| 203 | rpmcliProgressCurrent = 0; |
| 204 | break; |
| 205 | |
| 206 | case RPMCALLBACK_UNINST_STOP: |
| 207 | break; |
| 208 | case RPMCALLBACK_UNPACK_ERROR: |
| 209 | break; |
| 210 | case RPMCALLBACK_CPIO_ERROR: |
| 211 | break; |
| 212 | case RPMCALLBACK_SCRIPT_ERROR: |
| 213 | break; |
| 214 | case RPMCALLBACK_SCRIPT_START: |
| 215 | break; |
| 216 | case RPMCALLBACK_SCRIPT_STOP: |
| 217 | break; |
| 218 | case RPMCALLBACK_UNKNOWN: |
| 219 | default: |
| 220 | break; |
| 221 | } |
| 222 | |
| 223 | return rc; |
| 224 | } |
| 225 | |
| 226 | static void setNotifyFlag(struct rpmInstallArguments_s * ia, |
| 227 | rpmts ts) |
| 228 | { |
| 229 | int notifyFlags; |
| 230 | |
| 231 | notifyFlags = ia->installInterfaceFlags | (rpmIsVerbose()(rpmlogSetMask(0) >= (1 << ((unsigned)(RPMLOG_INFO)) )) ? INSTALL_LABEL : 0 ); |
| 232 | rpmtsSetNotifyCallback(ts, rpmShowProgress, (void *) ((long)notifyFlags)); |
| 233 | } |
| 234 | |
| 235 | struct rpmEIU { |
| 236 | int numFailed; |
| 237 | int numPkgs; |
| 238 | char ** pkgURL; |
| 239 | char ** fnp; |
| 240 | char * pkgState; |
| 241 | int prevx; |
| 242 | int pkgx; |
| 243 | int numRPMS; |
| 244 | int numSRPMS; |
| 245 | char ** sourceURL; |
| 246 | int argc; |
| 247 | char ** argv; |
| 248 | rpmRelocation * relocations; |
| 249 | rpmRC rpmrc; |
| 250 | }; |
| 251 | |
| 252 | static int rpmcliTransaction(rpmts ts, struct rpmInstallArguments_s * ia, |
| 253 | int numPackages) |
| 254 | { |
| 255 | rpmps ps; |
| 256 | |
| 257 | int rc = 0; |
| 258 | int stop = 0; |
| 259 | |
| 260 | int eflags = ia->installInterfaceFlags & INSTALL_ERASE; |
| 261 | |
| 262 | if (!(ia->installInterfaceFlags & INSTALL_NODEPS)) { |
| 263 | |
| 264 | if (rpmtsCheck(ts)) { |
| 265 | rc = numPackages; |
| 266 | stop = 1; |
| 267 | } |
| 268 | |
| 269 | ps = rpmtsProblems(ts); |
| 270 | if (!stop && rpmpsNumProblems(ps) > 0) { |
| 271 | rpmlog(RPMLOG_ERR, _("Failed dependencies:\n")dcgettext ("rpm", "Failed dependencies:\n", 5)); |
| 272 | rpmpsPrint(NULL((void*)0), ps); |
| 273 | rc = numPackages; |
| 274 | stop = 1; |
| 275 | } |
| 276 | ps = rpmpsFree(ps); |
| 277 | } |
| 278 | |
| 279 | if (!stop && !(ia->installInterfaceFlags & INSTALL_NOORDER)) { |
| 280 | if (rpmtsOrder(ts)) { |
| 281 | rc = numPackages; |
| 282 | stop = 1; |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | if (numPackages && !stop) { |
| 287 | rpmlog(RPMLOG_DEBUG, eflags ? "erasing packages\n" : |
| 288 | "installing binary packages\n"); |
| 289 | rpmtsClean(ts); |
| 290 | rc = rpmtsRun(ts, NULL((void*)0), ia->probFilter); |
| 291 | |
| 292 | ps = rpmtsProblems(ts); |
| 293 | |
| 294 | if (rpmpsNumProblems(ps) > 0 && (eflags || rc > 0)) |
| 295 | rpmpsPrint(NULL((void*)0), ps); |
| 296 | ps = rpmpsFree(ps); |
| 297 | } |
| 298 | |
| 299 | return rc; |
| 300 | } |
| 301 | |
| 302 | static int tryReadManifest(struct rpmEIU * eiu) |
| 303 | { |
| 304 | int rc; |
| 305 | |
| 306 | /* Try to read a package manifest. */ |
| 307 | FD_t fd = Fopen(*eiu->fnp, "r.ufdio"); |
| 308 | if (fd == NULL((void*)0) || Ferror(fd)) { |
| 309 | rpmlog(RPMLOG_ERR, _("open of %s failed: %s\n")dcgettext ("rpm", "open of %s failed: %s\n", 5), *eiu->fnp, |
| 310 | Fstrerror(fd)); |
| 311 | if (fd != NULL((void*)0)) { |
| 312 | Fclose(fd); |
| 313 | fd = NULL((void*)0); |
| 314 | } |
| 315 | eiu->numFailed++; |
| 316 | *eiu->fnp = NULL((void*)0); |
| 317 | return RPMRC_FAIL; |
| 318 | } |
| 319 | |
| 320 | /* Read list of packages from manifest. */ |
| 321 | rc = rpmReadPackageManifest(fd, &eiu->argc, &eiu->argv); |
| 322 | if (rc != RPMRC_OK) |
| 323 | rpmlog(RPMLOG_ERR, _("%s: not an rpm package (or package manifest): %s\n")dcgettext ("rpm", "%s: not an rpm package (or package manifest): %s\n" , 5), |
| 324 | *eiu->fnp, Fstrerror(fd)); |
| 325 | Fclose(fd); |
| 326 | fd = NULL((void*)0); |
| 327 | |
| 328 | if (rc != RPMRC_OK) { |
| 329 | eiu->numFailed++; |
| 330 | *eiu->fnp = NULL((void*)0); |
| 331 | } |
| 332 | |
| 333 | return rc; |
| 334 | } |
| 335 | |
| 336 | static int tryReadHeader(rpmts ts, struct rpmEIU * eiu, Header * hdrp) |
| 337 | { |
| 338 | /* Try to read the header from a package file. */ |
| 339 | FD_t fd = Fopen(*eiu->fnp, "r.ufdio"); |
| 340 | if (fd == NULL((void*)0) || Ferror(fd)) { |
| 341 | rpmlog(RPMLOG_ERR, _("open of %s failed: %s\n")dcgettext ("rpm", "open of %s failed: %s\n", 5), *eiu->fnp, |
| 342 | Fstrerror(fd)); |
| 343 | if (fd != NULL((void*)0)) { |
| 344 | Fclose(fd); |
| 345 | fd = NULL((void*)0); |
| 346 | } |
| 347 | eiu->numFailed++; |
| 348 | *eiu->fnp = NULL((void*)0); |
| 349 | return RPMRC_FAIL; |
| 350 | } |
| 351 | |
| 352 | /* Read the header, verifying signatures (if present). */ |
| 353 | eiu->rpmrc = rpmReadPackageFile(ts, fd, *eiu->fnp, hdrp); |
| 354 | Fclose(fd); |
| 355 | fd = NULL((void*)0); |
| 356 | |
| 357 | /* Honor --nomanifest */ |
| 358 | if (eiu->rpmrc == RPMRC_NOTFOUND && (giFlags & RPMGI_NOMANIFEST)) |
| 359 | eiu->rpmrc = RPMRC_FAIL; |
| 360 | |
| 361 | if (eiu->rpmrc == RPMRC_FAIL) { |
| 362 | rpmlog(RPMLOG_ERR, _("%s cannot be installed\n")dcgettext ("rpm", "%s cannot be installed\n", 5), *eiu->fnp); |
| 363 | eiu->numFailed++; |
| 364 | *eiu->fnp = NULL((void*)0); |
| 365 | } |
| 366 | |
| 367 | return RPMRC_OK; |
| 368 | } |
| 369 | |
| 370 | |
| 371 | /* On --freshen, verify package is installed and newer */ |
| 372 | static int checkFreshenStatus(rpmts ts, Header h) |
| 373 | { |
| 374 | rpmdbMatchIterator mi = NULL((void*)0); |
| 375 | const char * name = headerGetString(h, RPMTAG_NAME); |
| 376 | const char *arch = headerGetString(h, RPMTAG_ARCH); |
| 377 | Header oldH = NULL((void*)0); |
| 378 | |
| 379 | if (name != NULL((void*)0)) |
| 380 | mi = rpmtsInitIterator(ts, RPMDBI_NAME, name, 0); |
| 381 | if (rpmtsColor(ts) && arch) |
| 382 | rpmdbSetIteratorRE(mi, RPMTAG_ARCH, RPMMIRE_DEFAULT, arch); |
| 383 | |
| 384 | while ((oldH = rpmdbNextIterator(mi)) != NULL((void*)0)) { |
| 385 | /* Package is newer than those currently installed. */ |
| 386 | if (rpmVersionCompare(oldH, h) < 0) |
| 387 | break; |
| 388 | } |
| 389 | |
| 390 | rpmdbFreeIterator(mi); |
| 391 | return (oldH != NULL((void*)0)); |
| 392 | } |
| 393 | |
| 394 | static int rpmNoGlob(const char *fn, int *argcPtr, ARGV_t * argvPtr) |
| 395 | { |
| 396 | struct stat sb; |
| 397 | int rc = stat(fn, &sb); |
| 398 | if (rc == 0) { |
| 399 | argvAdd(argvPtr, fn); |
| 400 | *argcPtr = 1; |
| 401 | } else { |
| 402 | *argcPtr = 0; |
| 403 | } |
| 404 | return rc; |
| 405 | } |
| 406 | |
| 407 | /** @todo Generalize --freshen policies. */ |
| 408 | int rpmInstall(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_t fileArgv) |
| 409 | { |
| 410 | struct rpmEIU * eiu = xcalloc(1, sizeof(*eiu))rcalloc((1), (sizeof(*eiu))); |
| 411 | rpmRelocation * relocations; |
| 412 | char * fileURL = NULL((void*)0); |
| 413 | rpmVSFlags vsflags, ovsflags; |
| 414 | int rc; |
| 415 | int i; |
| 416 | |
| 417 | vsflags = setvsFlags(ia); |
| 418 | ovsflags = rpmtsSetVSFlags(ts, (vsflags | RPMVSF_NEEDPAYLOAD)); |
| 419 | |
| 420 | if (fileArgv == NULL((void*)0)) goto exit; |
| 421 | |
| 422 | (void) rpmtsSetFlags(ts, ia->transFlags); |
| 423 | |
| 424 | relocations = ia->relocations; |
| 425 | |
| 426 | setNotifyFlag(ia, ts); |
| 427 | |
| 428 | if ((eiu->relocations = relocations) != NULL((void*)0)) { |
| 429 | while (eiu->relocations->oldPath) |
| 430 | eiu->relocations++; |
| 431 | if (eiu->relocations->newPath == NULL((void*)0)) |
| 432 | eiu->relocations = NULL((void*)0); |
| 433 | } |
| 434 | |
| 435 | /* Build fully globbed list of arguments in argv[argc]. */ |
| 436 | for (eiu->fnp = fileArgv; *eiu->fnp != NULL((void*)0); eiu->fnp++) { |
| 437 | ARGV_t av = NULL((void*)0); |
| 438 | int ac = 0; |
| 439 | |
| 440 | if (giFlags & RPMGI_NOGLOB) { |
| 441 | rc = rpmNoGlob(*eiu->fnp, &ac, &av); |
| 442 | } else { |
| 443 | char * fn = rpmEscapeSpaces(*eiu->fnp); |
| 444 | rc = rpmGlob(fn, &ac, &av); |
| 445 | fn = _free(fn)rfree((fn)); |
Value stored to 'fn' is never read | |
| 446 | } |
| 447 | if (rc || ac == 0) { |
| 448 | if (giFlags & RPMGI_NOGLOB) { |
| 449 | rpmlog(RPMLOG_ERR, _("File not found: %s\n")dcgettext ("rpm", "File not found: %s\n", 5), *eiu->fnp); |
| 450 | } else { |
| 451 | rpmlog(RPMLOG_ERR, _("File not found by glob: %s\n")dcgettext ("rpm", "File not found by glob: %s\n", 5), *eiu->fnp); |
| 452 | } |
| 453 | eiu->numFailed++; |
| 454 | continue; |
| 455 | } |
| 456 | |
| 457 | argvAppend(&(eiu->argv), av); |
| 458 | argvFree(av); |
| 459 | eiu->argc += ac; |
| 460 | } |
| 461 | |
| 462 | restart: |
| 463 | /* Allocate sufficient storage for next set of args. */ |
| 464 | if (eiu->pkgx >= eiu->numPkgs) { |
| 465 | eiu->numPkgs = eiu->pkgx + eiu->argc; |
| 466 | eiu->pkgURL = xrealloc(eiu->pkgURL,rrealloc((eiu->pkgURL), ((eiu->numPkgs + 1) * sizeof(*eiu ->pkgURL))) |
| 467 | (eiu->numPkgs + 1) * sizeof(*eiu->pkgURL))rrealloc((eiu->pkgURL), ((eiu->numPkgs + 1) * sizeof(*eiu ->pkgURL))); |
| 468 | memset(eiu->pkgURL + eiu->pkgx, 0, |
| 469 | ((eiu->argc + 1) * sizeof(*eiu->pkgURL))); |
| 470 | eiu->pkgState = xrealloc(eiu->pkgState,rrealloc((eiu->pkgState), ((eiu->numPkgs + 1) * sizeof( *eiu->pkgState))) |
| 471 | (eiu->numPkgs + 1) * sizeof(*eiu->pkgState))rrealloc((eiu->pkgState), ((eiu->numPkgs + 1) * sizeof( *eiu->pkgState))); |
| 472 | memset(eiu->pkgState + eiu->pkgx, 0, |
| 473 | ((eiu->argc + 1) * sizeof(*eiu->pkgState))); |
| 474 | } |
| 475 | |
| 476 | /* Retrieve next set of args, cache on local storage. */ |
| 477 | for (i = 0; i < eiu->argc; i++) { |
| 478 | fileURL = _free(fileURL)rfree((fileURL)); |
| 479 | fileURL = eiu->argv[i]; |
| 480 | eiu->argv[i] = NULL((void*)0); |
| 481 | |
| 482 | switch (urlIsURL(fileURL)) { |
| 483 | case URL_IS_HTTPS: |
| 484 | case URL_IS_HTTP: |
| 485 | case URL_IS_FTP: |
| 486 | { char *tfn = NULL((void*)0); |
| 487 | FD_t tfd; |
| 488 | |
| 489 | if (rpmIsVerbose()(rpmlogSetMask(0) >= (1 << ((unsigned)(RPMLOG_INFO)) ))) |
| 490 | fprintf(stdoutstdout, _("Retrieving %s\n")dcgettext ("rpm", "Retrieving %s\n", 5), fileURL); |
| 491 | |
| 492 | tfd = rpmMkTempFile(rpmtsRootDir(ts), &tfn); |
| 493 | if (tfd && tfn) { |
| 494 | Fclose(tfd); |
| 495 | rc = urlGetFile(fileURL, tfn); |
| 496 | } else { |
| 497 | rc = -1; |
| 498 | } |
| 499 | |
| 500 | if (rc != 0) { |
| 501 | rpmlog(RPMLOG_ERR, |
| 502 | _("skipping %s - transfer failed\n")dcgettext ("rpm", "skipping %s - transfer failed\n", 5), fileURL); |
| 503 | eiu->numFailed++; |
| 504 | eiu->pkgURL[eiu->pkgx] = NULL((void*)0); |
| 505 | tfn = _free(tfn)rfree((tfn)); |
| 506 | break; |
| 507 | } |
| 508 | eiu->pkgState[eiu->pkgx] = 1; |
| 509 | eiu->pkgURL[eiu->pkgx] = tfn; |
| 510 | eiu->pkgx++; |
| 511 | } break; |
| 512 | case URL_IS_PATH: |
| 513 | case URL_IS_DASH: /* WRONG WRONG WRONG */ |
| 514 | case URL_IS_HKP: /* WRONG WRONG WRONG */ |
| 515 | default: |
| 516 | eiu->pkgURL[eiu->pkgx] = fileURL; |
| 517 | fileURL = NULL((void*)0); |
| 518 | eiu->pkgx++; |
| 519 | break; |
| 520 | } |
| 521 | } |
| 522 | fileURL = _free(fileURL)rfree((fileURL)); |
| 523 | |
| 524 | if (eiu->numFailed) goto exit; |
| 525 | |
| 526 | /* Continue processing file arguments, building transaction set. */ |
| 527 | for (eiu->fnp = eiu->pkgURL+eiu->prevx; |
| 528 | *eiu->fnp != NULL((void*)0); |
| 529 | eiu->fnp++, eiu->prevx++) |
| 530 | { |
| 531 | Header h = NULL((void*)0); |
| 532 | const char * fileName; |
| 533 | |
| 534 | rpmlog(RPMLOG_DEBUG, "============== %s\n", *eiu->fnp); |
| 535 | (void) urlPath(*eiu->fnp, &fileName); |
| 536 | |
| 537 | if (tryReadHeader(ts, eiu, &h) == RPMRC_FAIL) |
| 538 | continue; |
| 539 | |
| 540 | if (eiu->rpmrc == RPMRC_NOTFOUND) { |
| 541 | rc = tryReadManifest(eiu); |
| 542 | if (rc == RPMRC_OK) { |
| 543 | eiu->prevx++; |
| 544 | goto restart; |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | if (headerIsSource(h)) { |
| 549 | if (ia->installInterfaceFlags & INSTALL_FRESHEN) { |
| 550 | headerFree(h); |
| 551 | continue; |
| 552 | } |
| 553 | rpmlog(RPMLOG_DEBUG, "\tadded source package [%d]\n", |
| 554 | eiu->numSRPMS); |
| 555 | eiu->sourceURL = xrealloc(eiu->sourceURL,rrealloc((eiu->sourceURL), ((eiu->numSRPMS + 2) * sizeof (*eiu->sourceURL))) |
| 556 | (eiu->numSRPMS + 2) * sizeof(*eiu->sourceURL))rrealloc((eiu->sourceURL), ((eiu->numSRPMS + 2) * sizeof (*eiu->sourceURL))); |
| 557 | eiu->sourceURL[eiu->numSRPMS] = *eiu->fnp; |
| 558 | *eiu->fnp = NULL((void*)0); |
| 559 | eiu->numSRPMS++; |
| 560 | eiu->sourceURL[eiu->numSRPMS] = NULL((void*)0); |
| 561 | continue; |
| 562 | } |
| 563 | |
| 564 | if (eiu->relocations) { |
| 565 | struct rpmtd_s prefixes; |
| 566 | |
| 567 | headerGet(h, RPMTAG_PREFIXES, &prefixes, HEADERGET_DEFAULT); |
| 568 | if (rpmtdCount(&prefixes) == 1) { |
| 569 | eiu->relocations->oldPath = xstrdup(rpmtdGetString(&prefixes))rstrdup((rpmtdGetString(&prefixes))); |
| 570 | rpmtdFreeData(&prefixes); |
| 571 | } else { |
| 572 | rpmlog(RPMLOG_ERR, _("package %s is not relocatable\n")dcgettext ("rpm", "package %s is not relocatable\n", 5), |
| 573 | headerGetString(h, RPMTAG_NAME)); |
| 574 | eiu->numFailed++; |
| 575 | goto exit; |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | if (ia->installInterfaceFlags & INSTALL_FRESHEN) |
| 580 | if (checkFreshenStatus(ts, h) != 1) { |
| 581 | headerFree(h); |
| 582 | continue; |
| 583 | } |
| 584 | |
| 585 | if (ia->installInterfaceFlags & INSTALL_REINSTALL) |
| 586 | rc = rpmtsAddReinstallElement(ts, h, (fnpyKey)fileName); |
| 587 | else |
| 588 | rc = rpmtsAddInstallElement(ts, h, (fnpyKey)fileName, |
| 589 | (ia->installInterfaceFlags & INSTALL_UPGRADE) != 0, |
| 590 | relocations); |
| 591 | |
| 592 | headerFree(h); |
| 593 | if (eiu->relocations) |
| 594 | eiu->relocations->oldPath = _free(eiu->relocations->oldPath)rfree((eiu->relocations->oldPath)); |
| 595 | |
| 596 | switch (rc) { |
| 597 | case 0: |
| 598 | rpmlog(RPMLOG_DEBUG, "\tadded binary package [%d]\n", |
| 599 | eiu->numRPMS); |
| 600 | break; |
| 601 | case 1: |
| 602 | rpmlog(RPMLOG_ERR, |
| 603 | _("error reading from file %s\n")dcgettext ("rpm", "error reading from file %s\n", 5), *eiu->fnp); |
| 604 | eiu->numFailed++; |
| 605 | goto exit; |
| 606 | break; |
| 607 | default: |
| 608 | eiu->numFailed++; |
| 609 | goto exit; |
| 610 | break; |
| 611 | } |
| 612 | |
| 613 | eiu->numRPMS++; |
| 614 | } |
| 615 | |
| 616 | rpmlog(RPMLOG_DEBUG, "found %d source and %d binary packages\n", |
| 617 | eiu->numSRPMS, eiu->numRPMS); |
| 618 | |
| 619 | if (eiu->numFailed) goto exit; |
| 620 | |
| 621 | if (eiu->numRPMS) { |
| 622 | int rc = rpmcliTransaction(ts, ia, eiu->numPkgs); |
| 623 | if (rc < 0) |
| 624 | eiu->numFailed += eiu->numRPMS; |
| 625 | else if (rc > 0) |
| 626 | eiu->numFailed += rc; |
| 627 | } |
| 628 | |
| 629 | if (eiu->numSRPMS && (eiu->sourceURL != NULL((void*)0))) { |
| 630 | rpmcliProgressState = 0; |
| 631 | rpmcliProgressTotal = 0; |
| 632 | rpmcliProgressCurrent = 0; |
| 633 | for (i = 0; i < eiu->numSRPMS; i++) { |
| 634 | rpmsqPoll(); |
| 635 | if (eiu->sourceURL[i] != NULL((void*)0)) { |
| 636 | rc = RPMRC_OK; |
| 637 | if (!(rpmtsFlags(ts) & RPMTRANS_FLAG_TEST)) |
| 638 | rc = rpmInstallSource(ts, eiu->sourceURL[i], NULL((void*)0), NULL((void*)0)); |
| 639 | if (rc != 0) |
| 640 | eiu->numFailed++; |
| 641 | } |
| 642 | } |
| 643 | } |
| 644 | |
| 645 | exit: |
| 646 | if (eiu->pkgURL != NULL((void*)0)) { |
| 647 | for (i = 0; i < eiu->numPkgs; i++) { |
| 648 | if (eiu->pkgURL[i] == NULL((void*)0)) continue; |
| 649 | if (eiu->pkgState[i] == 1) |
| 650 | (void) unlink(eiu->pkgURL[i]); |
| 651 | eiu->pkgURL[i] = _free(eiu->pkgURL[i])rfree((eiu->pkgURL[i])); |
| 652 | } |
| 653 | } |
| 654 | eiu->pkgState = _free(eiu->pkgState)rfree((eiu->pkgState)); |
| 655 | eiu->pkgURL = _free(eiu->pkgURL)rfree((eiu->pkgURL)); |
| 656 | eiu->argv = _free(eiu->argv)rfree((eiu->argv)); |
| 657 | rc = eiu->numFailed; |
| 658 | free(eiu); |
| 659 | |
| 660 | rpmtsEmpty(ts); |
| 661 | rpmtsSetVSFlags(ts, ovsflags); |
| 662 | |
| 663 | return rc; |
| 664 | } |
| 665 | |
| 666 | int rpmErase(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_const_t argv) |
| 667 | { |
| 668 | char * const * arg; |
| 669 | char *qfmt = NULL((void*)0); |
| 670 | int numFailed = 0; |
| 671 | int numPackages = 0; |
| 672 | rpmVSFlags vsflags, ovsflags; |
| 673 | |
| 674 | if (argv == NULL((void*)0)) return 0; |
| 675 | |
| 676 | vsflags = setvsFlags(ia); |
| 677 | ovsflags = rpmtsSetVSFlags(ts, vsflags); |
| 678 | |
| 679 | (void) rpmtsSetFlags(ts, ia->transFlags); |
| 680 | |
| 681 | setNotifyFlag(ia, ts); |
| 682 | |
| 683 | qfmt = rpmExpand("%{?_query_all_fmt}\n", NULL((void*)0)); |
| 684 | for (arg = argv; *arg; arg++) { |
| 685 | rpmdbMatchIterator mi = rpmtsInitIterator(ts, RPMDBI_LABEL, *arg, 0); |
| 686 | int matches = rpmdbGetIteratorCount(mi); |
| 687 | int erasing = 1; |
| 688 | |
| 689 | if (! matches) { |
| 690 | rpmlog(RPMLOG_ERR, _("package %s is not installed\n")dcgettext ("rpm", "package %s is not installed\n", 5), *arg); |
| 691 | numFailed++; |
| 692 | } else { |
| 693 | Header h; /* XXX iterator owns the reference */ |
| 694 | |
| 695 | if (matches > 1 && |
| 696 | !(ia->installInterfaceFlags & UNINSTALL_ALLMATCHESINSTALL_ALLMATCHES)) { |
| 697 | rpmlog(RPMLOG_ERR, _("\"%s\" specifies multiple packages:\n")dcgettext ("rpm", "\"%s\" specifies multiple packages:\n", 5), |
| 698 | *arg); |
| 699 | numFailed++; |
| 700 | erasing = 0; |
| 701 | } |
| 702 | |
| 703 | while ((h = rpmdbNextIterator(mi)) != NULL((void*)0)) { |
| 704 | if (erasing) { |
| 705 | (void) rpmtsAddEraseElement(ts, h, -1); |
| 706 | numPackages++; |
| 707 | } else { |
| 708 | char *nevra = headerFormat(h, qfmt, NULL((void*)0)); |
| 709 | rpmlog(RPMLOG_NOTICE, " %s", nevra); |
| 710 | free(nevra); |
| 711 | } |
| 712 | } |
| 713 | } |
| 714 | rpmdbFreeIterator(mi); |
| 715 | } |
| 716 | free(qfmt); |
| 717 | |
| 718 | if (numFailed) goto exit; |
| 719 | numFailed = rpmcliTransaction(ts, ia, numPackages); |
| 720 | exit: |
| 721 | rpmtsEmpty(ts); |
| 722 | rpmtsSetVSFlags(ts, ovsflags); |
| 723 | |
| 724 | return numFailed; |
| 725 | } |
| 726 | |
| 727 | int rpmInstallSource(rpmts ts, const char * arg, |
| 728 | char ** specFilePtr, char ** cookie) |
| 729 | { |
| 730 | FD_t fd; |
| 731 | int rc; |
| 732 | |
| 733 | |
| 734 | fd = Fopen(arg, "r.ufdio"); |
| 735 | if (fd == NULL((void*)0) || Ferror(fd)) { |
| 736 | rpmlog(RPMLOG_ERR, _("cannot open %s: %s\n")dcgettext ("rpm", "cannot open %s: %s\n", 5), arg, Fstrerror(fd)); |
| 737 | if (fd != NULL((void*)0)) (void) Fclose(fd); |
| 738 | return 1; |
| 739 | } |
| 740 | |
| 741 | if (rpmIsVerbose()(rpmlogSetMask(0) >= (1 << ((unsigned)(RPMLOG_INFO)) )) && specFilePtr != NULL((void*)0)) |
| 742 | fprintf(stdoutstdout, _("Installing %s\n")dcgettext ("rpm", "Installing %s\n", 5), arg); |
| 743 | |
| 744 | { |
| 745 | rpmVSFlags ovsflags = |
| 746 | rpmtsSetVSFlags(ts, (specFilePtr) ? (rpmtsVSFlags(ts) | RPMVSF_NEEDPAYLOAD) : rpmtsVSFlags(ts)); |
| 747 | rpmRC rpmrc = rpmInstallSourcePackage(ts, fd, specFilePtr, cookie); |
| 748 | rc = (rpmrc == RPMRC_OK ? 0 : 1); |
| 749 | rpmtsSetVSFlags(ts, ovsflags); |
| 750 | } |
| 751 | if (rc != 0) { |
| 752 | rpmlog(RPMLOG_ERR, _("%s cannot be installed\n")dcgettext ("rpm", "%s cannot be installed\n", 5), arg); |
| 753 | if (specFilePtr && *specFilePtr) |
| 754 | *specFilePtr = _free(*specFilePtr)rfree((*specFilePtr)); |
| 755 | if (cookie && *cookie) |
| 756 | *cookie = _free(*cookie)rfree((*cookie)); |
| 757 | } |
| 758 | |
| 759 | (void) Fclose(fd); |
| 760 | |
| 761 | return rc; |
| 762 | } |
| 763 |