From 1f08405af05f60c7986c9f7343c3d4931f190603 Mon Sep 17 00:00:00 2001 From: Egon Elbre Date: Sat, 24 Mar 2018 16:41:04 +0200 Subject: [PATCH] Fix relative path finding (#982) strings.TrimPrefix can give the wrong result with case-insensitive paths. filepath.Rel usually works better. --- buffalo/cmd/build/archived_assets.go | 7 +++++-- generators/files.go | 6 ++++-- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/buffalo/cmd/build/archived_assets.go b/buffalo/cmd/build/archived_assets.go index 1951c4cba..65673a1e4 100644 --- a/buffalo/cmd/build/archived_assets.go +++ b/buffalo/cmd/build/archived_assets.go @@ -6,7 +6,6 @@ import ( "io" "os" "path/filepath" - "strings" "github.com/pkg/errors" "github.com/sirupsen/logrus" @@ -73,7 +72,11 @@ func (b *Builder) buildAssetsArchive() error { } if baseDir != "" { - header.Name = filepath.Join(baseDir, strings.TrimPrefix(path, source)) + rel, err := filepath.Rel(source, path) + if err != nil { + return errors.WithStack(err) + } + header.Name = filepath.Join(baseDir, rel) } if info.IsDir() { diff --git a/generators/files.go b/generators/files.go index 98d4badc3..805eaab22 100644 --- a/generators/files.go +++ b/generators/files.go @@ -70,8 +70,10 @@ func Find(path string) (Files, error) { if info != nil && !info.IsDir() { if filepath.Ext(p) == ".tmpl" { f := File{ReadPath: p} - rel := strings.TrimPrefix(p, root) - + rel, err := filepath.Rel(root, p) + if err != nil { + rel = strings.TrimPrefix(p, root) + } paths := strings.Split(rel, string(os.PathSeparator)) li := len(paths) - 1