Skip to content

Commit

Permalink
[pocketbase#2589] added .exe fallback to the selfupdate cmd and repla…
Browse files Browse the repository at this point in the history
…ced path with filepath
  • Loading branch information
ganigeorgiev committed May 28, 2023
1 parent e3876c0 commit 9a1354a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)).
Expand Down
19 changes: 13 additions & 6 deletions plugins/ghupdate/ghupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"log"
"net/http"
"os"
"path"
"path/filepath"
"runtime"
"strconv"
Expand All @@ -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.
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 9a1354a

Please sign in to comment.