aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGabriel Arakaki Giovanini <mail@gabrielgio.me>2023-06-23 23:37:57 +0200
committerGabriel Arakaki Giovanini <mail@gabrielgio.me>2023-06-23 23:37:57 +0200
commitcff5600c8abebd1ce988b2185c07e998c4a1d483 (patch)
tree870a9ddf845788c63665e339f2de67ea2707cd14
parent1dea35b9bcb3d37d61e554a99488626da9795331 (diff)
downloadlens-cff5600c8abebd1ce988b2185c07e998c4a1d483.tar.gz
lens-cff5600c8abebd1ce988b2185c07e998c4a1d483.tar.bz2
lens-cff5600c8abebd1ce988b2185c07e998c4a1d483.zip
fix: Wrap media scan into a go routine
For some unknown reason `ReadExif` hangs when the context is canceled through signal handling. Perhaps perl-exif tooling is closing on `SIGNINT`.
-rw-r--r--pkg/worker/exif_scanner.go27
1 files changed, 26 insertions, 1 deletions
diff --git a/pkg/worker/exif_scanner.go b/pkg/worker/exif_scanner.go
index 6d40dbd..d7865e3 100644
--- a/pkg/worker/exif_scanner.go
+++ b/pkg/worker/exif_scanner.go
@@ -33,8 +33,33 @@ func (e *EXIFScanner) Query(ctx context.Context) ([]*media.Media, error) {
return medias, nil
}
+func wrapReadExif(ctx context.Context, path string) (*media.MediaEXIF, error) {
+ c := make(chan *media.MediaEXIF)
+ e := make(chan error)
+ go func() {
+ defer close(c)
+ defer close(e)
+
+ newExif, err := fileop.ReadExif(path)
+ if err != nil {
+ e <- err
+ } else {
+ c <- newExif
+ }
+ }()
+
+ select {
+ case <-ctx.Done():
+ return nil, ctx.Err()
+ case m := <-c:
+ return m, nil
+ case err := <-e:
+ return nil, err
+ }
+}
+
func (e *EXIFScanner) Process(ctx context.Context, m *media.Media) error {
- newExif, err := fileop.ReadExif(m.Path)
+ newExif, err := wrapReadExif(ctx, m.Path)
if err != nil {
return err
}