summaryrefslogtreecommitdiff
path: root/cmd/rescribe/main.go
diff options
context:
space:
mode:
authorNick White <git@njw.name>2022-01-10 16:16:33 +0000
committerNick White <git@njw.name>2022-01-10 16:16:33 +0000
commit218ba0c8dadc48307a3d714fe2f725eb0072b7e2 (patch)
tree61058266ddeab2d3617aeb2cab4826deeb08c23b /cmd/rescribe/main.go
parent436551c5e6f9d96f82fdf31e01e422b2a937b6ee (diff)
rescribe: Rename PDFs taking into account that in some cases one or the other of binarised or colour may not exist
Diffstat (limited to 'cmd/rescribe/main.go')
-rw-r--r--cmd/rescribe/main.go21
1 files changed, 19 insertions, 2 deletions
diff --git a/cmd/rescribe/main.go b/cmd/rescribe/main.go
index 019d038..3f7bd71 100644
--- a/cmd/rescribe/main.go
+++ b/cmd/rescribe/main.go
@@ -505,8 +505,25 @@ func startProcess(logger log.Logger, tessCommand string, bookdir string, booknam
}
// For simplicity, remove .binarised.pdf and rename .colour.pdf to .pdf
- _ = os.Remove(filepath.Join(savedir, bookname+".binarised.pdf"))
- _ = os.Rename(filepath.Join(savedir, bookname+".colour.pdf"), filepath.Join(savedir, bookname+".pdf"))
+ // providing they both exist, otherwise just rename whichever exists
+ // to .pdf.
+ binpath := filepath.Join(savedir, bookname+".binarised.pdf")
+ colourpath := filepath.Join(savedir, bookname+".colour.pdf")
+ pdfpath := filepath.Join(savedir, bookname+".pdf")
+
+ _, err = os.Stat(binpath)
+ binexists := err == nil || os.IsExist(err)
+ _, err = os.Stat(colourpath)
+ colourexists := err == nil || os.IsExist(err)
+
+ if binexists && colourexists {
+ _ = os.Remove(binpath)
+ _ = os.Rename(colourpath, pdfpath)
+ } else if binexists {
+ _ = os.Rename(binpath, pdfpath)
+ } else if colourexists {
+ _ = os.Rename(colourpath, pdfpath)
+ }
return nil
}