This commit is contained in:
rabeyanoor 2026-10-12 08:47:43 +02:00 • committed by GitHub
commit 951bed95bd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 29 additions and 0 deletions

View file

@ -248,11 +248,23 @@ func canonicalLocalPath(path string) (string, error) {
return filepath.EvalSymlinks(abs)
}
// hasWildcard reports whether path has a glob wildcard outside its volume
// name, which may legitimately contain "?" (e.g. \\?\C:\).
func hasWildcard(path string) bool {
return strings.ContainsAny(path[len(filepath.VolumeName(path)):], "*?")
}
func fileDigestMap(path string) (map[string]string, error) {
fl := make(map[string]string)
fi, err := os.Stat(path)
if err != nil {
// Windows rejects wildcard characters in os.Stat with an invalid
// name error rather than ErrNotExist. A pattern that reaches here
// matched nothing, so report it as missing like other platforms do.
if runtime.GOOS == "windows" && hasWildcard(path) {
return nil, fmt.Errorf("%w: %s", os.ErrNotExist, path)
}
return nil, err
}

View file

@ -1005,6 +1005,23 @@ func TestCreateRequestFileGlobNoMatchUsesModelName(t *testing.T) {
}
}
func TestHasWildcard(t *testing.T) {
for _, tt := range []struct {
path string
want bool
}{
{"model.gguf", false},
{"model-*.gguf", true},
{"model-?.gguf", true},
{filepath.Join("dir", "*.gguf"), true},
{filepath.Join("dir", "model.gguf"), false},
} {
if got := hasWildcard(tt.path); got != tt.want {
t.Errorf("hasWildcard(%q) = %v, want %v", tt.path, got, tt.want)
}
}
}
func TestCreateRequestFileGlobRejectsBadPattern(t *testing.T) {
modelfile, err := ParseFile(strings.NewReader("FROM [\n"))
if err != nil {