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"
"io/ioutil" "io/ioutil"
"os" "os"
"path/filepath"
"runtime" "runtime"
"sync" "sync"
"time" "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. // CreateFileFromAsset creates a new file instance from the provided file path.
func (self *Context) CreateFileFromAsset(sourcePath, dataPath string) (*File, error) { 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) info, err := os.Stat(dataPath)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -54,7 +54,7 @@ func (self *File) Name() string {
// Dir returns the containing directory of the file. // Dir returns the containing directory of the file.
func (self *File) Dir() string { func (self *File) Dir() string {
return filepath.Dir(self.relPath) return filepath.ToSlash(filepath.Dir(self.relPath))
} }
// Ext returns the extension of the file. // Ext returns the extension of the file.