From 4ca9d2466fadcad6ba293fd42f8a2b862110186a Mon Sep 17 00:00:00 2001 From: per1234 Date: Sat, 3 Feb 2024 20:50:13 -0800 Subject: [PATCH] Fix failure to execute tool post-install script on Windows Background ---------- Tool Dependency Installation ---------------------------- "Arduino Create Agent" performs installation and updates of the tool dependencies required for direct communication between the local machine and the target board. It might be necessary to execute some sort of installation process in addition to placing the files from the tool archive on the user's hard drive. This capability is provided by a "post-install script" system. If a post-install script file (`post_install.bat` on Windows, `post_install.sh` other host operating systems) is found in the tool installation, "Arduino Create Agent" automatically executes it as part of the tool installation operation. One of the tool dependencies is `arduino:windows-drivers`, which provides the Windows device drivers for the official Arduino boards. This tool contains a post-install script that installs the drivers from the tool archive. It is essential for this script to be executed as the presence of the driver files alone doesn't have any effect. Go `exec` Package ----------------- From the Go 1.19 release, the behavior of the `exec` package was changed to make it more secure: https://pkg.go.dev/os/exec#hdr-Executables_in_the_current_directory > as of Go 1.19, this package will not resolve a program using an implicit or explicit path entry relative to the > current directory. That is, if you run exec.LookPath("go"), it will not successfully return ./go on Unix nor .\go.exe > on Windows, no matter how the path is configured. Instead, if the usual path algorithms would result in that answer, > these functions return an error err satisfying errors.Is(err, ErrDot). Problem ------- The code that executes the post-install script on Windows depended on the previous behavior of the `exec` package. Ever since the version of Go used to build "Arduino Create Agent" was updated to 1.19, the script has not been executed: ``` { "DownloadStatus": "Error", "Msg": "exec: \"post_install.bat\": cannot run executable found relative to current directory" } ``` This means "Arduino Create Agent" never installed the drivers from the `arduino:windows-drivers` tool on the machines who weren't using it before the 1.3.0 release. The failure to execute the post-install script results in **Arduino Create Agent** attempting installation of the `arduino:windows-drivers` tool on every Arduino Cloud session. Even if the user is not impacted by the lack of drivers (either because it is not required for their board, or because they installed the drivers via some other mechanism), they will still be annoyed and confused by the frequent appearance of the "**Installing drivers**" dialog that is produced by **Arduino Create Agent**'s post-install script execution code. --- tools/download.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/download.go b/tools/download.go index 177ca3f76..360d6e4c3 100644 --- a/tools/download.go +++ b/tools/download.go @@ -223,7 +223,8 @@ func findTool(pack, name, version string, data pkgs.Index) (pkgs.Tool, pkgs.Syst func (t *Tools) installDrivers(location string) error { OkPressed := 6 extension := ".bat" - preamble := "" + // add .\ to force locality + preamble := ".\\" if OS != "windows" { extension = ".sh" // add ./ to force locality