aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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
}