1
0
mirror of https://github.com/zyedidia/micro synced 2024-06-29 05:54:24 +00:00

normalize path - force slash separator to access embed FS (#2197)

This commit is contained in:
Ali Kefia 2021-08-25 22:26:54 +02:00 committed by GitHub
parent ec3292e8c4
commit a417ec4dcb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 3 deletions

1
.gitignore vendored
View File

@ -15,6 +15,5 @@ benchmark_results*
tools/build-version
tools/build-date
tools/info-plist
tools/bindata
tools/vscode-tests/
*.hdr

View File

@ -2,6 +2,7 @@ package config
import (
"embed"
"path/filepath"
"strings"
)
@ -10,9 +11,13 @@ import (
//go:embed colorschemes help plugins syntax
var runtime embed.FS
func fixPath(name string) string {
return strings.TrimLeft(filepath.ToSlash(name), "runtime/")
}
// AssetDir lists file names in folder
func AssetDir(name string) ([]string, error) {
name = strings.TrimLeft(name, "runtime/")
name = fixPath(name)
entries, err := runtime.ReadDir(name)
if err != nil {
return nil, err
@ -26,6 +31,6 @@ func AssetDir(name string) ([]string, error) {
// Asset returns a file content
func Asset(name string) ([]byte, error) {
name = strings.TrimLeft(name, "runtime/")
name = fixPath(name)
return runtime.ReadFile(name)
}