From a2cc622bc9028e3fabf6ca8d662c8ab4a327cdf7 Mon Sep 17 00:00:00 2001 From: Heinrich 'Henrik' Langos Date: Fri, 25 Nov 2022 01:21:03 +0000 Subject: [PATCH] Normalize library path before adding and improve error logging (#38) I hope this PR closes #9 Co-authored-by: Heinrich Langos Reviewed-on: https://git.mills.io/prologic/tube/pulls/38 Co-authored-by: Heinrich 'Henrik' Langos Co-committed-by: Heinrich 'Henrik' Langos --- app/app.go | 1 + media/library.go | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/app.go b/app/app.go index 69811eb..37114b2 100644 --- a/app/app.go +++ b/app/app.go @@ -146,6 +146,7 @@ func NewApp(cfg *Config) (*App, error) { // Run imports the library and starts server. func (a *App) Run() error { for _, pc := range a.Config.Library { + pc.Path = filepath.Clean(pc.Path) p := &media.Path{ Path: pc.Path, Prefix: pc.Prefix, diff --git a/media/library.go b/media/library.go index 7de68e0..0657847 100644 --- a/media/library.go +++ b/media/library.go @@ -35,10 +35,10 @@ func (lib *Library) AddPath(p *Path) error { // make sure new path doesn't collide with existing ones for _, p2 := range lib.Paths { if p.Path == p2.Path { - return errors.New("media: duplicate library path") + return errors.New(fmt.Sprintf("media: duplicate (normalized) library path '%s'", p.Path)) } if p.Prefix == p2.Prefix { - return errors.New("media: duplicate library prefix") + return errors.New(fmt.Sprintf("media: duplicate library prefix '%s'", p.Prefix)) } } if err := os.MkdirAll(p.Path, 0755); err != nil {