windows: fix delete

This commit is contained in:
Michael Yang 2023-08-30 14:31:12 -04:00
parent eeb40a672c
commit ae950b00f1

View file

@ -859,17 +859,15 @@ func DeleteModel(name string) error {
if err != nil { if err != nil {
return err return err
} }
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 {
return err if info.IsDir() {
}
if !info.IsDir() {
path := path[len(fp)+1:]
slashIndex := strings.LastIndex(path, "/")
if slashIndex == -1 {
return nil 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}, ":")
fmp := ParseModelPath(tag) fmp := ParseModelPath(tag)
// skip the manifest we're trying to delete // skip the manifest we're trying to delete
@ -883,14 +881,16 @@ func DeleteModel(name string) error {
log.Printf("skipping file: %s", fp) log.Printf("skipping file: %s", fp)
return nil return nil
} }
for _, layer := range manifest.Layers { for _, layer := range manifest.Layers {
delete(deleteMap, layer.Digest) delete(deleteMap, layer.Digest)
} }
delete(deleteMap, manifest.Config.Digest) delete(deleteMap, manifest.Config.Digest)
}
return nil return nil
}) }
if err != nil {
if err := filepath.Walk(fp, walkFunc); err != nil {
return err return err
} }