• Marcin Sulikowski's avatar
    buildpackage-funcs: Fix whitespace handling in .dsc paths · 1440f3cb
    Marcin Sulikowski authored
    We've noticed that pbuilder fails to build source packages located in
    directories which contain spaces within their names. For example, the
        $ pbuilder build "/tmp/source packages/pbuilder_0.230.2.dsc"
    fails with an error like this:
        I: Building the build Environment
        I: extracting base tarball [/var/cache/pbuilder/base.tgz]
        I: copying local configuration
        I: mounting /proc filesystem
        I: mounting /sys filesystem
        I: creating /{dev,run}/shm
        I: mounting /dev/pts filesystem
        I: redirecting /dev/ptmx to /dev/pts/ptmx
        I: policy-rc.d already exists
        I: Obtaining the cached apt archive contents
        I: Copying source file
        awk: cmd. line:5:              /^ / {if (p){print "/tmp/source
        awk: cmd. line:5:                                 ^ unterminated string
        awk: cmd. line:5:              /^ / {if (p){print "/tmp/source
        awk: cmd. line:5:                                 ^ syntax error
        I: copying [/tmp/source]
        cp: cannot stat '/tmp/source': No such file or directory
        I: unmounting dev/ptmx filesystem
        I: unmounting dev/pts filesystem
    Those problems are caused by the fact that:
    * The `get822files` function incorrectly concatenates strings in:
          awk '(...) {print "'$(dirname "$input")'/" $'${field}'}'
      When `$(dirname "$input")` contains whitespace, the awk script is
      divided by `bash` into multiple arguments for `awk` which causes
      the errors mentioned in the output above.
    * The `get822files` function is designed to return a list of paths
      separated by a single space character, which makes it impossible
      to parse its output when it looks like this:
          source packages/pbuilder_0.230.2.dsc source packages/pbuilder_0.230.2.tar.xz
    These issues make it impossible for pbuilder to copy the given source
    package to its chroot environment even though the rest of pbuilder's
    code is designed to handle whitespace in file names.
    We fix this by changing how the `get822files` function is supposed to
    work -- instead of listing paths separated by a single space, it now
    lists paths separated by LF characters which, although still allowed in
    paths, are almost never used in directory names. As a by-product, path
    of the source package may now contain any characters except for LF,
    including `'` and `"` which were not handled correctly before this fix
    as well.
    Signed-off-by: Marcin Sulikowski's avatarMarcin Sulikowski <marcin.sulikowski@editshare.com>