fix list models for windows
This commit is contained in:
parent
0f541a0367
commit
eeb40a672c
2 changed files with 14 additions and 27 deletions
|
@ -46,7 +46,7 @@ func ParseModelPath(name string) ModelPath {
|
||||||
name = after
|
name = after
|
||||||
}
|
}
|
||||||
|
|
||||||
parts := strings.Split(name, "/")
|
parts := strings.Split(name, string(os.PathSeparator))
|
||||||
switch len(parts) {
|
switch len(parts) {
|
||||||
case 3:
|
case 3:
|
||||||
mp.Registry = parts[0]
|
mp.Registry = parts[0]
|
||||||
|
|
|
@ -3,7 +3,6 @@ package server
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
@ -371,26 +370,12 @@ func ListModelsHandler(c *gin.Context) {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = filepath.Walk(fp, func(path string, info os.FileInfo, err error) error {
|
|
||||||
if err != nil {
|
walkFunc := func(path string, info os.FileInfo, _ error) error {
|
||||||
if errors.Is(err, os.ErrNotExist) {
|
|
||||||
log.Printf("manifest file does not exist: %s", fp)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if !info.IsDir() {
|
if !info.IsDir() {
|
||||||
fi, err := os.Stat(path)
|
dir, file := filepath.Split(path)
|
||||||
if err != nil {
|
dir = strings.Trim(strings.TrimPrefix(dir, fp), string(os.PathSeparator))
|
||||||
log.Printf("skipping file: %s", fp)
|
tag := strings.Join([]string{dir, file}, ":")
|
||||||
return nil
|
|
||||||
}
|
|
||||||
path := path[len(fp)+1:]
|
|
||||||
slashIndex := strings.LastIndex(path, "/")
|
|
||||||
if slashIndex == -1 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
tag := path[:slashIndex] + ":" + path[slashIndex+1:]
|
|
||||||
|
|
||||||
mp := ParseModelPath(tag)
|
mp := ParseModelPath(tag)
|
||||||
manifest, digest, err := GetManifest(mp)
|
manifest, digest, err := GetManifest(mp)
|
||||||
|
@ -398,17 +383,19 @@ func ListModelsHandler(c *gin.Context) {
|
||||||
log.Printf("skipping file: %s", fp)
|
log.Printf("skipping file: %s", fp)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
model := api.ModelResponse{
|
|
||||||
|
models = append(models, api.ModelResponse{
|
||||||
Name: mp.GetShortTagname(),
|
Name: mp.GetShortTagname(),
|
||||||
Size: manifest.GetTotalSize(),
|
Size: manifest.GetTotalSize(),
|
||||||
Digest: digest,
|
Digest: digest,
|
||||||
ModifiedAt: fi.ModTime(),
|
ModifiedAt: info.ModTime(),
|
||||||
}
|
})
|
||||||
models = append(models, model)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
}
|
||||||
if err != nil {
|
|
||||||
|
if err := filepath.Walk(fp, walkFunc); err != nil {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue