Skip to content

Commit

Permalink
Marks all workspace files as group read-write on live reload enabled (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmoran authored Mar 16, 2023
1 parent 6b1b2e5 commit b35c58a
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
17 changes: 17 additions & 0 deletions distzip/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
30 changes: 30 additions & 0 deletions distzip/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package distzip_test

import (
"fmt"
"io/fs"
"io/ioutil"
"os"
"path/filepath"
Expand Down Expand Up @@ -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",
))
})
})
})

Expand Down

0 comments on commit b35c58a

Please sign in to comment.