diff --git a/CHANGELOG.md b/CHANGELOG.md index 7677f7d8..01c69ac6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,11 @@ - Added VK OAuth2 provider ([#2533](https://github.com/pocketbase/pocketbase/pull/2533); thanks @imperatrona). +## 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..631f03fc 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 _, 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) + } + } // rename the current executable if err := os.Rename(oldExec, renamedOldExec); err != nil {