summaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorNick White <git@njw.name>2020-09-22 16:45:28 +0100
committerNick White <git@njw.name>2020-09-22 16:45:28 +0100
commit217a766647da7fa56289c0146705fec6f8cfea05 (patch)
treef3c095169d477e28323a98527b45cf66c076a3e9 /cmd
parent2d9546fe42c85e9882ff3ec041de75f7048e7d3a (diff)
[booktopipeline] Check that all images are valid before adding to pipeline
Diffstat (limited to 'cmd')
-rw-r--r--cmd/booktopipeline/main.go24
1 files changed, 24 insertions, 0 deletions
diff --git a/cmd/booktopipeline/main.go b/cmd/booktopipeline/main.go
index 9d4e55f..62e4132 100644
--- a/cmd/booktopipeline/main.go
+++ b/cmd/booktopipeline/main.go
@@ -9,6 +9,9 @@ package main
import (
"flag"
"fmt"
+ "image"
+ _ "image/png"
+ _ "image/jpeg"
"log"
"os"
"path/filepath"
@@ -126,6 +129,27 @@ func main() {
qid = conn.PreQueueId()
}
+ verboselog.Println("Checking that all images are valid in", bookdir)
+ checker := make(fileWalk)
+ go func() {
+ err = filepath.Walk(bookdir, checker.Walk)
+ if err != nil {
+ log.Fatalln("Filesystem walk failed:", err)
+ }
+ close(checker)
+ }()
+
+ for path := range checker {
+ f, err := os.Open(path)
+ if err != nil {
+ log.Fatalln("Opening image %s failed, bailing: %v", path, err)
+ }
+ _, _, err = image.Decode(f)
+ if err != nil {
+ log.Fatalf("Decoding image %s failed, bailing: %v", path, err)
+ }
+ }
+
verboselog.Println("Walking", bookdir)
walker := make(fileWalk)
go func() {