Backend: Run multiple instances of Sips
This commit is contained in:
parent
c02b7ed65b
commit
32f03ab149
1 changed files with 14 additions and 9 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue