synced with master

This commit is contained in:
Gani Georgiev 2023-05-28 23:57:19 +03:00
commit 97f29e4305
2 changed files with 18 additions and 6 deletions

View File

@ -5,6 +5,11 @@
- Added VK OAuth2 provider ([#2533](https://github.com/pocketbase/pocketbase/pull/2533); thanks @imperatrona). - 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 ## v0.16.3
- Fixed schema fields sort not working on Safari/Gnome Web ([#2567](https://github.com/pocketbase/pocketbase/issues/2567)). - Fixed schema fields sort not working on Safari/Gnome Web ([#2567](https://github.com/pocketbase/pocketbase/issues/2567)).

View File

@ -11,7 +11,6 @@ import (
"log" "log"
"net/http" "net/http"
"os" "os"
"path"
"path/filepath" "path/filepath"
"runtime" "runtime"
"strconv" "strconv"
@ -38,7 +37,8 @@ type Options struct {
// Repo specifies the name of the repository (default to "pocketbase"). // Repo specifies the name of the repository (default to "pocketbase").
Repo string 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 ArchiveExecutable string
// Optional context to use when fetching and downloading the latest release. // Optional context to use when fetching and downloading the latest release.
@ -154,20 +154,20 @@ func (p *plugin) update(withBackup bool) error {
return err return err
} }
releaseDir := path.Join(p.app.DataDir(), core.LocalTempDirName) releaseDir := filepath.Join(p.app.DataDir(), core.LocalTempDirName)
defer os.RemoveAll(releaseDir) defer os.RemoveAll(releaseDir)
color.Yellow("Downloading %s...", asset.Name) color.Yellow("Downloading %s...", asset.Name)
// download the release asset // 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 { if err := downloadFile(p.options.Context, p.options.HttpClient, asset.DownloadUrl, assetZip); err != nil {
return err return err
} }
color.Yellow("Extracting %s...", asset.Name) color.Yellow("Extracting %s...", asset.Name)
extractDir := path.Join(releaseDir, "extracted_"+asset.Name) extractDir := filepath.Join(releaseDir, "extracted_"+asset.Name)
defer os.RemoveAll(extractDir) defer os.RemoveAll(extractDir)
if err := archive.Extract(assetZip, extractDir); err != nil { if err := archive.Extract(assetZip, extractDir); err != nil {
@ -183,7 +183,14 @@ func (p *plugin) update(withBackup bool) error {
renamedOldExec := oldExec + ".old" renamedOldExec := oldExec + ".old"
defer os.Remove(renamedOldExec) 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 // rename the current executable
if err := os.Rename(oldExec, renamedOldExec); err != nil { if err := os.Rename(oldExec, renamedOldExec); err != nil {