diff --git a/distzip/build.go b/distzip/build.go index 084f006..e82f4bd 100644 --- a/distzip/build.go +++ b/distzip/build.go @@ -18,6 +18,9 @@ package distzip import ( "fmt" + "io/fs" + "os" + "path/filepath" "github.com/paketo-buildpacks/libpak/effect" "github.com/paketo-buildpacks/libpak/sbom" @@ -84,6 +87,20 @@ func (b Build) Build(context libcnb.BuildContext) (libcnb.BuildResult, error) { Default: true, }, ) + + err = filepath.Walk(context.Application.Path, func(path string, info fs.FileInfo, err error) error { + if err != nil { + return err + } + if path == context.Application.Path { + return nil + } + + return os.Chmod(path, info.Mode()|0060) + }) + if err != nil { + return libcnb.BuildResult{}, fmt.Errorf("unable to mark files as group read-write for live reload\n%w", err) + } } if b.SBOMScanner == nil { diff --git a/distzip/build_test.go b/distzip/build_test.go index cb058ee..36102b8 100644 --- a/distzip/build_test.go +++ b/distzip/build_test.go @@ -17,6 +17,8 @@ package distzip_test import ( + "fmt" + "io/fs" "io/ioutil" "os" "path/filepath" @@ -105,6 +107,34 @@ func testBuild(t *testing.T, context spec.G, it spec.S) { )) sbomScanner.AssertCalled(t, "ScanLaunch", ctx.Application.Path, libcnb.SyftJSON, libcnb.CycloneDXJSON) }) + + it("marks all workspace files as group read-write", func() { + _, err := distzip.Build{SBOMScanner: &sbomScanner}.Build(ctx) + Expect(err).NotTo(HaveOccurred()) + + var modes []string + err = filepath.Walk(ctx.Application.Path, func(path string, info fs.FileInfo, err error) error { + if err != nil { + return err + } + if path != ctx.Application.Path { + rel, err := filepath.Rel(ctx.Application.Path, path) + if err != nil { + return err + } + modes = append(modes, fmt.Sprintf("%s %s", info.Mode(), rel)) + } + + return nil + }) + Expect(err).NotTo(HaveOccurred()) + + Expect(modes).To(ConsistOf( + "drwxrwxr-x app", + "drwxrwxr-x app/bin", + "-rwxrwxr-x app/bin/test-script", + )) + }) }) })