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

« back to all changes in this revision

Viewing changes to lib/dpkg/database.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:
1
 
/*
2
 
 * libdpkg - Debian packaging suite library routines
3
 
 * dpkg-db.h - Low level package database routines (hash tables, etc.)
4
 
 *
5
 
 * Copyright © 1995 Ian Jackson <ian@chiark.greenend.org.uk>
6
 
 *
7
 
 * This is free software; you can redistribute it and/or modify
8
 
 * it under the terms of the GNU General Public License as published by
9
 
 * the Free Software Foundation; either version 2 of the License, or
10
 
 * (at your option) any later version.
11
 
 *
12
 
 * This is distributed in the hope that it will be useful,
13
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 
 * GNU General Public License for more details.
16
 
 *
17
 
 * You should have received a copy of the GNU General Public License
18
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 
 */
20
 
 
21
 
#include <config.h>
22
 
#include <compat.h>
23
 
 
24
 
#include <ctype.h>
25
 
#include <string.h>
26
 
#include <stdlib.h>
27
 
 
28
 
#include <dpkg/i18n.h>
29
 
#include <dpkg/dpkg.h>
30
 
#include <dpkg/dpkg-db.h>
31
 
 
32
 
#define BINS 8191
33
 
 /* This must always be a prime for optimal performance.
34
 
  * With 4093 buckets, we glean a 20% speedup, for 8191 buckets
35
 
  * we get 23%. The nominal increase in memory usage is a mere
36
 
  * sizeof(void*)*8063 (I.E. less than 32KB on 32bit systems)
37
 
  */
38
 
 
39
 
static struct pkginfo *bins[BINS];
40
 
static int npackages;
41
 
 
42
 
#define FNV_offset_basis 2166136261ul
43
 
#define FNV_mixing_prime 16777619ul
44
 
 
45
 
/* Fowler/Noll/Vo -- simple string hash.
46
 
 * For more info, see http://www.isthe.com/chongo/tech/comp/fnv/index.html
47
 
 * */
48
 
 
49
 
static unsigned int hash(const char *name) {
50
 
  register unsigned int h = FNV_offset_basis;
51
 
  register unsigned int p = FNV_mixing_prime;
52
 
  while( *name ) {
53
 
    h *= p;
54
 
    h ^= *name++;
55
 
  }
56
 
  return h;
57
 
}
58
 
 
59
 
void blankversion(struct versionrevision *version) {
60
 
  version->epoch= 0;
61
 
  version->version= version->revision= NULL;
62
 
}
63
 
 
64
 
void blankpackage(struct pkginfo *pigp) {
65
 
  pigp->name= NULL;
66
 
  pigp->status= stat_notinstalled;
67
 
  pigp->eflag = eflag_ok;
68
 
  pigp->want= want_unknown;
69
 
  pigp->priority= pri_unknown;
70
 
  pigp->otherpriority = NULL;
71
 
  pigp->section= NULL;
72
 
  blankversion(&pigp->configversion);
73
 
  pigp->files= NULL;
74
 
  pigp->clientdata= NULL;
75
 
  pigp->trigaw.head = pigp->trigaw.tail = NULL;
76
 
  pigp->othertrigaw_head = NULL;
77
 
  pigp->trigpend_head = NULL;
78
 
  blankpackageperfile(&pigp->installed);
79
 
  blankpackageperfile(&pigp->available);
80
 
}
81
 
 
82
 
void blankpackageperfile(struct pkginfoperfile *pifp) {
83
 
  pifp->essential = false;
84
 
  pifp->depends= NULL;
85
 
  pifp->depended= NULL;
86
 
  pifp->description= pifp->maintainer= pifp->source= pifp->installedsize= pifp->bugs= pifp->origin= NULL;
87
 
  pifp->architecture= NULL;
88
 
  blankversion(&pifp->version);
89
 
  pifp->conffiles= NULL;
90
 
  pifp->arbs= NULL;
91
 
}
92
 
 
93
 
static int nes(const char *s) { return s && *s; }
94
 
 
95
 
bool
96
 
informative(struct pkginfo *pkg, struct pkginfoperfile *info)
97
 
{
98
 
  /* Used by dselect and dpkg query options as an aid to decide
99
 
   * whether to display things, and by dump to decide whether to write them
100
 
   * out.
101
 
   */
102
 
  if (info == &pkg->installed &&
103
 
      (pkg->want != want_unknown ||
104
 
       pkg->eflag != eflag_ok ||
105
 
       pkg->status != stat_notinstalled ||
106
 
       informativeversion(&pkg->configversion)))
107
 
    /* We ignore Section and Priority, as these tend to hang around. */
108
 
    return true;
109
 
  if (info->depends ||
110
 
      nes(info->description) ||
111
 
      nes(info->maintainer) ||
112
 
      nes(info->origin) ||
113
 
      nes(info->bugs) ||
114
 
      nes(info->installedsize) ||
115
 
      nes(info->source) ||
116
 
      informativeversion(&info->version) ||
117
 
      info->conffiles ||
118
 
      info->arbs)
119
 
    return true;
120
 
  return false;
121
 
}
122
 
 
123
 
struct pkginfo *findpackage(const char *inname) {
124
 
  struct pkginfo **pointerp, *newpkg;
125
 
  char *name = m_strdup(inname), *p;
126
 
 
127
 
  p= name;
128
 
  while(*p) { *p= tolower(*p); p++; }
129
 
  
130
 
  pointerp= bins + (hash(name) % (BINS));
131
 
  while (*pointerp && strcasecmp((*pointerp)->name,name))
132
 
    pointerp= &(*pointerp)->next;
133
 
  if (*pointerp) { free(name); return *pointerp; }
134
 
 
135
 
  newpkg= nfmalloc(sizeof(struct pkginfo));
136
 
  blankpackage(newpkg);
137
 
  newpkg->name= nfstrsave(name);
138
 
  newpkg->next= NULL;
139
 
  *pointerp= newpkg;
140
 
  npackages++;
141
 
 
142
 
  free(name);
143
 
  return newpkg;
144
 
}
145
 
 
146
 
int countpackages(void) {
147
 
  return npackages;
148
 
}
149
 
 
150
 
struct pkgiterator {
151
 
  struct pkginfo *pigp;
152
 
  int nbinn;
153
 
};
154
 
 
155
 
struct pkgiterator *iterpkgstart(void) {
156
 
  struct pkgiterator *i;
157
 
  i= m_malloc(sizeof(struct pkgiterator));
158
 
  i->pigp= NULL;
159
 
  i->nbinn= 0;
160
 
  return i;
161
 
}
162
 
 
163
 
struct pkginfo *iterpkgnext(struct pkgiterator *i) {
164
 
  struct pkginfo *r;
165
 
  while (!i->pigp) {
166
 
    if (i->nbinn >= BINS) return NULL;
167
 
    i->pigp= bins[i->nbinn++];
168
 
  }
169
 
  r= i->pigp; i->pigp= r->next; return r;
170
 
}
171
 
 
172
 
void iterpkgend(struct pkgiterator *i) {
173
 
  free(i);
174
 
}
175
 
 
176
 
void resetpackages(void) {
177
 
  int i;
178
 
  nffreeall();
179
 
  npackages= 0;
180
 
  for (i=0; i<BINS; i++) bins[i]= NULL;
181
 
}
182
 
 
183
 
void hashreport(FILE *file) {
184
 
  int i, c;
185
 
  struct pkginfo *pkg;
186
 
  int *freq;
187
 
 
188
 
  freq= m_malloc(sizeof(int)*npackages+1);
189
 
  for (i=0; i<=npackages; i++) freq[i]= 0;
190
 
  for (i=0; i<BINS; i++) {
191
 
    for (c=0, pkg= bins[i]; pkg; c++, pkg= pkg->next);
192
 
    fprintf(file,"bin %5d has %7d\n",i,c);
193
 
    freq[c]++;
194
 
  }
195
 
  for (i=npackages; i>0 && freq[i]==0; i--);
196
 
  while (i>=0) { fprintf(file,_("size %7d occurs %5d times\n"),i,freq[i]); i--; }
197
 
 
198
 
  m_output(file, "<hash report>");
199
 
 
200
 
  free(freq);
201
 
}