ollama/server/fixblobs.go
Blake Mizerany 703684a82a
server: replace blob prefix separator from ':' to '-' (#3146)
This fixes issues with blob file names that contain ':' characters to be rejected by file systems that do not support them.
2024-03-14 20:18:06 -07:00

26 lines
598 B
Go

package server
import (
"os"
"path/filepath"
"strings"
)
// fixBlobs walks the provided dir and replaces (":") to ("-") in the file
// prefix. (e.g. sha256:1234 -> sha256-1234)
func fixBlobs(dir string) error {
return filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
if err != nil {
return err
}
baseName := filepath.Base(path)
typ, sha, ok := strings.Cut(baseName, ":")
if ok && typ == "sha256" {
newPath := filepath.Join(filepath.Dir(path), typ+"-"+sha)
if err := os.Rename(path, newPath); err != nil {
return err
}
}
return nil
})
}