Skip to content

Commit 8426d83

Browse files
committed
fixup! snap/pack: ensure layout paths presence for snaps using bare or core26 and later
1 parent 6e53e47 commit 8426d83

1 file changed

Lines changed: 18 additions & 7 deletions

File tree

snap/pack/pack.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,20 @@ func debArchitecture(info *snap.Info) string {
9595
}
9696
}
9797

98+
// isDir checks whether relPath exists and is a directory inside the snap
99+
// container.
100+
func isDir(container snap.Container, relPath string) bool {
101+
fi, err := container.Lstat(relPath)
102+
return err == nil && fi.IsDir()
103+
}
104+
105+
// isRegularFile checks whether relPath exists and is a regular file inside the
106+
// snap container.
107+
func isRegularFile(container snap.Container, relPath string) bool {
108+
fi, err := container.Lstat(relPath)
109+
return err == nil && fi.Mode().IsRegular()
110+
}
111+
98112
// validateContentPlugTargets checks that content interface plug target
99113
// directories exist in the snap directory tree.
100114
func validateContentPlugTargets(container snap.Container, info *snap.Info) error {
@@ -124,8 +138,7 @@ func validateContentPlugTargets(container snap.Container, info *snap.Info) error
124138
// only the $SNAP and/or / combination prefix was present
125139
continue
126140
}
127-
fi, err := container.Lstat(relPath)
128-
if err != nil || !fi.IsDir() {
141+
if !isDir(container, relPath) {
129142
return fmt.Errorf("content interface plug %q target %v must exist and must be a directory, ensure it is present in the snap or created before packing", plugName, target)
130143
}
131144
}
@@ -160,8 +173,7 @@ func validateLayoutPaths(container snap.Container, info *snap.Info) error {
160173
if relPath == "" {
161174
continue
162175
}
163-
fi, err := container.Lstat(relPath)
164-
if err != nil || !fi.IsDir() {
176+
if !isDir(container, relPath) {
165177
return fmt.Errorf("layout %q must exist as a directory in the snap, ensure it is present or created before packing", layoutPath)
166178
}
167179
continue
@@ -189,11 +201,10 @@ func validateLayoutPaths(container snap.Container, info *snap.Info) error {
189201
continue
190202
}
191203

192-
fi, err := container.Lstat(relPath)
193-
if layout.Bind != "" && (err != nil || !fi.IsDir()) {
204+
if layout.Bind != "" && !isDir(container, relPath) {
194205
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)
195206
}
196-
if layout.BindFile != "" && (err != nil || !fi.Mode().IsRegular()) {
207+
if layout.BindFile != "" && !isRegularFile(container, relPath) {
197208
return fmt.Errorf("layout %q source %q must exist and be a file, ensure it is present in the snap or created before packing", layoutPath, source)
198209
}
199210
}

0 commit comments

Comments
 (0)