bug(core/playback/mpv): jukebox mode under windows - navidrome#2767
Create SocketName function for both platforms, restore name of TempFileName Signed-off-by: apkatsikas <apkatsikas@gmail.com>
This commit is contained in:
parent
f066adcbfc
commit
e7186a4d6c
|
@ -0,0 +1,9 @@
|
|||
//go:build !windows
|
||||
|
||||
package mpv
|
||||
|
||||
import "github.com/navidrome/navidrome/utils"
|
||||
|
||||
func SocketName(prefix, suffix string) string {
|
||||
return utils.TempFileName(prefix, suffix)
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
//go:build windows
|
||||
|
||||
package mpv
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func SocketName() string {
|
||||
// Windows needs to use a named pipe for the socket
|
||||
// see https://mpv.io/manual/master#using-mpv-from-other-programs-or-scripts
|
||||
return filepath.Join(`\\.\pipe\mpvsocket`, prefix+uuid.NewString()+suffix)
|
||||
}
|
|
@ -32,7 +32,7 @@ func NewTrack(playbackDoneChannel chan bool, deviceName string, mf model.MediaFi
|
|||
return nil, err
|
||||
}
|
||||
|
||||
tmpSocketName := utils.RandomSocketOrFileName("mpv-ctrl-", ".socket")
|
||||
tmpSocketName := utils.TempFileName("mpv-ctrl-", ".socket")
|
||||
|
||||
args := createMPVCommand(mpvComdTemplate, deviceName, mf.Path, tmpSocketName)
|
||||
exe, err := start(args)
|
||||
|
|
|
@ -181,7 +181,7 @@ var _ = Describe("Extractor", func() {
|
|||
// Only run permission tests if we are not root
|
||||
RegularUserContext("when run without root privileges", func() {
|
||||
BeforeEach(func() {
|
||||
accessForbiddenFile = utils.RandomSocketOrFileName("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())
|
||||
|
|
|
@ -3,17 +3,10 @@ package utils
|
|||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
func RandomSocketOrFileName(prefix, suffix string) string {
|
||||
socketPath := os.TempDir()
|
||||
// Windows needs to use a named pipe instead of a file for the socket
|
||||
// see https://mpv.io/manual/master#using-mpv-from-other-programs-or-scripts
|
||||
if runtime.GOOS == "windows" {
|
||||
socketPath = `\\.\pipe\mpvsocket`
|
||||
}
|
||||
return filepath.Join(socketPath, prefix+uuid.NewString()+suffix)
|
||||
func TempFileName(prefix, suffix string) string {
|
||||
return filepath.Join(os.TempDir(), prefix+uuid.NewString()+suffix)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue