diff --git a/Dockerfile b/Dockerfile index 0cb0b38ca..a403fe2df 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM photoprism/development:20200113 +FROM photoprism/development:20200117 # Set up project directory WORKDIR "/go/src/github.com/photoprism/photoprism" diff --git a/Makefile b/Makefile index a6aa0419f..ff863e9cc 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/docker/development/Dockerfile b/docker/development/Dockerfile index b70e46069..a70f54d9e 100644 --- a/docker/development/Dockerfile +++ b/docker/development/Dockerfile @@ -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 && \ diff --git a/docker/photoprism/Dockerfile b/docker/photoprism/Dockerfile index 0fccb15e5..b19bbfc37 100644 --- a/docker/photoprism/Dockerfile +++ b/docker/photoprism/Dockerfile @@ -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 && \ diff --git a/internal/photoprism/convert.go b/internal/photoprism/convert.go index 8b19cbf9e..8e600ff6d 100644 --- a/internal/photoprism/convert.go +++ b/internal/photoprism/convert.go @@ -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" @@ -15,7 +18,8 @@ import ( // Convert represents a converter that can convert RAW/HEIF images to JPEG. type Convert struct { - conf *config.Config + 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) } diff --git a/internal/photoprism/import_worker.go b/internal/photoprism/import_worker.go index 1281d4e78..92fa6b14d 100644 --- a/internal/photoprism/import_worker.go +++ b/internal/photoprism/import_worker.go @@ -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()) } }