Convert: Set explicit LD_LIBRARY_PATH for external tools #2726

Signed-off-by: Michael Mayer <michael@photoprism.app>
This commit is contained in:
Michael Mayer 2022-10-26 18:51:28 +02:00
parent 73d987ec9f
commit 7723e6b32f
4 changed files with 24 additions and 3 deletions

View file

@ -414,11 +414,20 @@ func (c *Config) CachePath() string {
return fs.Abs(c.options.CachePath)
}
// CmdCachePath returns a path that CLI commands can use as cache directory.
// CmdCachePath returns a path that external CLI tools can use as cache directory.
func (c *Config) CmdCachePath() string {
return filepath.Join(c.CachePath(), "cmd")
}
// CmdLibPath returns the dynamic loader path that external CLI tools should use.
func (c *Config) CmdLibPath() string {
if dir := os.Getenv("LD_LIBRARY_PATH"); dir != "" {
return dir
}
return "/usr/local/lib:/usr/lib"
}
// ThumbCachePath returns the thumbnail storage directory.
func (c *Config) ThumbCachePath() string {
return c.CachePath() + "/thumbnails"

View file

@ -133,6 +133,15 @@ func TestConfig_CmdCachePath(t *testing.T) {
}
}
func TestConfig_CmdLibPath(t *testing.T) {
c := NewConfig(CliTestContext())
if dir := c.CmdLibPath(); dir == "" {
t.Fatal("cmd lib path is empty")
} else if !strings.HasPrefix(dir, "/usr") {
t.Fatalf("unexpected cmd lib path: %s", dir)
}
}
func TestConfig_CachePath2(t *testing.T) {
c := NewConfig(CliTestContext())
assert.Equal(t, "/go/src/github.com/photoprism/photoprism/storage/testdata/cache", c.CachePath())

View file

@ -110,7 +110,10 @@ func (c *Convert) ToJpeg(f *MediaFile, force bool) (*MediaFile, error) {
var stderr bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &stderr
cmd.Env = []string{fmt.Sprintf("HOME=%s", c.conf.CmdCachePath())}
cmd.Env = []string{
fmt.Sprintf("HOME=%s", c.conf.CmdCachePath()),
fmt.Sprintf("LD_LIBRARY_PATH=%s", c.conf.CmdLibPath()),
}
log.Infof("convert: converting %s to %s (%s)", clean.Log(filepath.Base(fileName)), clean.Log(filepath.Base(jpegName)), filepath.Base(cmd.Path))

View file

@ -2,7 +2,7 @@
set -e
DESTDIR=$(realpath "${1:-/usr}")
DESTDIR=$(realpath "${1:-/usr/local}")
LIBHEIF_VERSION=${2:-v1.13.0}
SYSTEM_ARCH=$("$(dirname "$0")/arch.sh")
DESTARCH=${DESTARCH:-$SYSTEM_ARCH}