~ubuntu-branches/ubuntu/precise/rpm/precise-proposed

« back to all changes in this revision

Viewing changes to lib/rpminstall.c

  • Committer: Bazaar Package Importer
  • Author(s): Michal Čihař
  • Date: 2010-06-28 11:12:30 UTC
  • mfrom: (17.2.5 sid)
  • Revision ID: james.westby@ubuntu.com-20100628111230-8ggjjhgpvrnr3ybx
Tags: 4.8.1-5
Fix compilation on hurd and kfreebsd (Closes: #587366).

Show diffs side-by-side

added added

removed removed

Lines of Context:
104
104
    void * rc = NULL;
105
105
    const char * filename = (const char *)key;
106
106
    static FD_t fd = NULL;
107
 
    int xx;
108
107
 
109
108
    switch (what) {
110
109
    case RPMCALLBACK_INST_OPEN_FILE:
116
115
            rpmlog(RPMLOG_ERR, _("open of %s failed: %s\n"), filename,
117
116
                        Fstrerror(fd));
118
117
            if (fd != NULL) {
119
 
                xx = Fclose(fd);
 
118
                Fclose(fd);
120
119
                fd = NULL;
121
120
            }
122
121
        } else
128
127
        /* FIX: still necessary? */
129
128
        fd = fdFree(fd, RPMDBG_M("persist (showProgress)"));
130
129
        if (fd != NULL) {
131
 
            xx = Fclose(fd);
 
130
            Fclose(fd);
132
131
            fd = NULL;
133
132
        }
134
133
        break;
208
207
static void setNotifyFlag(struct rpmInstallArguments_s * ia,
209
208
                          rpmts ts)
210
209
{
211
 
    int notifyFlags, xx;
 
210
    int notifyFlags;
212
211
 
213
212
    notifyFlags = ia->installInterfaceFlags | (rpmIsVerbose() ? INSTALL_LABEL : 0 );
214
 
    xx = rpmtsSetNotifyCallback(ts,
215
 
                                rpmShowProgress, (void *) ((long)notifyFlags));
 
213
    rpmtsSetNotifyCallback(ts, rpmShowProgress, (void *) ((long)notifyFlags));
216
214
}
217
215
 
218
216
struct rpmEIU {
219
217
    Header h;
220
 
    FD_t fd;
221
218
    int numFailed;
222
219
    int numPkgs;
223
220
    char ** pkgURL;
293
290
 
294
291
static int tryReadManifest(struct rpmEIU * eiu)
295
292
{
296
 
    int rc, xx;
 
293
    int rc;
297
294
 
298
295
    /* Try to read a package manifest. */
299
 
    eiu->fd = Fopen(*eiu->fnp, "r.fpio");
300
 
    if (eiu->fd == NULL || Ferror(eiu->fd)) {
 
296
    FD_t fd = Fopen(*eiu->fnp, "r.fpio");
 
297
    if (fd == NULL || Ferror(fd)) {
301
298
        rpmlog(RPMLOG_ERR, _("open of %s failed: %s\n"), *eiu->fnp,
302
 
               Fstrerror(eiu->fd));
303
 
        if (eiu->fd != NULL) {
304
 
            xx = Fclose(eiu->fd);
305
 
            eiu->fd = NULL;
 
299
               Fstrerror(fd));
 
300
        if (fd != NULL) {
 
301
            Fclose(fd);
 
302
            fd = NULL;
306
303
        }
307
304
        eiu->numFailed++; *eiu->fnp = NULL;
308
305
        return RPMRC_FAIL;
309
306
    }
310
307
 
311
308
    /* Read list of packages from manifest. */
312
 
    rc = rpmReadPackageManifest(eiu->fd, &eiu->argc, &eiu->argv);
 
309
    rc = rpmReadPackageManifest(fd, &eiu->argc, &eiu->argv);
313
310
    if (rc != RPMRC_OK)
314
311
        rpmlog(RPMLOG_ERR, _("%s: not an rpm package (or package manifest): %s\n"),
315
 
               *eiu->fnp, Fstrerror(eiu->fd));
316
 
    xx = Fclose(eiu->fd);
317
 
    eiu->fd = NULL;
 
312
               *eiu->fnp, Fstrerror(fd));
 
313
    Fclose(fd);
 
314
    fd = NULL;
318
315
 
319
316
    if (rc != RPMRC_OK)
320
317
        eiu->numFailed++; *eiu->fnp = NULL;
322
319
    return rc;
323
320
}
324
321
 
 
322
static int tryReadHeader(rpmts ts, struct rpmEIU * eiu, rpmVSFlags vsflags)
 
323
{
 
324
   rpmVSFlags tvsflags;
 
325
 
 
326
   /* Try to read the header from a package file. */
 
327
   FD_t fd = Fopen(*eiu->fnp, "r.ufdio");
 
328
   if (fd == NULL || Ferror(fd)) {
 
329
       rpmlog(RPMLOG_ERR, _("open of %s failed: %s\n"), *eiu->fnp,
 
330
              Fstrerror(fd));
 
331
       if (fd != NULL) {
 
332
           Fclose(fd);
 
333
           fd = NULL;
 
334
       }
 
335
       eiu->numFailed++; *eiu->fnp = NULL;
 
336
       return RPMRC_FAIL;
 
337
   }
 
338
 
 
339
   /* Read the header, verifying signatures (if present). */
 
340
   tvsflags = rpmtsSetVSFlags(ts, vsflags);
 
341
   eiu->rpmrc = rpmReadPackageFile(ts, fd, *eiu->fnp, &eiu->h);
 
342
   tvsflags = rpmtsSetVSFlags(ts, tvsflags);
 
343
   Fclose(fd);
 
344
   fd = NULL;
 
345
   
 
346
   /* Honor --nomanifest */
 
347
   if (eiu->rpmrc == RPMRC_NOTFOUND && (giFlags & RPMGI_NOMANIFEST))
 
348
       eiu->rpmrc = RPMRC_FAIL;
 
349
 
 
350
   if(eiu->rpmrc == RPMRC_FAIL) {
 
351
       rpmlog(RPMLOG_ERR, _("%s cannot be installed\n"), *eiu->fnp);
 
352
       eiu->numFailed++; *eiu->fnp = NULL;
 
353
   }
 
354
 
 
355
   return RPMRC_OK;
 
356
}
 
357
 
 
358
 
 
359
/* On --freshen, verify package is installed and newer */
 
360
static int checkFreshenStatus(rpmts ts, struct rpmEIU * eiu)
 
361
{
 
362
    rpmdbMatchIterator mi = NULL;
 
363
    const char * name = headerGetString(eiu->h, RPMTAG_NAME);
 
364
    Header oldH;
 
365
    int count;
 
366
 
 
367
    if (name != NULL)
 
368
        mi = rpmtsInitIterator(ts, RPMTAG_NAME, name, 0);
 
369
    count = rpmdbGetIteratorCount(mi);
 
370
    while ((oldH = rpmdbNextIterator(mi)) != NULL) {
 
371
        if (rpmVersionCompare(oldH, eiu->h) < 0)
 
372
            continue;
 
373
        /* same or newer package already installed */
 
374
        count = 0;
 
375
        break;
 
376
    }
 
377
    mi = rpmdbFreeIterator(mi);
 
378
    if (count == 0) {
 
379
        eiu->h = headerFree(eiu->h);
 
380
        return -1;
 
381
    }
 
382
    /* Package is newer than those currently installed. */
 
383
 
 
384
   return 1;
 
385
}
325
386
 
326
387
/** @todo Generalize --freshen policies. */
327
388
int rpmInstall(rpmts ts, struct rpmInstallArguments_s * ia, ARGV_t fileArgv)
329
390
    struct rpmEIU * eiu = xcalloc(1, sizeof(*eiu));
330
391
    rpmRelocation * relocations;
331
392
    char * fileURL = NULL;
332
 
    rpmVSFlags vsflags, ovsflags, tvsflags;
 
393
    rpmVSFlags vsflags, ovsflags;
333
394
    int rc;
334
 
    int xx;
335
395
    int i;
336
396
 
337
397
    if (fileArgv == NULL) goto exit;
398
458
        case URL_IS_HTTPS:
399
459
        case URL_IS_HTTP:
400
460
        case URL_IS_FTP:
401
 
        {   char *tfn;
 
461
        {   char *tfn = NULL;
402
462
            FD_t tfd;
403
463
 
404
464
            if (rpmIsVerbose())
448
508
        rpmlog(RPMLOG_DEBUG, "============== %s\n", *eiu->fnp);
449
509
        (void) urlPath(*eiu->fnp, &fileName);
450
510
 
451
 
        /* Try to read the header from a package file. */
452
 
        eiu->fd = Fopen(*eiu->fnp, "r.ufdio");
453
 
        if (eiu->fd == NULL || Ferror(eiu->fd)) {
454
 
            rpmlog(RPMLOG_ERR, _("open of %s failed: %s\n"), *eiu->fnp,
455
 
                        Fstrerror(eiu->fd));
456
 
            if (eiu->fd != NULL) {
457
 
                xx = Fclose(eiu->fd);
458
 
                eiu->fd = NULL;
459
 
            }
460
 
            eiu->numFailed++; *eiu->fnp = NULL;
461
 
            continue;
462
 
        }
463
 
 
464
 
        /* Read the header, verifying signatures (if present). */
465
 
        tvsflags = rpmtsSetVSFlags(ts, vsflags);
466
 
        eiu->rpmrc = rpmReadPackageFile(ts, eiu->fd, *eiu->fnp, &eiu->h);
467
 
        tvsflags = rpmtsSetVSFlags(ts, tvsflags);
468
 
        xx = Fclose(eiu->fd);
469
 
        eiu->fd = NULL;
470
 
 
471
 
        /* Honor --nomanifest */
472
 
        if (eiu->rpmrc == RPMRC_NOTFOUND && (giFlags & RPMGI_NOMANIFEST))
473
 
            eiu->rpmrc = RPMRC_FAIL;
474
 
 
475
 
        switch (eiu->rpmrc) {
476
 
        case RPMRC_FAIL:
477
 
            rpmlog(RPMLOG_ERR, _("%s cannot be installed\n"), *eiu->fnp);
478
 
            eiu->numFailed++; *eiu->fnp = NULL;
479
 
            continue;
480
 
            break;
481
 
        case RPMRC_NOTFOUND:
 
511
        if (tryReadHeader(ts, eiu, vsflags) == RPMRC_FAIL)
 
512
            continue;
 
513
 
 
514
        if (eiu->rpmrc == RPMRC_NOTFOUND) {
482
515
            rc = tryReadManifest(eiu);
483
516
            if (rc == RPMRC_OK) {
484
517
                eiu->prevx++;
485
 
                goto restart;
 
518
                goto restart;
486
519
            }
487
 
            break;
488
 
        case RPMRC_NOTTRUSTED:
489
 
        case RPMRC_NOKEY:
490
 
        case RPMRC_OK:
491
 
        default:
492
 
            break;
493
520
        }
494
521
 
495
522
        eiu->isSource = headerIsSource(eiu->h);
514
541
                eiu->relocations->oldPath = xstrdup(rpmtdGetString(&prefixes));
515
542
                rpmtdFreeData(&prefixes);
516
543
            } else {
517
 
                const char * name;
518
 
                xx = headerNVR(eiu->h, &name, NULL, NULL);
519
 
                rpmlog(RPMLOG_ERR,
520
 
                               _("package %s is not relocatable\n"), name);
 
544
                rpmlog(RPMLOG_ERR, _("package %s is not relocatable\n"),
 
545
                       headerGetString(eiu->h, RPMTAG_NAME));
521
546
                eiu->numFailed++;
522
547
                goto exit;
523
548
            }
524
549
        }
525
550
 
526
 
        /* On --freshen, verify package is installed and newer */
527
 
        if (ia->installInterfaceFlags & INSTALL_FRESHEN) {
528
 
            rpmdbMatchIterator mi;
529
 
            const char * name;
530
 
            Header oldH;
531
 
            int count;
532
 
 
533
 
            xx = headerNVR(eiu->h, &name, NULL, NULL);
534
 
            mi = rpmtsInitIterator(ts, RPMTAG_NAME, name, 0);
535
 
            count = rpmdbGetIteratorCount(mi);
536
 
            while ((oldH = rpmdbNextIterator(mi)) != NULL) {
537
 
                if (rpmVersionCompare(oldH, eiu->h) < 0)
538
 
                    continue;
539
 
                /* same or newer package already installed */
540
 
                count = 0;
541
 
                break;
542
 
            }
543
 
            mi = rpmdbFreeIterator(mi);
544
 
            if (count == 0) {
545
 
                eiu->h = headerFree(eiu->h);
546
 
                continue;
547
 
            }
548
 
            /* Package is newer than those currently installed. */
549
 
        }
 
551
        if (ia->installInterfaceFlags & INSTALL_FRESHEN)
 
552
            if (checkFreshenStatus(ts, eiu) != 1)
 
553
                continue;
550
554
 
551
555
        rc = rpmtsAddInstallElement(ts, eiu->h, (fnpyKey)fileName,
552
556
                        (ia->installInterfaceFlags & INSTALL_UPGRADE) != 0,