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

« back to all changes in this revision

Viewing changes to lib/dpkg/path.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:
3
3
 * path.c - path handling functions
4
4
 *
5
5
 * Copyright © 1995 Ian Jackson <ian@chiark.greenend.org.uk>
6
 
 * Copyright © 2008, 2009 Guillem Jover <guillem@debian.org>
 
6
 * Copyright © 2008-2010 Guillem Jover <guillem@debian.org>
7
7
 *
8
8
 * This is free software; you can redistribute it and/or modify
9
9
 * it under the terms of the GNU General Public License as published by
22
22
#include <config.h>
23
23
#include <compat.h>
24
24
 
25
 
#include <stdio.h>
26
25
#include <stdlib.h>
27
26
#include <string.h>
28
27
#include <stdio.h>
29
28
 
30
 
#include <dpkg/varbuf.h>
 
29
#include <dpkg/dpkg.h>
31
30
#include <dpkg/path.h>
32
31
 
 
32
/**
 
33
 * Trim ‘/’ and ‘/.’ from the end of a pathname.
 
34
 *
 
35
 * The given string will get NUL-terminatd.
 
36
 *
 
37
 * @param path The pathname to trim.
 
38
 *
 
39
 * @return The size of the trimmed pathname.
 
40
 */
33
41
size_t
34
 
path_rtrim_slash_slashdot(char *path)
 
42
path_trim_slash_slashdot(char *path)
35
43
{
36
44
        char *end;
37
45
 
48
56
        return end - path + 1;
49
57
}
50
58
 
 
59
/**
 
60
 * Skip ‘/’ and ‘./’ from the beginning of a pathname.
 
61
 *
 
62
 * @param path The pathname to skip.
 
63
 *
 
64
 * @return The new beginning of the pathname.
 
65
 */
51
66
const char *
52
67
path_skip_slash_dotslash(const char *path)
53
68
{
68
83
path_make_temp_template(const char *suffix)
69
84
{
70
85
        const char *tmpdir;
71
 
        struct varbuf template = VARBUF_INIT;
 
86
        char *template;
72
87
 
73
88
        tmpdir = getenv("TMPDIR");
74
89
#ifdef P_tmpdir
78
93
        if (!tmpdir)
79
94
                tmpdir = "/tmp";
80
95
 
81
 
        varbufprintf(&template, "%s/%s.XXXXXX", tmpdir, suffix);
 
96
        m_asprintf(&template, "%s/%s.XXXXXX", tmpdir, suffix);
82
97
 
83
 
        return varbuf_detach(&template);
 
98
        return template;
84
99
}
85
100
 
86
 
/*
87
 
 * snprintf(3) doesn't work if format contains %.<nnn>s and an argument has
88
 
 * invalid char for locale, then it returns -1.
89
 
 * ohshite() is ok, but fd_fd_copy(), which is used in tarobject(), is not
90
 
 * ok, because:
91
 
 *
92
 
 * - fd_fd_copy() == buffer_copy_TYPE() ‘lib/dpkg/buffer.h’.
93
 
 * - buffer_copy_TYPE() uses varbufvprintf(&v, desc, al); ‘lib/dpkg/buffer.c’.
94
 
 * - varbufvprintf() fails, because it calls with:
95
 
 *     fmt = "backend dpkg-deb during '%.255s'"
96
 
 *   arg may contain some invalid char, for example,
97
 
 *   «/usr/share/doc/console-tools/examples/unicode/\342\231\252\342\231\254»
98
 
 *   in console-tools.
99
 
 *
100
 
 * In this case, if the user uses some locale which doesn't support
101
 
 * “\342\231...”, vsnprintf() always returns -1 and varbufextend() fails.
102
 
 *
103
 
 * So, we need to escape invalid char, probably as in
104
 
 * ‘tar-1.13.19/lib/quotearg.c: quotearg_buffer_restyled()’
105
 
 * but here we escape all 8 bit chars, in order make it simple.
 
101
/**
 
102
 * Escape characters in a pathname for safe locale printing.
 
103
 *
 
104
 * We need to quote paths so that they do not cause problems when printing
 
105
 * them, for example with snprintf(3) which does not work if the format
 
106
 * string contains %s and an argument has invalid characters for the
 
107
 * current locale, it will then return -1.
 
108
 *
 
109
 * To simplify things, we just escape all 8 bit characters, instead of
 
110
 * just invalid characters.
 
111
 *
 
112
 * @param dst The escaped destination string.
 
113
 * @param src The source string to escape.
 
114
 * @param n The size of the destination buffer.
 
115
 *
 
116
 * @return The destination string.
106
117
 */
107
118
char *
108
119
path_quote_filename(char *dst, const char *src, size_t n)
113
124
        if (size == 0)
114
125
                return r;
115
126
 
116
 
        while (size > 0) {
117
 
                switch (*src) {
118
 
                case '\0':
119
 
                        *dst = '\0';
120
 
                        return r;
121
 
                case '\\':
122
 
                        if (size <= 2) {
123
 
                                /* Buffer full. */
124
 
                                *dst = '\0';
125
 
                                return r;
126
 
                        }
127
 
                        *dst++ = '\\';
128
 
                        *dst++ = '\\';
129
 
                        src++;
 
127
        while (*src) {
 
128
                if (*src == '\\') {
130
129
                        size -= 2;
131
 
                        break;
132
 
                default:
133
 
                        if (((*src) & 0x80) == '\0') {
134
 
                                *dst++ = *src++;
135
 
                                --size;
136
 
                        } else {
137
 
                                if (size > 4) {
138
 
                                        sprintf(dst, "\\%03o",
139
 
                                                *(const unsigned char *)src);
140
 
                                        size -= 4;
141
 
                                        dst += 4;
142
 
                                        src++;
143
 
                                } else {
144
 
                                        /* Buffer full. */
145
 
                                        *dst = '\0';
146
 
                                        return r;
147
 
                                }
148
 
                        }
 
130
                        if (size <= 0)
 
131
                                break;
 
132
 
 
133
                        *dst++ = '\\';
 
134
                        *dst++ = '\\';
 
135
                        src++;
 
136
                } else if (((*src) & 0x80) == '\0') {
 
137
                        size--;
 
138
                        if (size <= 0)
 
139
                                break;
 
140
 
 
141
                        *dst++ = *src++;
 
142
                } else {
 
143
                        size -= 4;
 
144
                        if (size <= 0)
 
145
                                break;
 
146
 
 
147
                        sprintf(dst, "\\%03o",
 
148
                                *(const unsigned char *)src);
 
149
                        dst += 4;
 
150
                        src++;
149
151
                }
150
152
        }
151
 
        /* Buffer full. */
152
 
        *(dst - 1) = '\0';
 
153
 
 
154
        *dst = '\0';
153
155
 
154
156
        return r;
155
157
}
156