🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
Move `TempFileName` to `utils`
Deluanfa72aaa4624b
diff --git a/core/playback/mpv/mpv.go b/core/playback/mpv/mpv.goindex 957d779ce..8b10c5b91 100644--- a/core/playback/mpv/mpv.go+++ b/core/playback/mpv/mpv.go@@ -2,14 +2,11 @@ package mpvimport ("context"- "crypto/rand"- "encoding/hex""errors""fmt""io""os""os/exec"- "path/filepath""strings""sync"@@ -133,10 +130,3 @@ var (mpvPath stringmpvErr error)--func TempFileName(prefix, suffix string) string {- randBytes := make([]byte, 16)- // we can savely ignore the return value since we're loading into a precreated, fixedsized buffer- _, _ = rand.Read(randBytes)- return filepath.Join(os.TempDir(), prefix+hex.EncodeToString(randBytes)+suffix)-}diff --git a/core/playback/mpv/track.go b/core/playback/mpv/track.goindex fc012044b..e0578b40d 100644--- a/core/playback/mpv/track.go+++ b/core/playback/mpv/track.go@@ -13,6 +13,7 @@ import ("github.com/dexterlb/mpvipc""github.com/navidrome/navidrome/log""github.com/navidrome/navidrome/model"+ "github.com/navidrome/navidrome/utils")type MpvTrack struct {@@ -31,7 +32,7 @@ func NewTrack(playbackDoneChannel chan bool, deviceName string, mf model.MediaFireturn nil, err}- tmpSocketName := TempFileName("mpv-ctrl-", ".socket")+ tmpSocketName := utils.TempFileName("mpv-ctrl-", ".socket")args := createMPVCommand(mpvComdTemplate, deviceName, mf.Path, tmpSocketName)exe, err := start(args)diff --git a/scanner/metadata/taglib/taglib_test.go b/scanner/metadata/taglib/taglib_test.goindex 29d9938fb..310079101 100644--- a/scanner/metadata/taglib/taglib_test.go+++ b/scanner/metadata/taglib/taglib_test.go@@ -4,8 +4,8 @@ import ("io/fs""os"- "github.com/navidrome/navidrome/core/playback/mpv""github.com/navidrome/navidrome/scanner/metadata"+ "github.com/navidrome/navidrome/utils". "github.com/onsi/ginkgo/v2". "github.com/onsi/gomega")@@ -181,7 +181,7 @@ var _ = Describe("Extractor", func() {// Only run permission tests if we are not rootRegularUserContext("when run without root privileges", func() {BeforeEach(func() {- accessForbiddenFile = mpv.TempFileName("access_forbidden", ".mp3")+ accessForbiddenFile = utils.TempFileName("access_forbidden-", ".mp3")f, err := os.OpenFile(accessForbiddenFile, os.O_WRONLY|os.O_CREATE, 0222)Expect(err).ToNot(HaveOccurred())diff --git a/utils/files.go b/utils/files.gonew file mode 100644index 000000000..293aba941--- /dev/null+++ b/utils/files.go@@ -0,0 +1,12 @@+package utils++import (+ "os"+ "path/filepath"++ "github.com/google/uuid"+)++func TempFileName(prefix, suffix string) string {+ return filepath.Join(os.TempDir(), prefix+uuid.NewString()+suffix)+}