Skip to content

Commit

Permalink
Remove compiled artifact if we expand it
Browse files Browse the repository at this point in the history
  • Loading branch information
hibell authored and Hank W Ibell committed Dec 12, 2022
1 parent d3ac57a commit 374dc74
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 5 additions & 3 deletions liberty/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func (b Base) contributeApp(layer libcnb.Layer, config server.Config) error {
serverPath := filepath.Join(layer.Path, "wlp", "usr", "servers", b.ServerName)

linkPath := filepath.Join(serverPath, "apps", "app")
if err := os.Remove(linkPath); err != nil && !errors.Is(err, fs.ErrNotExist) {
if err := os.RemoveAll(linkPath); err != nil && !errors.Is(err, fs.ErrNotExist) {
return fmt.Errorf("unable to remove app\n%w", err)
}

Expand All @@ -291,10 +291,12 @@ func (b Base) contributeApp(layer libcnb.Layer, config server.Config) error {
if err != nil {
return fmt.Errorf("unable to open compiled artifact\n%w", err)
}
err = crush.Extract(compiledArtifact, linkPath, 0)
if err != nil {
if err := crush.Extract(compiledArtifact, linkPath, 0); err != nil {
return fmt.Errorf("unable to extract compiled artifact\n%w", err)
}
if err := os.Remove(appPath); err != nil {
return fmt.Errorf("unable to remove compiled artifact\n%w", err)
}
}

if config.Application.Name == "app" {
Expand Down
2 changes: 2 additions & 0 deletions liberty/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,10 @@ func testBase(t *testing.T, _ spec.G, it spec.S) {
layer, err = base.Contribute(layer)
Expect(err).ToNot(HaveOccurred())

// Ensure app war is expanded to <server>/apps/app and compiled artifact was deleted
Expect(filepath.Join(layer.Path, "wlp", "usr", "servers", "defaultServer", "apps", "app")).To(BeADirectory())
Expect(filepath.Join(layer.Path, "wlp", "usr", "servers", "defaultServer", "apps", "app", "index.html")).To(BeAnExistingFile())
Expect(filepath.Join(ctx.Application.Path, "test.war")).ToNot(BeAnExistingFile())

serverDir := filepath.Join(layer.Path, "wlp", "usr", "servers", "defaultServer")
for _, file := range []string{
Expand Down

0 comments on commit 374dc74

Please sign in to comment.