fix: download bug

This commit is contained in:
fengcaiwen
2023-12-16 23:21:55 +08:00
parent c0da61cd4b
commit 7c53cbc79b
3 changed files with 9 additions and 3 deletions

View File

@@ -246,7 +246,7 @@ func (w *wsHandler) remoteInstallKubevpnIfCommandNotFound(ctx context.Context, s
w.Log("Get latest kubevpn version failed: %v", err)
return err
}
fmt.Printf("The latest version is: %s, commit: %s\n", latestVersion, latestCommit)
w.Log("The latest version is: %s, commit: %s", latestVersion, latestCommit)
var temp *os.File
temp, err = os.CreateTemp("", "")
if err != nil {
@@ -304,6 +304,7 @@ func (w *wsHandler) Log(format string, a ...any) {
str = fmt.Sprintf(format, a...)
}
w.conn.Write([]byte(str + "\r\n"))
log.Infof(format, a...)
}
func (w *wsHandler) PrintLine(msg string) {

View File

@@ -72,7 +72,9 @@ func main(sess *ssh.Session, stdout, stderr io.Writer, filename string, to strin
func sCopy(dst io.Writer, src io.Reader, size int64, stdout, stderr io.Writer) error {
total := float64(size) / 1024 / 1024
log.Printf("Length: 68276642 (%0.2fM)\n", total)
s := fmt.Sprintf("Length: %d (%0.2fM)\n", size, total)
log.Info(s)
io.WriteString(stdout, s)
bar := progressbar.NewOptions(int(size),
progressbar.OptionSetWriter(stdout),

View File

@@ -11,6 +11,7 @@ import (
"strings"
"github.com/schollz/progressbar/v3"
log "github.com/sirupsen/logrus"
utilerrors "k8s.io/apimachinery/pkg/util/errors"
"k8s.io/apimachinery/pkg/util/sets"
)
@@ -88,7 +89,9 @@ func Download(client *http.Client, url string, filename string, stdout, stderr i
}
defer get.Body.Close()
total := float64(get.ContentLength) / 1024 / 1024
fmt.Printf("Length: 68276642 (%0.2fM)\n", total)
s := fmt.Sprintf("Length: %d (%0.2fM)\n", get.ContentLength, total)
log.Info(s)
io.WriteString(stdout, s)
var f *os.File
f, err = os.OpenFile(filename, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0755)