Skip to content

Commit fe4bcc8

Browse files
authored
Merge pull request #1089 from jshufro/jms/fixupdate
Fix update command when tmpdir is on a different device
2 parents 935112f + 08b2741 commit fe4bcc8

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

rocketpool-cli/update/update.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"net/http"
77
"os"
88
"os/exec"
9+
"path/filepath"
910
"runtime"
1011
"strings"
1112

@@ -18,6 +19,7 @@ import (
1819

1920
const (
2021
downloadUrlFormatString = "https://github.com/rocket-pool/smartnode/releases/latest/download/rocketpool-cli-%s-%s"
22+
downloadDirName = ".smartnode_downloads"
2123
)
2224

2325
func validateOsArch() error {
@@ -107,18 +109,18 @@ func Update(yes bool, skipSignatureVerification bool, force bool) error {
107109
}
108110
fmt.Printf("Replacing the cli at %s with the latest version...\n", oldBinaryPath)
109111

110-
// Create a temporary directory to download the new binary to
111-
tempDir, err := os.MkdirTemp("", "rocketpool-cli-update-")
112+
downloadDir := filepath.Join(filepath.Dir(oldBinaryPath), downloadDirName)
113+
err = os.MkdirAll(downloadDir, 0755)
112114
if err != nil {
113-
return fmt.Errorf("error creating temporary directory: %w", err)
115+
return fmt.Errorf("error creating download directory: %w", err)
114116
}
115117
defer func() {
116-
// Ignore errors, tmpreaper will handle it
117-
_ = os.RemoveAll(tempDir)
118+
// Ignore errors, future downloads will hopefully succeed at deleting the directory
119+
_ = os.RemoveAll(downloadDir)
118120
}()
119121

120122
// Create a file that is executable and has the correct permissions
121-
tempFile, err := os.CreateTemp(tempDir, "rocketpool-cli-update-*.bin")
123+
tempFile, err := os.CreateTemp(downloadDir, "rocketpool-cli-update-*.bin")
122124
if err != nil {
123125
return fmt.Errorf("error creating temporary file: %w", err)
124126
}

0 commit comments

Comments
 (0)