From 10283f9c0aa01308a5f55e9e5a790d0ed09214db Mon Sep 17 00:00:00 2001 From: Jesper Pedersen Date: Wed, 14 Oct 2026 14:47:09 +0200 Subject: [PATCH] fix: hide empty files in a config directory --- CHANGELOG.md | 2 ++ main.go | 2 ++ main_test.go | 27 +++++++++++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e072dc3..1a1ab39 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -35,3 +35,5 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 warning, and `task deps` and `task icon` no longer print spurious warnings. - `task deps` on Debian/Ubuntu installs the Wayland headers that current Fyne needs to build. +- Empty or comment-only files in a config directory, such as Docker bind-mount + placeholders, no longer show up as unmanaged services. diff --git a/main.go b/main.go index 031e256..42bb725 100644 --- a/main.go +++ b/main.go @@ -327,6 +327,8 @@ func listServices(target string, isFile bool) ([]Service, error) { doc, err := readDoc(filepath.Join(target, n)) if err != nil { log.Print(err) + } else if len(doc) == 0 { + continue // empty or comment-only, e.g. a bind-mount placeholder; unreadable files still get a row } svcs := extract(doc, n) if len(svcs) == 0 { diff --git a/main_test.go b/main_test.go index 5a71624..b01a3a4 100644 --- a/main_test.go +++ b/main_test.go @@ -107,3 +107,30 @@ func TestDisabledRoundTrip(t *testing.T) { t.Fatalf("re-enable: %+v", got) } } + +// Empty files (bind-mount placeholders) are hidden, but a broken file must stay visible: +// Traefik rejects the whole directory over it. +func TestListServicesDirectory(t *testing.T) { + dir := t.TempDir() + for name, body := range map[string]string{ + "placeholder.yaml": "# mount point only\n", + "empty.yml": "", + "broken.yml": "http: [\n", + "tls.yml": "tls:\n certificates: []\n", + } { + if err := os.WriteFile(filepath.Join(dir, name), []byte(body), 0o600); err != nil { + t.Fatal(err) + } + } + got, err := listServices(dir, false) + if err != nil { + t.Fatal(err) + } + var names []string + for _, s := range got { + names = append(names, s.Name) + } + if want := []string{"broken", "tls"}; !reflect.DeepEqual(names, want) { + t.Fatalf("listed %v, want %v", names, want) + } +}