From 96b9c0412522472dfb4d2d51917feb926c2fa749 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 15 May 2022 20:26:09 -0700 Subject: [PATCH] Filepath fixes --- context.go | 9 +++++++++ file.go | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/context.go b/context.go index ba477ad..d3288c9 100644 --- a/context.go +++ b/context.go @@ -6,6 +6,7 @@ import ( "io" "io/ioutil" "os" + "path/filepath" "runtime" "sync" "time" @@ -49,6 +50,14 @@ func (self *Context) CreateFileFromReader(sourcePath string, reader io.Reader) ( // CreateFileFromAsset creates a new file instance from the provided file path. func (self *Context) CreateFileFromAsset(sourcePath, dataPath string) (*File, error) { + if filepath.IsAbs(sourcePath) { + return nil, errors.New("source paths must be relative") + } + + if filepath.IsAbs(dataPath) { + return nil, errors.New("data paths must be relative") + } + info, err := os.Stat(dataPath) if err != nil { return nil, err diff --git a/file.go b/file.go index 41e1c02..33e249e 100644 --- a/file.go +++ b/file.go @@ -54,7 +54,7 @@ func (self *File) Name() string { // Dir returns the containing directory of the file. func (self *File) Dir() string { - return filepath.Dir(self.relPath) + return filepath.ToSlash(filepath.Dir(self.relPath)) } // Ext returns the extension of the file.