mirror of
https://github.com/ollama/ollama.git
synced 2026-10-20 18:41:17 +00:00
Merge 6d767a92a5 into c1c536297f
This commit is contained in:
commit
951bed95bd
2 changed files with 29 additions and 0 deletions
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue