Filepath fixes

This commit is contained in:
Alex Yatskov 2022-05-15 20:26:09 -07:00
parent f635ce5da3
commit 96b9c04125
2 changed files with 10 additions and 1 deletions

View File

@ -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

View File

@ -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.