Compare commits

...

3 Commits

Author SHA1 Message Date
rdelaage
812fed163e
Merge 0c7da11f4d into 068121d722 2023-10-12 07:11:49 -07:00
068121d722
adjust base url 2023-10-11 21:50:43 +02:00
Romain de Laage
0c7da11f4d
Fix upgrade command
fix #191
2022-11-14 09:02:56 +01:00
2 changed files with 22 additions and 20 deletions

View File

@ -1,6 +1,6 @@
export default { export default {
logo: <span>Autorestic</span>, logo: <span>Autorestic</span>,
docsRepositoryBase: 'https://github.com/cupcakearmy/autorestic/blob/main', docsRepositoryBase: 'https://github.com/cupcakearmy/autorestic/tree/master/docs',
project: { project: {
link: 'https://github.com/cupcakearmy/autorestic', link: 'https://github.com/cupcakearmy/autorestic',
}, },

View File

@ -6,7 +6,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"os" "os"
"path" "path"
@ -37,7 +36,7 @@ func dlJSON(url string) (GithubRelease, error) {
return parsed, err return parsed, err
} }
defer resp.Body.Close() defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body) body, err := io.ReadAll(resp.Body)
if err != nil { if err != nil {
return parsed, err return parsed, err
@ -73,9 +72,10 @@ func downloadAndInstallAsset(body GithubRelease, name string) error {
// Uncompress // Uncompress
bz := bzip2.NewReader(resp.Body) bz := bzip2.NewReader(resp.Body)
// Save to tmp // Save to tmp file in the same directory as the install directory
// Linux does not support overwriting the file that is currently being overwritten, but it can be deleted and a new one moved in its place. // Linux does not support overwriting the file that is currently being running
tmp, err := ioutil.TempFile(os.TempDir(), "autorestic-") // But it can be delete the old one and a new one moved in its place.
tmp, err := os.CreateTemp(INSTALL_PATH, "autorestic-")
if err != nil { if err != nil {
return err return err
} }
@ -89,24 +89,26 @@ func downloadAndInstallAsset(body GithubRelease, name string) error {
to := path.Join(INSTALL_PATH, name) to := path.Join(INSTALL_PATH, name)
defer os.Remove(tmp.Name()) // Cleanup temporary file after thread exits defer os.Remove(tmp.Name()) // Cleanup temporary file after thread exits
if err := os.Rename(tmp.Name(), to); err != nil {
colors.Error.Printf("os.Rename() failed (%v), retrying with io.Copy()\n", err.Error()) mode := os.FileMode(0755)
var src *os.File if originalBin, err := os.Lstat(to); err == nil {
var dst *os.File mode = originalBin.Mode()
if src, err = os.Open(tmp.Name()); err != nil { err := os.Remove(to)
return err if err != nil {
}
if dst, err = os.Create(to); err != nil {
return err
}
if _, err := io.Copy(dst, src); err != nil {
return err
}
if err := os.Chmod(to, 0755); err != nil {
return err return err
} }
} }
err = os.Rename(tmp.Name(), to)
if err != nil {
return err
}
err = os.Chmod(to, mode)
if err != nil {
return err
}
colors.Success.Printf("Successfully installed '%s' under %s\n", name, INSTALL_PATH) colors.Success.Printf("Successfully installed '%s' under %s\n", name, INSTALL_PATH)
return nil return nil
} }