Skip to content
This repository has been archived by the owner on Sep 3, 2020. It is now read-only.

Commit

Permalink
Use executable's path as the temp path (#488)
Browse files Browse the repository at this point in the history
Solve the problem of `⨯ Error: rename /tmp/apex-upgrade
/usr/local/bin/apex: cross-device link`

Close #412
  • Loading branch information
Wu Jiang authored and tj committed Jul 17, 2016
1 parent 6474216 commit fbc3dab
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,15 @@ func Upgrade(version string) error {
return errors.New("cannot find binary for your system")
}

// get the executable's path
cmdPath, err := exec.LookPath("apex")
if err != nil {
return err
}
cmdDir := filepath.Dir(cmdPath)

// create tmp file
tmpPath := filepath.Join(os.TempDir(), "apex-upgrade")
tmpPath := filepath.Join(cmdDir, "apex-upgrade")
f, err := os.OpenFile(tmpPath, os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0755)
if err != nil {
return err
Expand All @@ -62,11 +69,6 @@ func Upgrade(version string) error {
}

// replace it
cmdPath, err := exec.LookPath("apex")
if err != nil {
return err
}

log.Infof("replacing %s", cmdPath)
err = os.Rename(tmpPath, cmdPath)
if err != nil {
Expand Down

0 comments on commit fbc3dab

Please sign in to comment.