Skip to content

Commit

Permalink
Save temporary in correct dir during upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
calmh committed May 2, 2014
1 parent 9659d02 commit b374ec9
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions cmd/syncthing/upgrade_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"path"
Expand Down Expand Up @@ -64,7 +65,7 @@ func upgrade() error {
if strings.HasPrefix(asset.Name, expectedRelease) {
if strings.HasSuffix(asset.Name, ".tar.gz") {
infof("Downloading %s...", asset.Name)
fname, err := readTarGZ(asset.URL)
fname, err := readTarGZ(asset.URL, filepath.Dir(path))
if err != nil {
return err
}
Expand All @@ -90,7 +91,7 @@ func upgrade() error {
return nil
}

func readTarGZ(url string) (string, error) {
func readTarGZ(url string, dir string) (string, error) {
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return "", err
Expand Down Expand Up @@ -125,20 +126,19 @@ func readTarGZ(url string) (string, error) {
}

if path.Base(hdr.Name) == "syncthing" {
fname := filepath.Join(os.TempDir(), "syncthing.new")
of, err := os.Create(fname)
of, err := ioutil.TempFile(dir, "syncthing")
if err != nil {
return "", err
}
io.Copy(of, tr)
err = of.Close()
if err != nil {
os.Remove(fname)
os.Remove(of.Name())
return "", err
}

os.Chmod(fname, os.FileMode(hdr.Mode))
return fname, nil
os.Chmod(of.Name(), os.FileMode(hdr.Mode))
return of.Name(), nil
}
}

Expand Down

0 comments on commit b374ec9

Please sign in to comment.