← Back to issue list

snapcraft fails in a directory with spaces

View original Launchpad issue

Metadata

Project
snapcraft (launchpad)
Number
#1720230
Type
issue
State
closed
Author
~elopio
Labels
—
Created
Updated
Closed

Current evaluation

Fixed directory names with spaces by quoting environment-variable values in project_loader; merged as snapcore/snapcraft#1578 (commit d154224d7).

Resolution: closed resolved

Reason: The issue was resolved by merged PR snapcore/snapcraft#1578, commit d154224d7, which quoted additional environment-variable values and fixed Launchpad bug 1720230.

Evaluated by: mr-cal-bot

No scores available.

Issue body

Mark Lee found that snapcraft fails with a very very dark error when it is run in a directory with spaces. To reproduce: $ mkdir "with spaces" $ cd "with spaces" $ snapcraft init $ snapcraft $ snapcraft Preparing to pull my-part Pulling my-part Preparing to build my-part Building my-part /tmp/tmpnwpk1s18: 3: export: spaces/stage/usr/share/perl5/: bad variable name Full output: https://paste.ubuntu.com/25635330/ The problem here is that in snapcraft.internal.common.run we save some environment variables to a script that we then use as a proxy to run a command. Some of those variables are not escaped, with makes the syntax of the script invalid. For example, this is the contents of the script in one of our tests: export PATH="/root/Test App-linux-x64/parts/desktop-gtk2/install/usr/sbin:/root/Test App-linux-x64/parts/desktop-gtk2/install/usr/bin:/root/Test App-linux-x64/parts/desktop-gtk2/install/sbin:/root/Test App-linux-x64/parts/desktop-gtk2/install/bin:$PATH" export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:/root/Test App-linux-x64/parts/desktop-gtk2/install/lib:/root/Test App-linux-x64/parts/desktop-gtk2/install/usr/lib:/root/Test App-linux-x64/parts/desktop-gtk2/install/lib/x86_64-linux-gnu:/root/Test App-linux-x64/parts/desktop-gtk2/install/usr/lib/x86_64-linux-gnu" export LD_LIBRARY_PATH="/root/Test App-linux-x64/parts/desktop-gtk2/install/usr/lib/x86_64-linux-gnu/mesa-egl:$LD_LIBRARY_PATH" export PATH="/root/Test App-linux-x64/stage/usr/sbin:/root/Test App-linux-x64/stage/usr/bin:/root/Test App-linux-x64/stage/sbin:/root/Test App-linux-x64/stage/bin:$PATH" export LDFLAGS="$LDFLAGS -L/root/Test App-linux-x64/parts/desktop-gtk2/install/lib -L/root/Test App-linux-x64/parts/desktop-gtk2/install/usr/lib -L/root/Test App-linux-x64/parts/desktop-gtk2/install/lib/x86_64-linux-gnu -L/root/Test App-linux-x64/parts/desktop-gtk2/install/usr/lib/x86_64-linux-gnu" export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/root/Test App-linux-x64/parts/desktop-gtk2/install/usr/share/pkgconfig" export PERL5LIB=/root/Test App-linux-x64/stage/usr/share/perl5/ export SNAPCRAFT_PART_INSTALL=/root/Test App-linux-x64/parts/desktop-gtk2/install export SNAPCRAFT_PARALLEL_BUILD_COUNT=4 export SNAPCRAFT_STAGE=/root/Test App-linux-x64/stage export SNAPCRAFT_PROJECT_NAME=testapp export SNAPCRAFT_PROJECT_VERSION=1.0.0 export SNAPCRAFT_PROJECT_GRADE=devel The error comes from the PERL5LIB var, but all the ones after that one are not escaped.

Evaluation history

Date Model Scores Action Summary
stealth/space-bunny-alpha — closed resolved Fixed directory names with spaces by quoting environment-variable values in project_loader; merged as snapcore/snapcraft#1578 (commit d154224d7).
stealth/space-bunny-alpha — closed resolved Fixed paths containing spaces by quoting environment-variable values in generated shell scripts; merged in snapcraft#1578 as d154224d7.
stealth/space-bunny-alpha — closed resolved Unquoted environment values broke generated shell proxy scripts in paths containing spaces; commit 44e0be393 ("Fix environment variable handling") corrected the handling.
qwen/qwen3.6-35b-a3b — — Fixed by properly quoting environment variables in the generated shell script. Paths containing spaces are now escaped to prevent bash syntax errors during execution.
qwen/qwen3.6-35b-a3b — — Closed. Fixed by properly escaping environment variables in the generated shell script to prevent syntax errors when build paths contain spaces.

Update history

Date Change
created

Related work

  • Likely Fixed By: snapcore/snapcraft#1578 (confidence 100%)

    Merged fix explicitly expands quoting in project_loader and references this Launchpad bug.

Related issues

Issue Project State Summary Similarity
#1717413 snapcraft snap with an unexisting dir shows a traceback snapcraft (launchpad) closed Missing-directory handling was fixed to return a clear SnapcraftEnvironmentError instead of a traceback; Launchpad bug #1717413 is closed as Fixed.
73%
#1815658 snapcraft leaks build-environment across parts snapcraft (launchpad) closed Fixed by snapcore/snapcraft PR #2472 (commit 8ca7dd7f2), preventing a part's build-environment from leaking into subsequently processed parts.
71%
#1794507 snapcraft fails ugly with multipass when a space is inserted into `name:` field snapcraft (launchpad) closed snapcraft launched Multipass before validating snapcraft.yaml, so a space in `name:` produced an opaque 'Invalid instance name' error. Fixed by merged PR #2388 (commit ba65313cc) adding early snapcraft.yaml validation.
70%
#1693798 snapcraft builds a snap that won't install if + is in the name snapcraft (launchpad) closed Fixed by merged snapcore/snapcraft#1622 (commit 066d6e757), which synchronized snap-name validation with snapd and rejected '+' in snap names.
70%
#5167 Snapcraft raises an internal error if there is a file called `snap` snapcraft closed Fixed by merged PR #5512 (commit 02e267fb9): get_snap_project now catches NotADirectoryError and raises ProjectDirectoryTypeError instead of crashing when a file named 'snap' exists in the project directory.
70%