fix list models for windows

This commit is contained in:
Michael Yang 2023-08-30 14:14:12 -04:00
parent 0f541a0367
commit eeb40a672c
2 changed files with 14 additions and 27 deletions

View file

@ -46,7 +46,7 @@ func ParseModelPath(name string) ModelPath {
name = after
}
parts := strings.Split(name, "/")
parts := strings.Split(name, string(os.PathSeparator))
switch len(parts) {
case 3:
mp.Registry = parts[0]

View file

@ -3,7 +3,6 @@ package server
import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"log"
@ -371,26 +370,12 @@ func ListModelsHandler(c *gin.Context) {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}
err = filepath.Walk(fp, func(path string, info os.FileInfo, err error) error {
if err != nil {
if errors.Is(err, os.ErrNotExist) {
log.Printf("manifest file does not exist: %s", fp)
return nil
}
return err
}
walkFunc := func(path string, info os.FileInfo, _ error) error {
if !info.IsDir() {
fi, err := os.Stat(path)
if err != nil {
log.Printf("skipping file: %s", fp)
return nil
}
path := path[len(fp)+1:]
slashIndex := strings.LastIndex(path, "/")
if slashIndex == -1 {
return nil
}
tag := path[:slashIndex] + ":" + path[slashIndex+1:]
dir, file := filepath.Split(path)
dir = strings.Trim(strings.TrimPrefix(dir, fp), string(os.PathSeparator))
tag := strings.Join([]string{dir, file}, ":")
mp := ParseModelPath(tag)
manifest, digest, err := GetManifest(mp)
@ -398,17 +383,19 @@ func ListModelsHandler(c *gin.Context) {
log.Printf("skipping file: %s", fp)
return nil
}
model := api.ModelResponse{
models = append(models, api.ModelResponse{
Name: mp.GetShortTagname(),
Size: manifest.GetTotalSize(),
Digest: digest,
ModifiedAt: fi.ModTime(),
}
models = append(models, model)
}
return nil
ModifiedAt: info.ModTime(),
})
if err != nil {
}
return nil
}
if err := filepath.Walk(fp, walkFunc); err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}