diff --git a/resources/embed.go b/resources/embed.go index 5c476e87f..3b2d64894 100644 --- a/resources/embed.go +++ b/resources/embed.go @@ -8,7 +8,7 @@ import ( "sync" "github.com/navidrome/navidrome/conf" - "github.com/navidrome/navidrome/utils" + "github.com/navidrome/navidrome/utils/merge" ) var ( @@ -20,7 +20,7 @@ var ( func FS() fs.FS { fsOnce.Do(func() { - fsys = utils.MergeFS{ + fsys = merge.FS{ Base: embedFS, Overlay: os.DirFS(path.Join(conf.Server.DataFolder, "resources")), } diff --git a/utils/merge_fs.go b/utils/merge/merge_fs.go similarity index 87% rename from utils/merge_fs.go rename to utils/merge/merge_fs.go index b1586e9d6..e7d6c596a 100644 --- a/utils/merge_fs.go +++ b/utils/merge/merge_fs.go @@ -1,4 +1,4 @@ -package utils +package merge import ( "errors" @@ -7,15 +7,15 @@ import ( "sort" ) -// MergeFS implements a simple merged fs.FS, that can combine a Base FS with an Overlay FS. The semantics are: +// FS implements a simple merged fs.FS, that can combine a Base FS with an Overlay FS. The semantics are: // - Files from the Overlay FS will override files with the same name in the Base FS // - Directories are combined, with priority for the Overlay FS over the Base FS for files with matching names -type MergeFS struct { +type FS struct { Base fs.FS Overlay fs.FS } -func (m MergeFS) Open(name string) (fs.File, error) { +func (m FS) Open(name string) (fs.File, error) { file, err := m.Overlay.Open(name) if err != nil { return m.Base.Open(name) @@ -43,7 +43,7 @@ func (m MergeFS) Open(name string) (fs.File, error) { return m.mergeDirs(name, info, baseDirFile, overlayDirFile) } -func (m MergeFS) mergeDirs(name string, info fs.FileInfo, baseDir fs.ReadDirFile, overlayDir fs.ReadDirFile) (fs.File, error) { +func (m FS) mergeDirs(name string, info fs.FileInfo, baseDir fs.ReadDirFile, overlayDir fs.ReadDirFile) (fs.File, error) { merged := map[string]fs.DirEntry{} baseFiles, err := baseDir.ReadDir(-1) diff --git a/utils/merge_fs_test.go b/utils/merge/merge_fs_test.go similarity index 93% rename from utils/merge_fs_test.go rename to utils/merge/merge_fs_test.go index bdf443205..e0cc18125 100644 --- a/utils/merge_fs_test.go +++ b/utils/merge/merge_fs_test.go @@ -1,4 +1,4 @@ -package utils_test +package merge_test import ( "io" @@ -6,12 +6,12 @@ import ( "os" "path/filepath" - "github.com/navidrome/navidrome/utils" + "github.com/navidrome/navidrome/utils/merge" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) -var _ = Describe("MergeFS", func() { +var _ = Describe("FS", func() { var baseName, overlayName string var mergedDir fs.FS @@ -20,7 +20,7 @@ var _ = Describe("MergeFS", func() { overlayName, _ = os.MkdirTemp("", "merge_fs_overlay_test") baseDir := os.DirFS(baseName) overlayDir := os.DirFS(overlayName) - mergedDir = utils.MergeFS{Base: baseDir, Overlay: overlayDir} + mergedDir = merge.FS{Base: baseDir, Overlay: overlayDir} }) AfterEach(func() { _ = os.RemoveAll(baseName)