Skip to content

Commit ca8e2aa

Browse files
committed
fixup! snap/pack: validate content interface plug target exists for core26+
1 parent bbf77d4 commit ca8e2aa

2 files changed

Lines changed: 24 additions & 5 deletions

File tree

snap/pack/pack.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,12 @@ func validateContentPlugTargets(container snap.Container, info *snap.Info) error
131131
if relPath == "" {
132132
continue
133133
}
134-
if _, err := container.Lstat(relPath); err != nil {
135-
return fmt.Errorf("content interface plug %q has target %q which does not exist", plugName, target)
134+
fi, err := container.Lstat(relPath)
135+
if err != nil {
136+
return fmt.Errorf("content interface plug %q target %q does not exist", plugName, target)
137+
}
138+
if !fi.IsDir() {
139+
return fmt.Errorf("content interface plug %q target %q must be a directory", plugName, target)
136140
}
137141
}
138142
return nil

snap/pack/pack_test.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,22 @@ plugs:
649649
`)
650650
var buf bytes.Buffer
651651
err := pack.CheckSkeleton(&buf, sourceDir)
652-
c.Assert(err, ErrorMatches, `content interface plug "shared-data" has target "\$SNAP/import" which does not exist`)
652+
c.Assert(err, ErrorMatches, `content interface plug "shared-data" target "\$SNAP/import" does not exist`)
653+
}
654+
655+
func (s *packSuite) TestCheckSkeletonContentPlugTargetNotDirectory(c *C) {
656+
sourceDir := makeExampleSnapSourceDir(c, `name: hello
657+
version: 0
658+
base: core26
659+
plugs:
660+
shared-data:
661+
interface: content
662+
target: $SNAP/import
663+
`)
664+
c.Assert(os.WriteFile(filepath.Join(sourceDir, "import"), []byte(""), 0644), IsNil)
665+
var buf bytes.Buffer
666+
err := pack.CheckSkeleton(&buf, sourceDir)
667+
c.Assert(err, ErrorMatches, `content interface plug "shared-data" target "\$SNAP/import" must be a directory`)
653668
}
654669

655670
func (s *packSuite) TestCheckSkeletonContentPlugTargetOldBaseSkipped(c *C) {
@@ -710,7 +725,7 @@ plugs:
710725
`)
711726
var buf bytes.Buffer
712727
err := pack.CheckSkeleton(&buf, sourceDir)
713-
c.Assert(err, ErrorMatches, `content interface plug "shared-data" has target "import" which does not exist`)
728+
c.Assert(err, ErrorMatches, `content interface plug "shared-data" target "import" does not exist`)
714729
}
715730

716731
func (s *packSuite) TestCheckSkeletonContentPlugTargetMultiplePlugs(c *C) {
@@ -728,5 +743,5 @@ plugs:
728743
c.Assert(os.Mkdir(filepath.Join(sourceDir, "existing"), 0755), IsNil)
729744
var buf bytes.Buffer
730745
err := pack.CheckSkeleton(&buf, sourceDir)
731-
c.Assert(err, ErrorMatches, `content interface plug "plug-missing" has target "\$SNAP/missing" which does not exist`)
746+
c.Assert(err, ErrorMatches, `content interface plug "plug-missing" target "\$SNAP/missing" does not exist`)
732747
}

0 commit comments

Comments
 (0)