From 026ca93c9e042286627fb851881715300f26d26d Mon Sep 17 00:00:00 2001 From: Sebastiaan Klippert Date: Tue, 22 Nov 2022 21:55:46 +0100 Subject: [PATCH] Document changes in relative path discovery in go 1.19 --- README.md | 2 ++ wkhtmltopdf.go | 7 ++++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 22b5447..677628d 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,8 @@ go-wkhtmltopdf finds the path to wkhtmltopdf by * looking in the PATH and PATHEXT environment dirs * using the WKHTMLTOPDF_PATH environment dir +**Warning**: Running executables from the current path is no longer possible in Go 1.19, see https://pkg.go.dev/os/exec@master#hdr-Executables_in_the_current_directory + If you need to set your own wkhtmltopdf path or want to change it during execution, you can call SetPath(). # Usage diff --git a/wkhtmltopdf.go b/wkhtmltopdf.go index 69af654..23a810a 100644 --- a/wkhtmltopdf.go +++ b/wkhtmltopdf.go @@ -248,13 +248,15 @@ func (pdfg *PDFGenerator) WriteFile(filename string) error { // - first looking in the current dir // - looking in the PATH and PATHEXT environment dirs // - using the WKHTMLTOPDF_PATH environment dir +// Warning: Running executables from the current path is no longer possible in Go 1.19 +// See https://pkg.go.dev/os/exec@master#hdr-Executables_in_the_current_directory // The path is cached, meaning you can not change the location of wkhtmltopdf in // a running program once it has been found func (pdfg *PDFGenerator) findPath() error { const exe = "wkhtmltopdf" pdfg.binPath = GetPath() if pdfg.binPath != "" { - // wkhtmltopdf has already already found, return + // wkhtmltopdf has already been found, return return nil } exeDir, err := filepath.Abs(filepath.Dir(os.Args[0])) @@ -268,6 +270,9 @@ func (pdfg *PDFGenerator) findPath() error { return nil } path, err = exec.LookPath(exe) + if errors.Is(err, exec.ErrDot) { + return err + } if err == nil && path != "" { binPath.Set(path) pdfg.binPath = path