more resilient Manifests

This commit is contained in:
Michael Yang 2024-05-09 10:00:18 -07:00
parent a385382ff5
commit 81fb06f530
2 changed files with 18 additions and 3 deletions

View file

@ -125,13 +125,24 @@ func Manifests() (map[model.Name]*Manifest, error) {
ms := make(map[model.Name]*Manifest) ms := make(map[model.Name]*Manifest)
for _, match := range matches { for _, match := range matches {
rel, err := filepath.Rel(manifests, match) fi, err := os.Stat(match)
if err != nil { if err != nil {
return nil, err return nil, err
} }
n := model.ParseNameFromFilepath(rel) if !fi.IsDir() {
if n.IsValid() { rel, err := filepath.Rel(manifests, match)
if err != nil {
slog.Warn("bad filepath", "path", match, "error", err)
continue
}
n := model.ParseNameFromFilepath(rel)
if !n.IsValid() {
slog.Warn("bad manifest name", "path", rel, "error", err)
continue
}
m, err := ParseNamedManifest(n) m, err := ParseNamedManifest(n)
if err != nil { if err != nil {
slog.Warn("bad manifest", "name", n, "error", err) slog.Warn("bad manifest", "name", n, "error", err)

View file

@ -56,6 +56,10 @@ func TestManifests(t *testing.T) {
filepath.Join("host", "namespace", "model", "tag"), filepath.Join("host", "namespace", "model", "tag"),
filepath.Join("host", "namespace", "model", ".hidden"), filepath.Join("host", "namespace", "model", ".hidden"),
}, },
"subdir": {
filepath.Join("host", "namespace", "model", "tag", "one"),
filepath.Join("host", "namespace", "model", "tag", "another", "one"),
},
} }
for n, wants := range cases { for n, wants := range cases {