Skip to content

Commit

Permalink
Document changes in relative path discovery in go 1.19
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastiaanKlippert committed Nov 22, 2022
1 parent 2a06997 commit 026ca93
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 6 additions & 1 deletion wkhtmltopdf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand All @@ -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
Expand Down

0 comments on commit 026ca93

Please sign in to comment.