From 81fb06f5307349244263a199d66eb30926a71d28 Mon Sep 17 00:00:00 2001 From: Michael Yang Date: Thu, 9 May 2024 10:00:18 -0700 Subject: [PATCH] more resilient Manifests --- server/manifest.go | 17 ++++++++++++++--- server/manifest_test.go | 4 ++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/server/manifest.go b/server/manifest.go index 41a96c55..a5251298 100644 --- a/server/manifest.go +++ b/server/manifest.go @@ -125,13 +125,24 @@ func Manifests() (map[model.Name]*Manifest, error) { ms := make(map[model.Name]*Manifest) for _, match := range matches { - rel, err := filepath.Rel(manifests, match) + fi, err := os.Stat(match) if err != nil { return nil, err } - n := model.ParseNameFromFilepath(rel) - if n.IsValid() { + if !fi.IsDir() { + 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) if err != nil { slog.Warn("bad manifest", "name", n, "error", err) diff --git a/server/manifest_test.go b/server/manifest_test.go index 35c6bc8d..4da86745 100644 --- a/server/manifest_test.go +++ b/server/manifest_test.go @@ -56,6 +56,10 @@ func TestManifests(t *testing.T) { filepath.Join("host", "namespace", "model", "tag"), 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 {