From 6d767a92a5e87302224b4764c3fc92dc32b6dbdc Mon Sep 17 00:00:00 2001 From: Rabeya Noor Date: Mon, 21 Sep 2026 23:34:16 +0600 Subject: [PATCH] parser: treat unmatched wildcard FROM paths as missing on Windows Fixes #18568 --- parser/parser.go | 12 ++++++++++++ parser/parser_test.go | 17 +++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/parser/parser.go b/parser/parser.go index 5ca018f56..9557eb6e6 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -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 } diff --git a/parser/parser_test.go b/parser/parser_test.go index 0257c03c3..048431445 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -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 {