fix FileImporter not work on windows

This commit is contained in:
zuiwuchang 2022-09-03 14:47:39 +08:00 committed by Dave Cunningham
parent c17729a921
commit b835910677

View File

@ -20,7 +20,7 @@ import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os" "os"
"path" "path/filepath"
"unsafe" "unsafe"
"github.com/google/go-jsonnet/ast" "github.com/google/go-jsonnet/ast"
@ -232,10 +232,10 @@ func (importer *FileImporter) tryPath(dir, importedPath string) (found bool, con
importer.fsCache = make(map[string]*fsCacheEntry) importer.fsCache = make(map[string]*fsCacheEntry)
} }
var absPath string var absPath string
if path.IsAbs(importedPath) { if filepath.IsAbs(importedPath) {
absPath = importedPath absPath = importedPath
} else { } else {
absPath = path.Join(dir, importedPath) absPath = filepath.Join(dir, importedPath)
} }
var entry *fsCacheEntry var entry *fsCacheEntry
if cacheEntry, isCached := importer.fsCache[absPath]; isCached { if cacheEntry, isCached := importer.fsCache[absPath]; isCached {
@ -268,7 +268,7 @@ func (importer *FileImporter) Import(importedFrom, importedPath string) (content
// in the importer. // in the importer.
// We need to relativize the paths in the error formatter, so that the stack traces // We need to relativize the paths in the error formatter, so that the stack traces
// don't have ugly absolute paths (less readable and messy with golden tests). // don't have ugly absolute paths (less readable and messy with golden tests).
dir, _ := path.Split(importedFrom) dir, _ := filepath.Split(importedFrom)
found, content, foundHere, err := importer.tryPath(dir, importedPath) found, content, foundHere, err := importer.tryPath(dir, importedPath)
if err != nil { if err != nil {
return Contents{}, "", err return Contents{}, "", err