From 3b146588c6cfb6caaac37c5eb7edbe99225888de Mon Sep 17 00:00:00 2001 From: WithoutPants <53250216+WithoutPants@users.noreply.github.com> Date: Thu, 30 May 2024 15:50:27 +1000 Subject: [PATCH] Fix ffmpeg resolution when in current directory (#4899) * Use absolute path to resolve ffmpeg in config directory * Pass absolute config path to plugins --- internal/api/resolver_mutation_configure.go | 2 +- internal/manager/config/config.go | 14 ++++++++++++++ internal/manager/init.go | 4 +++- pkg/plugin/plugins.go | 4 ++-- 4 files changed, 20 insertions(+), 4 deletions(-) diff --git a/internal/api/resolver_mutation_configure.go b/internal/api/resolver_mutation_configure.go index b6ffd5a49..34b627b3c 100644 --- a/internal/api/resolver_mutation_configure.go +++ b/internal/api/resolver_mutation_configure.go @@ -27,7 +27,7 @@ func (r *mutationResolver) Setup(ctx context.Context, input manager.SetupInput) func (r *mutationResolver) DownloadFFMpeg(ctx context.Context) (string, error) { mgr := manager.GetInstance() - configDir := mgr.Config.GetConfigPath() + configDir := mgr.Config.GetConfigPathAbs() // don't run if ffmpeg is already installed ffmpegPath := ffmpeg.FindFFMpeg(configDir) diff --git a/internal/manager/config/config.go b/internal/manager/config/config.go index 5c6f94bb1..f67726219 100644 --- a/internal/manager/config/config.go +++ b/internal/manager/config/config.go @@ -496,6 +496,20 @@ func (i *Config) GetConfigPath() string { return filepath.Dir(i.GetConfigFile()) } +// GetConfigPathAbs returns the path of the directory containing the used +// configuration file, resolved to an absolute path. Returns the return value +// of GetConfigPath if the path cannot be made into an absolute path. +func (i *Config) GetConfigPathAbs() string { + p := filepath.Dir(i.GetConfigFile()) + + ret, _ := filepath.Abs(p) + if ret == "" { + return p + } + + return ret +} + // GetDefaultDatabaseFilePath returns the default database filename, // which is located in the same directory as the config file. func (i *Config) GetDefaultDatabaseFilePath() string { diff --git a/internal/manager/init.go b/internal/manager/init.go index ca6c8d042..347d08a15 100644 --- a/internal/manager/init.go +++ b/internal/manager/init.go @@ -260,7 +260,9 @@ func (s *Manager) writeStashIcon() { func (s *Manager) RefreshFFMpeg(ctx context.Context) { // use same directory as config path - configDirectory := s.Config.GetConfigPath() + // executing binaries requires directory to be included + // https://pkg.go.dev/os/exec#hdr-Executables_in_the_current_directory + configDirectory := s.Config.GetConfigPathAbs() stashHomeDir := paths.GetStashHomeDirectory() // prefer the configured paths diff --git a/pkg/plugin/plugins.go b/pkg/plugin/plugins.go index 0a44ca000..38cde68bc 100644 --- a/pkg/plugin/plugins.go +++ b/pkg/plugin/plugins.go @@ -91,7 +91,7 @@ type PluginSetting struct { type ServerConfig interface { GetHost() string GetPort() int - GetConfigPath() string + GetConfigPathAbs() string HasTLSConfig() bool GetPluginsPath() string GetDisabledPlugins() []string @@ -249,7 +249,7 @@ func (c Cache) makeServerConnection(ctx context.Context) common.StashServerConne Host: c.config.GetHost(), Port: c.config.GetPort(), SessionCookie: cookie, - Dir: c.config.GetConfigPath(), + Dir: c.config.GetConfigPathAbs(), } if c.config.HasTLSConfig() {