Skip to content

bug in bindatafs on windows #6

@sugacube

Description

@sugacube

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)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions