snap/pack: ensure layout paths presence for snaps using bare or core26 and later - #16893
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #16893 +/- ##
==========================================
+ Coverage 79.06% 79.10% +0.04%
==========================================
Files 1368 1375 +7
Lines 190680 191204 +524
Branches 2465 2465
==========================================
+ Hits 150758 151259 +501
- Misses 30835 30842 +7
- Partials 9087 9103 +16
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Wed May 6 10:08:17 UTC 2026 Failures:Preparing:
Executing:
Restoring:
Skipped tests from snapd-testing-skipIf you wish to have any of the below tests run in your PR, in your PR description, add 'unskip:' followed by a copy-and-pasted list (without variants) of the below tests you wish to run (unskip plus test list must be valid yaml)
|
| layout := info.Layout[layoutPath] | ||
|
|
||
| // Determine the source path. Only check bind and bind-file; | ||
| // symlink targets and tmpfs layouts are not validated. |
There was a problem hiding this comment.
Let's add a TODO for this but keep it as-is.
5ee50f8 to
0919a7f
Compare
0919a7f to
eaa2cfe
Compare
There was a problem hiding this comment.
Pull request overview
Extends snap/pack skeleton validation to ensure layout-related paths under $SNAP (bind/bind-file sources and tmpfs targets) actually exist in the snap source tree when packing snaps that should carry those paths (bare / core26+).
Changes:
- Add layout path presence validation for
$SNAP-scoped layout bind/bind-file sources and$SNAPtmpfs mountpoints. - Refactor base gating into a shared helper used to decide when strict validation applies.
- Add unit tests covering valid/invalid layout-path scenarios and skipping for older bases.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
snap/pack/pack.go |
Adds validateLayoutPaths and gates strict validation via needsStrictLayoutOrContentValidation. |
snap/pack/pack_test.go |
Adds test matrix for layout source/tmpfs path presence and old-base skip behavior. |
| } | ||
| // Only $SNAP paths (or paths with no variable prefix) can be checked at | ||
| // pack time; $SNAP_DATA and $SNAP_COMMON are read-write runtime | ||
| // directories and mount points can be created as needed. |
There was a problem hiding this comment.
why is this comment going away?
There was a problem hiding this comment.
hm, I may have dropped a bit too much during rebase. Let me restore it
| relPath := strings.TrimPrefix(layoutPath, "$SNAP") | ||
| relPath = strings.TrimPrefix(relPath, "/") | ||
| if relPath == "" { | ||
| continue | ||
| } | ||
| fi, err := container.Lstat(relPath) | ||
| if err != nil || !fi.IsDir() { |
There was a problem hiding this comment.
the other functions has also code like? maybe a small helper?
| if layout.Bind != "" && (err != nil || !fi.IsDir()) { | ||
| return fmt.Errorf("layout %q source %q must exist and be a directory, ensure it is present in the snap or created before packing", layoutPath, source) | ||
| } | ||
| if layout.BindFile != "" && (err != nil || fi.IsDir()) { |
There was a problem hiding this comment.
hm spotted a small issue here, this should be Mode().IsRegular()
…6 and later Ensure that layout paths - sources and tmpfs targets, located under $SNAP are actually found inside the snap directory tree. This is an extension of validation introduced for content interface targets, and follows the exact same rules - i.e. snaps using bare or core26+ bases are expected to carry relevant paths. Related: SNAPDENG-36626 Signed-off-by: Maciej Borzecki <maciej.borzecki@canonical.com>
…r core26 and later
…r core26 and later
…r core26 and later
61783fc to
8426d83
Compare
| continue | ||
| } | ||
| relPath := strings.TrimPrefix(layoutPath, "$SNAP") | ||
| relPath = strings.TrimPrefix(relPath, "/") |
There was a problem hiding this comment.
maybe: we could make a trimSnapPrefix(p) helper that also consider SNAP_DATA and SNAP_COMMON and returns "" in those cases too?
There was a problem hiding this comment.
to be clear if we do the helper that might not be the best name
There was a problem hiding this comment.
I'll open a followup PR
Ensure that layout paths - sources and tmpfs targets, located under
$SNAP are actually found inside the snap directory tree.
This is an extension of validation introduced for content interface
targets, and follows the exact same rules - i.e. snaps using bare or
core26+ bases are expected to carry relevant paths.
Related: SNAPDENG-36626
Based on #16828
Thanks for helping us make a better snapd!
Have you signed the license agreement and read the contribution guide?