Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions cmd/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/anyproto/anytype-cli/core"
"github.com/anyproto/anytype-cli/core/output"
"github.com/spf13/cobra"
"golang.org/x/mod/semver"
)

const (
Expand Down Expand Up @@ -48,7 +49,7 @@ func runUpdate(cmd *cobra.Command, args []string) error {
currentBase = current[:idx]
}

if currentBase >= latest {
if semver.Compare(currentBase, latest) >= 0 {
output.Info("Already up to date (%s)", current)
return nil
}
Expand Down Expand Up @@ -321,13 +322,26 @@ func replaceBinary(newBinary string) error {
}

if err := os.Rename(newBinary, currentBinary); err != nil {
if runtime.GOOS != "windows" {
if runtime.GOOS == "windows" {
// Windows locks running exe, so we can't overwrite.
// Rename the current binary first, then replace with the new one.
current := core.GetVersion()
oldBinary := currentBinary + "_" + current
if err := os.Rename(currentBinary, oldBinary); err != nil {
return output.Error("failed to move current binary (permission denied). Try running as administrator: %w", err)
}
if err := os.Rename(newBinary, currentBinary); err != nil {
// Attempt to restore the original
_ = os.Rename(oldBinary, currentBinary)
return output.Error("failed to install new binary: %w", err)
}

return nil
} else {
cmd := exec.Command("mv", newBinary, currentBinary)
if err := cmd.Run(); err != nil {
return output.Error("failed to replace binary at %s (permission denied). To get the latest version, reinstall from repository: https://github.com/%s/%s", currentBinary, githubOwner, githubRepo)
}
} else {
return output.Error("failed to replace binary at %s. To get the latest version, reinstall from repository: https://github.com/%s/%s", currentBinary, githubOwner, githubRepo)
}
}

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ require (
golang.org/x/crypto v0.47.0 // indirect
golang.org/x/exp v0.0.0-20251023183803-a4bb9ffd2546 // indirect
golang.org/x/image v0.27.0 // indirect
golang.org/x/mod v0.32.0 // indirect
golang.org/x/mod v0.33.0 // indirect
golang.org/x/net v0.49.0 // indirect
golang.org/x/oauth2 v0.32.0 // indirect
golang.org/x/sync v0.19.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1021,8 +1021,8 @@ golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.12.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
golang.org/x/mod v0.32.0 h1:9F4d3PHLljb6x//jOyokMv3eX+YDeepZSEo3mFJy93c=
golang.org/x/mod v0.32.0/go.mod h1:SgipZ/3h2Ci89DlEtEXWUk/HteuRin+HHhN+WbNhguU=
golang.org/x/mod v0.33.0 h1:tHFzIWbBifEmbwtGz65eaWyGiGZatSrT9prnU8DbVL8=
golang.org/x/mod v0.33.0/go.mod h1:swjeQEj+6r7fODbD2cqrnje9PnziFuw4bmLbBZFrQ5w=
golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
Expand Down