From c009329ebb492a4a26bfde629243699bf0654728 Mon Sep 17 00:00:00 2001 From: Connor Hicks Date: Wed, 10 Feb 2021 08:33:28 -0500 Subject: [PATCH 1/3] allow for complex directory structures within the bundle static/ --- bundle/bundle.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/bundle/bundle.go b/bundle/bundle.go index 7a27df19..556b3848 100644 --- a/bundle/bundle.go +++ b/bundle/bundle.go @@ -67,7 +67,8 @@ func (b *Bundle) StaticFile(filePath string) ([]byte, error) { // Write writes a runnable bundle // based loosely on https://golang.org/src/archive/zip/example_test.go -func Write(directive *directive.Directive, files []os.File, staticFiles []os.File, targetPath string) error { +// staticFiles should be a map of *relative* filepaths to their associated files, with or without the `static/` prefix. +func Write(directive *directive.Directive, modules []os.File, staticFiles map[string]os.File, targetPath string) error { if directive == nil { return errors.New("directive must be provided") } @@ -83,8 +84,8 @@ func Write(directive *directive.Directive, files []os.File, staticFiles []os.Fil return errors.Wrap(err, "failed to writeDirective") } - // Add some files to the archive. - for _, file := range files { + // Add the Wasm modules to the archive. + for _, file := range modules { if file.Name() == "Directive.yaml" || file.Name() == "Directive.yml" { // only allow the canonical directive that's passed in continue @@ -101,13 +102,13 @@ func Write(directive *directive.Directive, files []os.File, staticFiles []os.Fil } // Add static files to the archive. - for _, file := range staticFiles { + for path, file := range staticFiles { contents, err := ioutil.ReadAll(&file) if err != nil { return errors.Wrapf(err, "failed to read file %s", file.Name()) } - fileName := fmt.Sprintf("static/%s", filepath.Base(file.Name())) + fileName := ensurePrefix(path, "static/") if err := writeFile(w, fileName, contents); err != nil { return errors.Wrap(err, "failed to writeFile into bundle") } From db2fa7a4f220d3ebbf7088c2d32e627aac6a791b Mon Sep 17 00:00:00 2001 From: Connor Hicks Date: Wed, 10 Feb 2021 08:42:08 -0500 Subject: [PATCH 2/3] update tester --- bundle/bundlewritetester/main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bundle/bundlewritetester/main.go b/bundle/bundlewritetester/main.go index fd99aa44..d326e202 100644 --- a/bundle/bundlewritetester/main.go +++ b/bundle/bundlewritetester/main.go @@ -23,7 +23,7 @@ func main() { files = append(files, *file) } - staticFiles := []os.File{} + staticFiles := map[string]os.File{} for _, filename := range []string{"go.mod", "go.sum", "Makefile"} { path := filepath.Join("./", filename) @@ -32,7 +32,7 @@ func main() { log.Fatal("failed to open file", err) } - staticFiles = append(staticFiles, *file) + staticFiles[path] = *file } directive := &directive.Directive{ From 358474d0829c30c9ee50f66a920f5d56a71b731d Mon Sep 17 00:00:00 2001 From: Connor Hicks Date: Wed, 10 Feb 2021 08:42:30 -0500 Subject: [PATCH 3/3] fix path --- bundle/bundlewritetester/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundle/bundlewritetester/main.go b/bundle/bundlewritetester/main.go index d326e202..d3a72489 100644 --- a/bundle/bundlewritetester/main.go +++ b/bundle/bundlewritetester/main.go @@ -25,7 +25,7 @@ func main() { staticFiles := map[string]os.File{} for _, filename := range []string{"go.mod", "go.sum", "Makefile"} { - path := filepath.Join("./", filename) + path := filepath.Join("/", filename) file, err := os.Open(path) if err != nil {