Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
Fix assets are not extracted
Browse files Browse the repository at this point in the history
Final zip was deleted by Cleanup routine, and the generated zip
was not valid.

Fixes #1717
  • Loading branch information
stanislas-m committed Jul 13, 2019
1 parent 5243fe3 commit 76bc7d9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
13 changes: 9 additions & 4 deletions genny/build/archived_assets.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,19 @@ func archivedAssets(opts *Options) (*genny.Generator, error) {
return nil
}

if _, err = io.Copy(writer, file); err != nil {
return err
}
return r.File(genny.NewFile(target, bb))
_, err = io.Copy(writer, file)
return err
})
if err != nil {
return err
}
// We need to close the archive before passing the buffer to genny, otherwise the zip
// will be corrupted.
archive.Close()
if err := r.File(genny.NewFile(target, bb)); err != nil {
return err
}
opts.keep.Store(target, struct{}{})
return nil
})

Expand Down
4 changes: 4 additions & 0 deletions genny/build/cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ func Cleanup(opts *Options) genny.RunFn {
return err
}
for _, f := range r.Disk.Files() {
if _, keep := opts.keep.Load(f.Name()); keep {
// Keep this file
continue
}
if err := r.Disk.Delete(f.Name()); err != nil {
return err
}
Expand Down
4 changes: 4 additions & 0 deletions genny/build/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type Options struct {
// GoCommand is the `go X` command to be used. Default is "build".
GoCommand string `json:"go_command"`
rollback *sync.Map
keep *sync.Map
}

// Validate that options are usuable
Expand All @@ -64,6 +65,9 @@ func (opts *Options) Validate() error {
if opts.rollback == nil {
opts.rollback = &sync.Map{}
}
if opts.keep == nil {
opts.keep = &sync.Map{}
}
if len(opts.GoCommand) == 0 {
opts.GoCommand = "build"
}
Expand Down

0 comments on commit 76bc7d9

Please sign in to comment.