From 218ba0c8dadc48307a3d714fe2f725eb0072b7e2 Mon Sep 17 00:00:00 2001 From: Nick White Date: Mon, 10 Jan 2022 16:16:33 +0000 Subject: rescribe: Rename PDFs taking into account that in some cases one or the other of binarised or colour may not exist --- cmd/rescribe/main.go | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'cmd/rescribe/main.go') 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 } -- cgit v1.2.1-24-ge1ad