~ubuntu-branches/debian/wheezy/dpkg/wheezy

« back to all changes in this revision

Viewing changes to src/filesdb.c

  • Committer: Bazaar Package Importer
  • Author(s): Guillem Jover, Guillem Jover, Raphaël Hertzog, Jonathan Nieder, Steve Langasek, Mark Hymers, Updated programs translations, Updated man page translations, Updated scripts translations, Updated dselect translations
  • Date: 2011-04-01 23:56:54 UTC
  • Revision ID: james.westby@ubuntu.com-20110401235654-8y800dtb75skfrh7
Tags: 1.16.0
[ Guillem Jover ]
* Use DPKG_MAINTSCRIPT_PACKAGE environment variable as package name on
  dpkg-divert when no --package or --local options have been specified.
* Do not allow versions starting with non-digit when doing strict parsing,
  warn otherwise.
* Update dpkg(1) to note that --status-fd output does not contain newlines
  in error messages anymore (this was fixed in 1.15.0).
* Add a new --status-logger option to dpkg, similar to --status-fd but
  instead invoke the command ourselves and feed the status information
  to its standard input. Suggested by Raphaël Hertzog.
* Add missing space in update-alternative --set-selections output.
* Add missing options to update-alternative --help output.
* Count “conffile name is duplicated” for dpkg-deb warning count summary.
* Improve and clarify strings for translation. Closes: #604914
* Prefix all fatal error messages with “error: ”.
* Do not check presence of update-rc.d in the PATH in dpkg, as it's not
  a program needed for dpkg correct operation.
* Fix dpkg -GEO options on multiple versions of the same packages.
  Closes: #31141
* Propagate --admindir to programs run from maintainer scritpts.
  Closes: #97076
* Do not fail when trying to remove the root directory. This will only
  happen either on distributions where dpkg is a foreign package manager,
  or on artificial dpkg databases.
* Always warn when parsing any package control data which does not have
  an Architecture field except for status and status log files when
  packages are not-installed or half-installed.
* By default reject installing packages w/o an Architecture field. They
  now need --force-architecture, dpkg will still warn about them though.
* Fix build failure when passing --disable-nls to configure.
* Do not segfault on “dpkg -i --no-act”.
* Add missing semicolon to the vsnprintf() compat declaration.
  Thanks to Robert Millan. Closes: #612203
* On install for Ubuntu adjust the i386 GNU cpu name in cputable.
  Thanks to Colin Watson <cjwatson@ubuntu.com>. Closes: #611741
* Sync the info database directory on unpack instead of the temporary
  control information directory, and print the correct pathname on error
  instead of the last file acted on that directory.
* Document in dpkg-query --help output and man page that --list and --show
  arguments are optional.
* Do not read and write the available file unnecessarily.
  Thanks to Michel Lespinasse <walken@zoy.org>. Closes: #397121
* Fix typo in «dpkg-name --overwrite» argument parsing so that it actually
  works at all. Thanks to Ivan Gagis <igagis@gmail.com>. LP: #728708
* Add armhf support to ostable and triplettable. Closes: #594179
* Set the modification time for unpacked symlinks on supported systems.
* Fix undefined value useage in dpkg-genchanges when adding files w/o a
  matching architecture, because they are not present in debian/control,
  this is most commonly the case due to dpkg-distaddfile.
* Terminate immediately on dpkg-divert rename errors instead of propagating
  up the error codes, this improves error reporting and avoids triggering
  leak detectors. Closes: #620380
* When moving a diverted file across filesystems in dpkg-divert, remove
  the source file.

[ Raphaël Hertzog ]
* Fail properly when debian/source/format is empty. Closes: #600854
* Add new deb-src-control(5) manual page documenting the debian/control
  file contained in source packages.
  - it documents the X[SBC]- prefix. Closes: #476335
  - it documents the VCS-* fields too. Closes: #483119
  Thanks to Oxan van Leeuwen <oxan@oxanvanleeuwen.nl> who wrote it
  as part of the Google Code In program.
* Enhance dpkg-shlibdeps to not fail immediatly when a library is not found.
  Instead continue and fail after all problems have been reported. Thanks
  to Chris Baines <cbaines8@gmail.com> for the patch. Closes: #596841
* Fix dpkg-source to not list Debian packaging files as modified
  upstream files in Format "1.0" when unpacking to a non-standard
  directory.
* Apply patch from Colin Watson to let dpkg-buildflags return -O3
  instead of -O2 when building ppc64 packages on Ubuntu. Closes: #612472
* Add new function get_control_path() to Dpkg::Path, it wraps dpkg-query
  --control-path.
* Update dpkg-shlibdeps to be multiarch-ready:
  - use get_control_path() to find symbols/shlibs files
  - parse correctly the output of dpkg --search
* Small fix to support files >2GB in .deb on 64-bit systems. Closes: #616502
  Thanks to Martin Dorey <mdorey@bluearc.com> for the patch.
* dpkg-source now keeps the file ordering in the autogenerated patch when
  regenerating it. Closes: #606080
  Thanks to Colin Watson for the patch.
* dpkg-source now uses a timestamp retrieved from the filesystem when
  resetting the timestamp of patched files so that a time skew when using
  NFS doesn't introduce any inconsistency. Closes: #613023
  Thanks to Jonathan Nieder <jrnieder@gmail.com> for the patch and the
  diagnosis.
* dpkg-source will now remove quilt's .pc directory when --unapply-patches
  is in use. Closes: #591858
* dpkg-source is now a bit less strict when parsing patches:
  - it accepts seeing the same file twice; Closes: #608829
  - it doesn't match on the English text "No newline at end of file" as it
    might be translated in some cases. Closes: #612465
* Improve parser in Dpkg::Control::Hash to not require an empty line
  before the PGP signature. Closes: #617923
  Thanks to Roger Leigh for the initial patch.
* Fix a regression in dpkg-divert where using --rename led to a failure when
  the rename implies crossing file systems. Thanks to Durk Strooisma for
  spotting it.
* Use the correct mtime when installing a file with statoverrides.
  Regression introduced in 1.16.0. LP: #739179
* Remove duplicate word in german translation of dpkg(1). Closes: #616096
* Strip repeated non-significant spaces before and after newlines
  in Uploaders. Closes: #598922
* Ignore whitespaces after options in headers of changelog entries.
  Closes: #605719
* Fix dpkg-source's regression with empty patches (introduced while fixing
  #613023). Closes: #619541

[ Jonathan Nieder ]
* Remove support for use of synchronous sync(2), due to its pernicious
  side-effects and to ease maintenance.
* Clarify that an up-to-date dpkg only needs to be unpacked for
  dpkg-maintscript-helper to work.

[ Steve Langasek ]
* Add new variables to dpkg-architecture, DEB_HOST_MULTIARCH and
  DEB_BUILD_MULTIARCH, that return the "ideal" GNU triplet for each
  architecture which should be used as the path component for library
  installation.

[ Mark Hymers ]
* Add support for Built-Using field. Closes: #619311

[ Updated programs translations ]
* German (Sven Joachim).
* Portuguese (Miguel Figueiredo).
* Spanish (Javier Fernandez-Sanguino).
* Swedish (Peter Krefting).

[ Updated man page translations ]
* German (Helge Kreutzmann).
* Swedish (Peter Krefting).

[ Updated scripts translations ]
* German (Helge Kreutzmann).
* Swedish (Peter Krefting).

[ Updated dselect translations ]
* Spanish (Javier Fernandez-Sanguino).

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
#include <dpkg/dpkg-db.h>
45
45
#include <dpkg/path.h>
46
46
#include <dpkg/dir.h>
47
 
#include <dpkg/buffer.h>
 
47
#include <dpkg/fdio.h>
48
48
#include <dpkg/pkg-array.h>
49
49
#include <dpkg/progress.h>
50
50
 
51
51
#include "filesdb.h"
52
52
#include "main.h"
53
53
 
54
 
 
55
 
/* filepackages support for tracking packages owning a file. */
 
54
/*** Package control information database directory routines. ***/
 
55
 
 
56
/*
 
57
 * XXX: Strictly speaking these functions do not exactly belong here, and
 
58
 * they should be eventually moved back to a unified on-disk database
 
59
 * handling module in libdpkg. For now this is good enough, as it avoids
 
60
 * pulling unneeded code into the resulting binaries, because all its
 
61
 * users require filesdb anyway.
 
62
 */
 
63
 
 
64
static char *infodir;
 
65
 
 
66
static void
 
67
pkgadmindir_init(void)
 
68
{
 
69
  infodir = dpkg_db_get_path(INFODIR);
 
70
}
 
71
 
 
72
const char *
 
73
pkgadmindir(void)
 
74
{
 
75
  return infodir;
 
76
}
 
77
 
 
78
const char *
 
79
pkgadminfile(struct pkginfo *pkg, const char *filetype)
 
80
{
 
81
  static struct varbuf vb;
 
82
 
 
83
  varbuf_reset(&vb);
 
84
  varbuf_add_str(&vb, infodir);
 
85
  varbuf_add_str(&vb, pkg->name);
 
86
  varbuf_add_char(&vb, '.');
 
87
  varbuf_add_str(&vb, filetype);
 
88
  varbuf_end_str(&vb);
 
89
 
 
90
  return vb.buf;
 
91
}
 
92
 
 
93
/*** filepackages support for tracking packages owning a file. ***/
56
94
 
57
95
#define PERFILEPACKAGESLUMP 10
58
96
 
107
145
  free(iter);
108
146
}
109
147
 
110
 
/*** Generic data structures and routines ***/
 
148
/*** Generic data structures and routines. ***/
111
149
 
112
150
static bool allpackagesdone = false;
113
151
static int nfiles= 0;
153
191
       current= current->next) {
154
192
    /* For each file that used to be in the package,
155
193
     * go through looking for this package's entry in the list
156
 
     * of packages containing this file, and blank it out.
157
 
     */
 
194
     * of packages containing this file, and blank it out. */
158
195
    for (packageslump= current->namenode->packages;
159
196
         packageslump;
160
197
         packageslump= packageslump->more)
168
205
               findlast++);
169
206
          findlast--;
170
207
          /* findlast is now the last occupied entry, which may be the same as
171
 
           * search.  We blank out the entry for this package.  We also
 
208
           * search. We blank out the entry for this package. We also
172
209
           * have to copy the last entry into the empty slot, because
173
 
           * the list is null-pointer-terminated.
174
 
           */
 
210
           * the list is NULL-pointer-terminated. */
175
211
          packageslump->pkgs[search]= packageslump->pkgs[findlast];
176
212
          packageslump->pkgs[findlast] = NULL;
177
 
          /* This may result in an empty link in the list.  This is OK. */
 
213
          /* This may result in an empty link in the list. This is OK. */
178
214
          goto xit_search_to_delete_from_perfilenodelist;
179
215
        }
180
216
  xit_search_to_delete_from_perfilenodelist:
181
217
    ;
182
218
    /* The actual filelist links were allocated using nfmalloc, so
183
 
     * we shouldn't free them.
184
 
     */
 
219
     * we shouldn't free them. */
185
220
  }
186
221
  pkg->clientdata->files = NULL;
187
222
}
263
298
  filelistfile= pkgadminfile(pkg,LISTFILE);
264
299
 
265
300
  onerr_abort++;
266
 
  
 
301
 
267
302
  fd= open(filelistfile,O_RDONLY);
268
303
 
269
304
  if (fd==-1) {
281
316
  }
282
317
 
283
318
  push_cleanup(cu_closefd, ehflag_bombout, NULL, 0, 1, &fd);
284
 
  
 
319
 
285
320
   if(fstat(fd, &stat_buf))
286
321
     ohshite(_("unable to stat files list file for package '%.250s'"),
287
322
             pkg->name);
289
324
   if (stat_buf.st_size) {
290
325
     loaded_list = nfmalloc(stat_buf.st_size);
291
326
     loaded_list_end = loaded_list + stat_buf.st_size;
292
 
  
293
 
    fd_buf_copy(fd, loaded_list, stat_buf.st_size, _("files list for package `%.250s'"), pkg->name);
294
 
  
 
327
 
 
328
    if (fd_read(fd, loaded_list, stat_buf.st_size) < 0)
 
329
      ohshite(_("reading files list for package '%.250s'"), pkg->name);
 
330
 
295
331
    lendp= &pkg->clientdata->files;
296
332
    thisline = loaded_list;
297
333
    while (thisline < loaded_list_end) {
298
 
      if (!(ptr = memchr(thisline, '\n', loaded_list_end - thisline))) 
 
334
      if (!(ptr = memchr(thisline, '\n', loaded_list_end - thisline)))
299
335
        ohshit(_("files list file for package '%.250s' is missing final newline"),
300
336
               pkg->name);
301
 
      /* where to start next time around */
 
337
      /* Where to start next time around. */
302
338
      nextline = ptr + 1;
303
 
      /* strip trailing "/" */
 
339
      /* Strip trailing ‘/’. */
304
340
      if (ptr > thisline && ptr[-1] == '/') ptr--;
305
 
      /* add the file to the list */
 
341
      /* Add the file to the list. */
306
342
      if (ptr == thisline)
307
343
        ohshit(_("files list file for package `%.250s' contains empty filename"),pkg->name);
308
344
      *ptr = '\0';
310
346
      thisline = nextline;
311
347
    }
312
348
  }
313
 
  pop_cleanup(ehflag_normaltidy); /* fd= open() */
 
349
  pop_cleanup(ehflag_normaltidy); /* fd = open() */
314
350
  if (close(fd))
315
351
    ohshite(_("error closing files list file for package `%.250s'"),pkg->name);
316
352
 
419
455
 
420
456
  if (allpackagesdone) return;
421
457
  if (saidread<2) {
422
 
    int max = countpackages();
 
458
    int max = pkg_db_count();
423
459
 
424
460
    saidread=1;
425
461
    progress_init(&progress, _("(Reading database ... "), max);
455
491
  ensure_allinstfiles_available();
456
492
}
457
493
 
 
494
/*
 
495
 * If leaveout is nonzero, will not write any file whose filenamenode
 
496
 * has the fnnf_elide_other_lists flag set.
 
497
 */
458
498
void
459
499
write_filelist_except(struct pkginfo *pkg, struct fileinlist *list,
460
500
                      bool leaveout)
461
501
{
462
 
  /* If leaveout is nonzero, will not write any file whose filenamenode
463
 
   * has the fnnf_elide_other_lists flag set.
464
 
   */
465
 
  static struct varbuf vb, newvb;
 
502
  static struct varbuf newvb;
 
503
  const char *listfile;
466
504
  FILE *file;
467
505
 
468
 
  varbufreset(&vb);
469
 
  varbufaddstr(&vb, pkgadmindir());
470
 
  varbufaddstr(&vb,pkg->name);
471
 
  varbufaddstr(&vb,"." LISTFILE);
472
 
  varbufaddc(&vb,0);
473
 
 
474
 
  varbufreset(&newvb);
475
 
  varbufaddstr(&newvb,vb.buf);
476
 
  varbufaddstr(&newvb,NEWDBEXT);
477
 
  varbufaddc(&newvb,0);
478
 
  
 
506
  listfile = pkgadminfile(pkg, LISTFILE);
 
507
 
 
508
  varbuf_reset(&newvb);
 
509
  varbuf_add_str(&newvb, listfile);
 
510
  varbuf_add_str(&newvb, NEWDBEXT);
 
511
  varbuf_end_str(&newvb);
 
512
 
479
513
  file= fopen(newvb.buf,"w+");
480
514
  if (!file)
481
515
    ohshite(_("unable to create updated files list file for package %s"),pkg->name);
493
527
    ohshite(_("failed to flush updated files list file for package %s"),pkg->name);
494
528
  if (fsync(fileno(file)))
495
529
    ohshite(_("failed to sync updated files list file for package %s"),pkg->name);
496
 
  pop_cleanup(ehflag_normaltidy); /* file= fopen() */
 
530
  pop_cleanup(ehflag_normaltidy); /* file = fopen() */
497
531
  if (fclose(file))
498
532
    ohshite(_("failed to close updated files list file for package %s"),pkg->name);
499
 
  if (rename(newvb.buf,vb.buf))
 
533
  if (rename(newvb.buf, listfile))
500
534
    ohshite(_("failed to install updated files list file for package %s"),pkg->name);
501
535
 
502
536
  dir_sync_path(pkgadmindir());
504
538
  note_must_reread_files_inpackage(pkg);
505
539
}
506
540
 
 
541
/*
 
542
 * Initializes an iterator that appears to go through the file
 
543
 * list ‘files’ in reverse order, returning the namenode from
 
544
 * each. What actually happens is that we walk the list here,
 
545
 * building up a reverse list, and then peel it apart one
 
546
 * entry at a time.
 
547
 */
507
548
void reversefilelist_init(struct reversefilelistiter *iterptr,
508
549
                          struct fileinlist *files) {
509
 
  /* Initialises an iterator that appears to go through the file
510
 
   * list `files' in reverse order, returning the namenode from
511
 
   * each.  What actually happens is that we walk the list here,
512
 
   * building up a reverse list, and then peel it apart one
513
 
   * entry at a time.
514
 
   */
515
550
  struct fileinlist *newent;
516
 
  
 
551
 
517
552
  iterptr->todo = NULL;
518
553
  while (files) {
519
554
    newent= m_malloc(sizeof(struct fileinlist));
537
572
  return ret;
538
573
}
539
574
 
 
575
/*
 
576
 * Clients must call this function to clean up the reversefilelistiter
 
577
 * if they wish to break out of the iteration before it is all done.
 
578
 * Calling this function is not necessary if reversefilelist_next has
 
579
 * been called until it returned 0.
 
580
 */
540
581
void reversefilelist_abort(struct reversefilelistiter *iterptr) {
541
 
  /* Clients must call this function to clean up the reversefilelistiter
542
 
   * if they wish to break out of the iteration before it is all done.
543
 
   * Calling this function is not necessary if reversefilelist_next has
544
 
   * been called until it returned 0.
545
 
   */
546
582
  while (reversefilelist_next(iterptr));
547
583
}
548
584
 
551
587
  int nbinn;
552
588
};
553
589
 
 
590
/* This must always be a power of two. If you change it consider changing
 
591
 * the per-character hashing factor (currently 1785 = 137 * 13) too. */
554
592
#define BINS (1 << 17)
555
 
 /* This must always be a power of two.  If you change it
556
 
  * consider changing the per-character hashing factor (currently
557
 
  * 1785 = 137*13) too.
558
 
  */
559
593
 
560
594
static struct filenamenode *bins[BINS];
561
595
 
588
622
  struct filenamenode *fnn;
589
623
  int i;
590
624
 
 
625
  pkgadmindir_init();
 
626
 
591
627
  for (i=0; i<BINS; i++)
592
628
    for (fnn= bins[i]; fnn; fnn= fnn->next) {
593
629
      fnn->flags= 0;
606
642
  struct filenamenode **pointerp, *newnode;
607
643
  const char *orig_name = name;
608
644
 
609
 
  /* We skip initial slashes and ./ pairs, and add our own single leading slash. */
 
645
  /* We skip initial slashes and ‘./’ pairs, and add our own single
 
646
   * leading slash. */
610
647
  name = path_skip_slash_dotslash(name);
611
648
 
612
649
  pointerp= bins + (hash(name) & (BINS-1));
613
650
  while (*pointerp) {
614
 
/* Why is this assert nescessary?  It is checking already added entries. */
 
651
    /* XXX: Why is the assert needed? It's checking already added entries. */
615
652
    assert((*pointerp)->name[0] == '/');
616
653
    if (!strcmp((*pointerp)->name+1,name)) break;
617
654
    pointerp= &(*pointerp)->next;