diff options
author | Nick White <git@njw.name> | 2022-01-10 16:16:33 +0000 |
---|---|---|
committer | Nick White <git@njw.name> | 2022-01-10 16:16:33 +0000 |
commit | 218ba0c8dadc48307a3d714fe2f725eb0072b7e2 (patch) | |
tree | 61058266ddeab2d3617aeb2cab4826deeb08c23b /cmd | |
parent | 436551c5e6f9d96f82fdf31e01e422b2a937b6ee (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')
-rw-r--r-- | cmd/rescribe/main.go | 21 |
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 } |