Normalize library path before adding and improve error logging (#38)

I hope this PR closes #9

Co-authored-by: Heinrich Langos <gumbo2000@noreply@mills.io>
Reviewed-on: https://git.mills.io/prologic/tube/pulls/38
Co-authored-by: Heinrich 'Henrik' Langos <gumbo2000@noreply@mills.io>
Co-committed-by: Heinrich 'Henrik' Langos <gumbo2000@noreply@mills.io>
This commit is contained in:
Heinrich 'Henrik' Langos 2022-11-25 01:21:03 +00:00 committed by James Mills
parent efa00d1534
commit a2cc622bc9
2 changed files with 3 additions and 2 deletions

View file

@ -146,6 +146,7 @@ func NewApp(cfg *Config) (*App, error) {
// Run imports the library and starts server. // Run imports the library and starts server.
func (a *App) Run() error { func (a *App) Run() error {
for _, pc := range a.Config.Library { for _, pc := range a.Config.Library {
pc.Path = filepath.Clean(pc.Path)
p := &media.Path{ p := &media.Path{
Path: pc.Path, Path: pc.Path,
Prefix: pc.Prefix, Prefix: pc.Prefix,

View file

@ -35,10 +35,10 @@ func (lib *Library) AddPath(p *Path) error {
// make sure new path doesn't collide with existing ones // make sure new path doesn't collide with existing ones
for _, p2 := range lib.Paths { for _, p2 := range lib.Paths {
if p.Path == p2.Path { 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 { 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 { if err := os.MkdirAll(p.Path, 0755); err != nil {