mirror of
https://github.com/navidrome/navidrome.git
synced 2026-08-01 07:21:17 +00:00
A library configured with a file:// path stored absRoot as the raw URI, so Abs produced strings like file:/music/cover.jpg that os.Open/os.Stat reject — folder, upload and embedded art were treated as dangling on every request, looping forever. Normalize a file:// path to its parsed OS path (the same root os.DirFS uses); non-local schemes are left unchanged (out of scope, per the artwork-musicfs TODO).
53 lines
1.6 KiB
Go
53 lines
1.6 KiB
Go
package artwork
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/navidrome/navidrome/core/storage/storagetest"
|
|
"github.com/navidrome/navidrome/model"
|
|
"github.com/navidrome/navidrome/tests"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("loadLibraryView", Ordered, func() {
|
|
var ctx context.Context
|
|
var ds *tests.MockDataStore
|
|
|
|
BeforeAll(func() {
|
|
storagetest.Register("fake", &storagetest.FakeFS{})
|
|
})
|
|
|
|
BeforeEach(func() {
|
|
ctx = GinkgoT().Context()
|
|
ds = &tests.MockDataStore{MockedLibrary: &tests.MockLibraryRepo{}}
|
|
})
|
|
|
|
It("returns a view for a library backed by registered storage", func() {
|
|
Expect(ds.Library(ctx).Put(&model.Library{ID: 1, Path: "fake:///music"})).To(Succeed())
|
|
|
|
lib, err := loadLibraryView(ctx, ds, 1)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(lib.FS).ToNot(BeNil())
|
|
Expect(lib.absRoot).To(Equal("fake:///music"))
|
|
})
|
|
|
|
It("normalizes a library path to an OS root that Abs can join for os.Open/os.Stat", func() {
|
|
// file:// URLs become their parsed OS path; bare paths and non-local schemes are unchanged.
|
|
Expect(localOSRoot("file:///music/library")).To(Equal("/music/library"))
|
|
Expect(localOSRoot("/music/library")).To(Equal("/music/library"))
|
|
Expect(localOSRoot("fake:///music")).To(Equal("fake:///music"))
|
|
})
|
|
|
|
It("returns an error when the library does not exist", func() {
|
|
_, err := loadLibraryView(ctx, ds, 999)
|
|
Expect(err).To(HaveOccurred())
|
|
})
|
|
|
|
It("returns an error when the library path uses an unregistered scheme", func() {
|
|
Expect(ds.Library(ctx).Put(&model.Library{ID: 2, Path: "unsupported:///music"})).To(Succeed())
|
|
_, err := loadLibraryView(ctx, ds, 2)
|
|
Expect(err).To(HaveOccurred())
|
|
})
|
|
})
|