1
0
mirror of https://github.com/hrfee/jfa-go.git synced 2024-12-22 09:00:10 +00:00

fix external fs

This commit is contained in:
Harvey Tindall 2021-07-16 15:39:22 +01:00
parent 8ec4031ba3
commit 7f37633423
Signed by: hrfee
GPG Key ID: BBC65952848FB1A2

View File

@ -12,8 +12,8 @@ import (
const binaryType = "external" const binaryType = "external"
var localFS fs.FS var localFS dirFS
var langFS fs.FS var langFS dirFS
// When using os.DirFS, even on Windows the separator seems to be '/'. // When using os.DirFS, even on Windows the separator seems to be '/'.
// func FSJoin(elem ...string) string { return filepath.Join(elem...) } // func FSJoin(elem ...string) string { return filepath.Join(elem...) }
@ -29,9 +29,23 @@ func FSJoin(elem ...string) string {
return strings.TrimSuffix(path, sep) return strings.TrimSuffix(path, sep)
} }
type dirFS string
func (dir dirFS) Open(name string) (fs.File, error) {
return os.Open(string(dir) + "/" + name)
}
func (dir dirFS) ReadFile(name string) ([]byte, error) {
return os.ReadFile(string(dir) + "/" + name)
}
func (dir dirFS) ReadDir(name string) ([]fs.DirEntry, error) {
return os.ReadDir(string(dir) + "/" + name)
}
func loadFilesystems() { func loadFilesystems() {
log.Println("Using external storage") log.Println("Using external storage")
executable, _ := os.Executable() executable, _ := os.Executable()
localFS = os.DirFS(filepath.Join(filepath.Dir(executable), "data")) localFS = dirFS(filepath.Join(filepath.Dir(executable), "data"))
langFS = os.DirFS(filepath.Join(filepath.Dir(executable), "data", "lang")) langFS = dirFS(filepath.Join(filepath.Dir(executable), "data", "lang"))
} }