Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug in bindatafs on windows #6

Open
sugacube opened this issue Oct 22, 2018 · 0 comments
Open

bug in bindatafs on windows #6

sugacube opened this issue Oct 22, 2018 · 0 comments

Comments

@sugacube
Copy link

There appears to be a bug when using bindatafs on windows OS.
This is manifested for example when trying to use qor/admin with bindatafs on windows, then some templates are not loaded resulting in distorted views.

See qor/admin#153 for how to reproduce.

Solution is to fix templates of bindatafs: update "Glob" and "Asset" functions: use "path" in stead of "filepath", and change \ to /. (although maybe better to us os.PathSeparator)

-- bindatafs.go.template:

func (assetFS *bindataFS) Glob(pattern string) (matches []string, err error) {
	pattern = strings.Replace(pattern, "\\", "/", -1)
	if len(_bindata) > 0 {
		for key, _ := range _bindata {
			if ok, err := path.Match(pattern, key); ok && err == nil {
				matches = append(matches, key)
			}
		}
		return matches, nil
	}

	return assetFS.AssetFileSystem.Glob(pattern)
}



func (assetFS *nameSpacedBindataFS) Asset(name string) ([]byte, error) {
	name = strings.TrimPrefix(name, "/")
	if len(_bindata) > 0 {
		return Asset(path.Join(assetFS.nameSpace, name))
	}
	return assetFS.AssetFileSystem.Asset(name)
}

func (assetFS *nameSpacedBindataFS) Glob(pattern string) (matches []string, err error) {
	pattern = strings.Replace(pattern, "\\", "/", -1)
	if len(_bindata) > 0 {
		nameSpacedPattern := path.Join(assetFS.nameSpace, pattern)
		for key := range _bindata {
			if ok, err := path.Match(nameSpacedPattern, key); ok && err == nil {
				matches = append(matches, strings.TrimPrefix(key, assetFS.nameSpace))
			}
		}
		return matches, nil
	}

	return assetFS.AssetFileSystem.Glob(pattern)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant