From 9a1354ae6254857d922dfd1a28f49788d68e96e5 Mon Sep 17 00:00:00 2001 From: Gani Georgiev Date: Sun, 28 May 2023 21:57:12 +0300 Subject: [PATCH 1/2] [#2589] added .exe fallback to the selfupdate cmd and replaced path with filepath --- CHANGELOG.md | 5 +++++ plugins/ghupdate/ghupdate.go | 19 +++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6dcd0f35..eeebf735 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## v0.16.4-WIP + +- Fixed the selfupdate command not working on Windows due to missing `.exe` in the extracted binary path ([#2589](https://github.com/pocketbase/pocketbase/discussions/2589)). + + ## v0.16.3 - Fixed schema fields sort not working on Safari/Gnome Web ([#2567](https://github.com/pocketbase/pocketbase/issues/2567)). diff --git a/plugins/ghupdate/ghupdate.go b/plugins/ghupdate/ghupdate.go index 4c92b09e..cbac6732 100644 --- a/plugins/ghupdate/ghupdate.go +++ b/plugins/ghupdate/ghupdate.go @@ -11,7 +11,6 @@ import ( "log" "net/http" "os" - "path" "path/filepath" "runtime" "strconv" @@ -38,7 +37,8 @@ type Options struct { // Repo specifies the name of the repository (default to "pocketbase"). Repo string - // ArchiveExecutable specifies the name of the executable file in the release archive (default to "pocketbase"). + // ArchiveExecutable specifies the name of the executable file in the release archive + // (default to "pocketbase"; an additional ".exe" check is also performed as a fallback). ArchiveExecutable string // Optional context to use when fetching and downloading the latest release. @@ -154,20 +154,20 @@ func (p *plugin) update(withBackup bool) error { return err } - releaseDir := path.Join(p.app.DataDir(), core.LocalTempDirName) + releaseDir := filepath.Join(p.app.DataDir(), core.LocalTempDirName) defer os.RemoveAll(releaseDir) color.Yellow("Downloading %s...", asset.Name) // download the release asset - assetZip := path.Join(releaseDir, asset.Name) + assetZip := filepath.Join(releaseDir, asset.Name) if err := downloadFile(p.options.Context, p.options.HttpClient, asset.DownloadUrl, assetZip); err != nil { return err } color.Yellow("Extracting %s...", asset.Name) - extractDir := path.Join(releaseDir, "extracted_"+asset.Name) + extractDir := filepath.Join(releaseDir, "extracted_"+asset.Name) defer os.RemoveAll(extractDir) if err := archive.Extract(assetZip, extractDir); err != nil { @@ -183,7 +183,14 @@ func (p *plugin) update(withBackup bool) error { renamedOldExec := oldExec + ".old" defer os.Remove(renamedOldExec) - newExec := path.Join(extractDir, p.options.ArchiveExecutable) + newExec := filepath.Join(extractDir, p.options.ArchiveExecutable) + if _, err := os.Stat(newExec); err != nil { + // try again with an .exe extension + newExec = newExec + ".exe" + if _, err := os.Stat(newExec); err != nil { + return fmt.Errorf("The executable in the extracted path is missing or it is inaccessible: %w", err) + } + } // rename the current executable if err := os.Rename(oldExec, renamedOldExec); err != nil { From 732044f795c0e55b2daddd06d88193fbf9c87f53 Mon Sep 17 00:00:00 2001 From: Gani Georgiev Date: Sun, 28 May 2023 22:00:48 +0300 Subject: [PATCH 2/2] keep both original file and fallback errors --- plugins/ghupdate/ghupdate.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/ghupdate/ghupdate.go b/plugins/ghupdate/ghupdate.go index cbac6732..631f03fc 100644 --- a/plugins/ghupdate/ghupdate.go +++ b/plugins/ghupdate/ghupdate.go @@ -187,8 +187,8 @@ func (p *plugin) update(withBackup bool) error { if _, err := os.Stat(newExec); err != nil { // try again with an .exe extension newExec = newExec + ".exe" - if _, err := os.Stat(newExec); err != nil { - return fmt.Errorf("The executable in the extracted path is missing or it is inaccessible: %w", err) + if _, fallbackErr := os.Stat(newExec); fallbackErr != nil { + return fmt.Errorf("The executable in the extracted path is missing or it is inaccessible: %w, %w", err, fallbackErr) } }