Backend: Upgrade darktable and don't run more than one command at once #202

Signed-off-by: Michael Mayer <michael@liquidbytes.net>
This commit is contained in:
Michael Mayer 2020-01-17 01:37:06 +01:00
parent 7c4707903d
commit 64a16a27b0
6 changed files with 46 additions and 12 deletions

View file

@ -1,4 +1,4 @@
FROM photoprism/development:20200113
FROM photoprism/development:20200117
# Set up project directory
WORKDIR "/go/src/github.com/photoprism/photoprism"

View file

@ -137,8 +137,9 @@ lint-js:
(cd frontend && npm run lint)
fmt-js:
(cd frontend && npm run fmt)
fmt-go:
fmt-imports:
goimports -w pkg internal cmd
fmt-go:
go fmt ./pkg/... ./internal/... ./cmd/...
tidy:
go mod tidy

View file

@ -51,7 +51,8 @@ RUN apt-get update && apt-get upgrade && \
exiftool
# Install RAW to JPEG converter
RUN add-apt-repository ppa:pmjdebruijn/darktable-release && \
RUN sh -c "echo 'deb http://download.opensuse.org/repositories/graphics:/darktable:/master/xUbuntu_18.04/ /' > /etc/apt/sources.list.d/graphics:darktable:master.list" && \
wget -qO - https://download.opensuse.org/repositories/graphics:darktable:master/xUbuntu_18.04/Release.key | apt-key add - && \
apt-get update && \
apt-get install darktable && \
apt-get upgrade && \

View file

@ -1,4 +1,4 @@
FROM photoprism/development:20200113 as build
FROM photoprism/development:20200117 as build
# Set up project directory
WORKDIR "/go/src/github.com/photoprism/photoprism"
@ -27,12 +27,20 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
rm -rf /var/lib/apt/lists/*
# Copy dependencies
COPY --from=build /etc/apt/sources.list.d/pmjdebruijn-ubuntu-darktable-release-bionic.list /etc/apt/sources.list.d/pmjdebruijn-ubuntu-darktable-release-bionic.list
COPY --from=build /etc/apt/trusted.gpg.d/pmjdebruijn_ubuntu_darktable-release.gpg /etc/apt/trusted.gpg.d/pmjdebruijn_ubuntu_darktable-release.gpg
COPY --from=build /usr/lib/libtensorflow.so /usr/lib/libtensorflow.so
COPY --from=build /usr/lib/libtensorflow_framework.so /usr/lib/libtensorflow_framework.so
RUN ldconfig
# Install RAW to JPEG converter
RUN sh -c "echo 'deb http://download.opensuse.org/repositories/graphics:/darktable:/master/xUbuntu_18.04/ /' > /etc/apt/sources.list.d/graphics:darktable:master.list" && \
wget -qO - https://download.opensuse.org/repositories/graphics:darktable:master/xUbuntu_18.04/Release.key | apt-key add - && \
apt-get update && \
apt-get install darktable && \
apt-get upgrade && \
apt-get dist-upgrade && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# Install darktable (RAW to JPEG converter)
RUN apt-get update && \
apt-get install -y --no-install-recommends darktable && \

View file

@ -1,11 +1,14 @@
package photoprism
import (
"bytes"
"errors"
"fmt"
"os"
"os/exec"
"path/filepath"
"runtime"
"sync"
"github.com/photoprism/photoprism/internal/config"
"github.com/photoprism/photoprism/internal/event"
@ -16,6 +19,7 @@ import (
// Convert represents a converter that can convert RAW/HEIF images to JPEG.
type Convert struct {
conf *config.Config
cmdMutex sync.Mutex
}
// NewConvert returns a new converter and expects the config as argument.
@ -140,11 +144,31 @@ func (c *Convert) ToJpeg(image *MediaFile) (*MediaFile, error) {
return NewMediaFile(jpegFilename)
}
if convertCommand, err := c.ConvertCommand(image, jpegFilename, xmpFilename); err != nil {
return nil, err
} else if err := convertCommand.Run(); err != nil {
cmd, err := c.ConvertCommand(image, jpegFilename, xmpFilename)
if err != nil {
return nil, err
}
// Unclear if this is really necessary here, but safe is safe.
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()
// Fetch command output.
var out bytes.Buffer
var stderr bytes.Buffer
cmd.Stdout = &out
cmd.Stderr = &stderr
// Run convert command.
if err := cmd.Run(); err != nil {
return nil, errors.New(stderr.String())
}
return NewMediaFile(jpegFilename)
}

View file

@ -66,7 +66,7 @@ func importWorker(jobs <-chan ImportJob) {
if importedMainFile.IsRaw() || importedMainFile.IsHEIF() || importedMainFile.IsImageOther() {
if _, err := imp.convert.ToJpeg(importedMainFile); err != nil {
log.Errorf("import: could not create jpeg from \"%s\"", err)
log.Errorf("import: creating jpeg failed (%s)", err.Error())
}
}
@ -74,7 +74,7 @@ func importWorker(jobs <-chan ImportJob) {
log.Error(err)
} else {
if err := jpg.RenderDefaultThumbnails(imp.conf.ThumbnailsPath(), false); err != nil {
log.Errorf("import: could not create default thumbnails (%s)", err)
log.Errorf("import: could not create default thumbnails (%s)", err.Error())
}
}