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

Commit

Permalink
Fix relative path finding (#982) (#989)
Browse files Browse the repository at this point in the history
strings.TrimPrefix can give the wrong result with case-insensitive
paths. filepath.Rel usually works better.
  • Loading branch information
egonelbre authored and stanislas-m committed May 12, 2018
1 parent df18355 commit c443b52
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 5 additions & 2 deletions buffalo/cmd/build/archived_assets.go
Expand Up @@ -6,7 +6,6 @@ import (
"io"
"os"
"path/filepath"
"strings"

"github.com/pkg/errors"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -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() {
Expand Down
6 changes: 4 additions & 2 deletions generators/files.go
Expand Up @@ -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
Expand Down

0 comments on commit c443b52

Please sign in to comment.