From 32f03ab149d100c36a379365b0f50f067cc66093 Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Sat, 1 Feb 2020 23:07:20 +0100 Subject: [PATCH] Backend: Run multiple instances of Sips --- internal/photoprism/convert.go | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/internal/photoprism/convert.go b/internal/photoprism/convert.go index d5b7c90da..fe832066a 100644 --- a/internal/photoprism/convert.go +++ b/internal/photoprism/convert.go @@ -88,26 +88,29 @@ func (c *Convert) Start(path string) error { } // ConvertCommand returns the command for converting files to JPEG, depending on the format. -func (c *Convert) ConvertCommand(image *MediaFile, jpegName string, xmpName string) (result *exec.Cmd, err error) { +func (c *Convert) ConvertCommand(image *MediaFile, jpegName string, xmpName string) (result *exec.Cmd, useMutex bool, err error) { if image.IsRaw() { if c.conf.SipsBin() != "" { result = exec.Command(c.conf.SipsBin(), "-s", "format", "jpeg", "--out", jpegName, image.fileName) } else if c.conf.DarktableBin() != "" { + // Only one instance of darktable-cli allowed due to locking + useMutex = true + if xmpName != "" { result = exec.Command(c.conf.DarktableBin(), image.fileName, xmpName, jpegName) } else { result = exec.Command(c.conf.DarktableBin(), image.fileName, jpegName) } } else { - return nil, fmt.Errorf("convert: no binary for raw to jpeg could be found (%s)", image.FileName()) + return nil, useMutex, fmt.Errorf("convert: no raw to jpeg converter installed (%s)", image.Base()) } } else if image.IsHEIF() { result = exec.Command(c.conf.HeifConvertBin(), image.fileName, jpegName) } else { - return nil, fmt.Errorf("convert: image type not supported for conversion (%s)", image.Type()) + return nil, useMutex, fmt.Errorf("convert: image type not supported for conversion (%s)", image.Type()) } - return result, nil + return result, useMutex, nil } // ToJpeg converts a single image file to JPEG if possible. @@ -161,7 +164,7 @@ func (c *Convert) ToJpeg(image *MediaFile) (*MediaFile, error) { return NewMediaFile(jpegName) } - cmd, err := c.ConvertCommand(image, jpegName, xmpName) + cmd, useMutex, err := c.ConvertCommand(image, jpegName, xmpName) if err != nil { return nil, err @@ -171,10 +174,12 @@ func (c *Convert) ToJpeg(image *MediaFile) (*MediaFile, error) { runtime.LockOSThread() defer runtime.UnlockOSThread() - // Make sure only one command is executed at a time. - // See https://photo.stackexchange.com/questions/105969/darktable-cli-fails-because-of-locked-database-file - c.cmdMutex.Lock() - defer c.cmdMutex.Unlock() + if useMutex { + // Make sure only one command is executed at a time. + // See https://photo.stackexchange.com/questions/105969/darktable-cli-fails-because-of-locked-database-file + c.cmdMutex.Lock() + defer c.cmdMutex.Unlock() + } // Fetch command output. var out bytes.Buffer