~ubuntu-branches/debian/experimental/dpkg/experimental

« back to all changes in this revision

Viewing changes to lib/dpkg/dump.c

  • Committer: Package Import Robot
  • Author(s): Guillem Jover
  • Date: 2012-01-31 21:58:08 UTC
  • Revision ID: package-import@ubuntu.com-20120131215808-jd379pas5w3epk43
Tags: 1.16.2~really1.16.1.2
Revert unapproved NMU.

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 *
5
5
 * Copyright © 1995 Ian Jackson <ian@chiark.greenend.org.uk>
6
6
 * Copyright © 2001 Wichert Akkerman
7
 
 * Copyright © 2006,2008-2011 Guillem Jover <guillem@debian.org>
8
 
 * Copyright © 2011 Linaro Limited
9
 
 * Copyright © 2011 Raphaël Hertzog <hertzog@debian.org>
10
7
 *
11
8
 * This is free software; you can redistribute it and/or modify
12
9
 * it under the terms of the GNU General Public License as published by
50
47
       const struct pkginfo *pigp, const struct pkgbin *pifp,
51
48
       enum fwriteflags flags, const struct fieldinfo *fip)
52
49
{
53
 
  assert(pigp->set->name);
 
50
  assert(pigp->name);
54
51
  if (flags&fw_printheader)
55
52
    varbuf_add_str(vb, "Package: ");
56
 
  varbuf_add_str(vb, pigp->set->name);
 
53
  varbuf_add_str(vb, pigp->name);
57
54
  if (flags&fw_printheader)
58
55
    varbuf_add_char(vb, '\n');
59
56
}
169
166
}
170
167
 
171
168
void
172
 
w_multiarch(struct varbuf *vb,
173
 
            const struct pkginfo *pigp, const struct pkgbin *pifp,
174
 
            enum fwriteflags flags, const struct fieldinfo *fip)
175
 
{
176
 
  int value = PKGPFIELD(pifp, fip->integer, int);
177
 
 
178
 
  if (!(flags & fw_printheader)) {
179
 
    varbuf_add_str(vb, multiarchinfos[value].name);
180
 
    return;
181
 
  }
182
 
  if (!value)
183
 
    return;
184
 
 
185
 
  varbuf_add_str(vb, fip->name);
186
 
  varbuf_add_str(vb, ": ");
187
 
  varbuf_add_str(vb, multiarchinfos[value].name);
188
 
  varbuf_add_char(vb, '\n');
189
 
}
190
 
 
191
 
void
192
 
w_architecture(struct varbuf *vb,
193
 
               const struct pkginfo *pigp, const struct pkgbin *pifp,
194
 
               enum fwriteflags flags, const struct fieldinfo *fip)
195
 
{
196
 
  if (!pifp->arch)
197
 
    return;
198
 
  if (pifp->arch->type == arch_none)
199
 
    return;
200
 
 
201
 
  if (flags & fw_printheader) {
202
 
    varbuf_add_str(vb, fip->name);
203
 
    varbuf_add_str(vb, ": ");
204
 
  }
205
 
  varbuf_add_str(vb, pifp->arch->name);
206
 
  if (flags & fw_printheader)
207
 
    varbuf_add_char(vb, '\n');
208
 
}
209
 
 
210
 
void
211
169
w_priority(struct varbuf *vb,
212
170
           const struct pkginfo *pigp, const struct pkgbin *pifp,
213
171
           enum fwriteflags flags, const struct fieldinfo *fip)
283
241
    varbuf_add_str(vb, possdel);
284
242
    possdel = " | ";
285
243
    varbuf_add_str(vb, dop->ed->name);
286
 
    if (!dop->arch_is_implicit)
287
 
      varbuf_add_archqual(vb, dop->arch);
288
244
    if (dop->verrel != dvr_none) {
289
245
      varbuf_add_str(vb, " (");
290
246
      switch (dop->verrel) {
404
360
    varbuf_add_str(vb, "Triggers-Awaited:");
405
361
  for (ta = pigp->trigaw.head; ta; ta = ta->sameaw.next) {
406
362
    varbuf_add_char(vb, ' ');
407
 
    varbuf_add_pkgbin_name(vb, ta->pend, &ta->pend->installed, pnaw_nonambig);
 
363
    varbuf_add_str(vb, ta->pend->name);
408
364
  }
409
365
  if (flags & fw_printheader)
410
366
    varbuf_add_char(vb, '\n');
433
389
            const struct pkginfo *pigp, const struct pkgbin *pifp)
434
390
{
435
391
  struct varbuf vb = VARBUF_INIT;
436
 
  struct varbuf pkgname = VARBUF_INIT;
437
 
 
438
 
  varbuf_add_pkgbin_name(&pkgname, pigp, pifp, pnaw_nonambig);
439
392
 
440
393
  varbufrecord(&vb,pigp,pifp);
441
394
  varbuf_end_str(&vb);
442
395
  if (fputs(vb.buf,file) < 0)
443
 
    ohshite(_("failed to write details of `%.50s' to `%.250s'"),
444
 
            pkgname.buf, filename);
 
396
    ohshite(_("failed to write details of `%.50s' to `%.250s'"), pigp->name,
 
397
            filename);
445
398
   varbuf_destroy(&vb);
446
399
}
447
400
 
453
406
  struct pkgiterator *it;
454
407
  struct pkginfo *pigp;
455
408
  struct pkgbin *pifp;
 
409
  char *oldfn, *newfn;
456
410
  const char *which;
457
 
  struct atomic_file *file;
 
411
  FILE *file;
458
412
  struct varbuf vb = VARBUF_INIT;
 
413
  int old_umask;
459
414
 
460
415
  which = (flags & wdb_dump_available) ? "available" : "status";
461
 
 
462
 
  file = atomic_file_new(filename, aff_backup);
463
 
  atomic_file_open(file);
464
 
  if (setvbuf(file->fp, writebuf, _IOFBF, sizeof(writebuf)))
 
416
  m_asprintf(&oldfn, "%s%s", filename, OLDDBEXT);
 
417
  m_asprintf(&newfn, "%s%s", filename, NEWDBEXT);
 
418
 
 
419
  old_umask = umask(022);
 
420
  file= fopen(newfn,"w");
 
421
  umask(old_umask);
 
422
  if (!file)
 
423
    ohshite(_("failed to open '%s' for writing %s database"), filename, which);
 
424
 
 
425
  if (setvbuf(file,writebuf,_IOFBF,sizeof(writebuf)))
465
426
    ohshite(_("unable to set buffering on %s database file"), which);
466
427
 
467
428
  it = pkg_db_iter_new();
468
 
  while ((pigp = pkg_db_iter_next_pkg(it)) != NULL) {
 
429
  while ((pigp = pkg_db_iter_next(it)) != NULL) {
469
430
    pifp = (flags & wdb_dump_available) ? &pigp->available : &pigp->installed;
470
431
    /* Don't dump records which have no useful content. */
471
432
    if (!pkg_is_informative(pigp, pifp))
473
434
    varbufrecord(&vb,pigp,pifp);
474
435
    varbuf_add_char(&vb, '\n');
475
436
    varbuf_end_str(&vb);
476
 
    if (fputs(vb.buf, file->fp) < 0)
 
437
    if (fputs(vb.buf,file) < 0)
477
438
      ohshite(_("failed to write %s database record about '%.50s' to '%.250s'"),
478
 
              which, pkgbin_name(pigp, pifp, pnaw_nonambig), filename);
 
439
              which, pigp->name, filename);
479
440
    varbuf_reset(&vb);
480
441
  }
481
442
  pkg_db_iter_free(it);
482
443
  varbuf_destroy(&vb);
483
 
  if (flags & wdb_must_sync)
484
 
    atomic_file_sync(file);
485
 
 
486
 
  atomic_file_close(file);
487
 
  atomic_file_commit(file);
488
 
  atomic_file_free(file);
 
444
  if (flags & wdb_must_sync) {
 
445
    if (fflush(file))
 
446
      ohshite(_("failed to flush %s database to '%.250s'"), which, filename);
 
447
    if (fsync(fileno(file)))
 
448
      ohshite(_("failed to fsync %s database to '%.250s'"), which, filename);
 
449
  }
 
450
  if (fclose(file))
 
451
    ohshite(_("failed to close '%.250s' after writing %s database"),
 
452
            filename, which);
 
453
  unlink(oldfn);
 
454
  if (link(filename,oldfn) && errno != ENOENT)
 
455
    ohshite(_("failed to link '%.250s' to '%.250s' for backup of %s database"),
 
456
            filename, oldfn, which);
 
457
  if (rename(newfn,filename))
 
458
    ohshite(_("failed to install '%.250s' as '%.250s' containing %s database"),
 
459
            newfn, filename, which);
489
460
 
490
461
  if (flags & wdb_must_sync)
491
462
    dir_sync_path_parent(filename);
 
463
 
 
464
  free(newfn);
 
465
  free(oldfn);
492
466
}