From 217a766647da7fa56289c0146705fec6f8cfea05 Mon Sep 17 00:00:00 2001 From: Nick White Date: Tue, 22 Sep 2020 16:45:28 +0100 Subject: [booktopipeline] Check that all images are valid before adding to pipeline --- cmd/booktopipeline/main.go | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'cmd/booktopipeline') 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() { -- cgit v1.2.1-24-ge1ad