From 89fc45b865f86057844585f1d4de6132c4bd2d19 Mon Sep 17 00:00:00 2001 From: sp-yduck Date: Mon, 31 Jul 2023 20:24:07 +0900 Subject: [PATCH] refactor writefile --- proxmox/websocket.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/proxmox/websocket.go b/proxmox/websocket.go index 35b9e46..0b2ebd4 100644 --- a/proxmox/websocket.go +++ b/proxmox/websocket.go @@ -65,15 +65,15 @@ func (c *VNCWebSocketClient) Write(cmd string) error { func (c *VNCWebSocketClient) WriteFile(ctx context.Context, content, path string) error { c.Exec(ctx, fmt.Sprintf("rm %s", path)) - if _, _, err := c.Exec(ctx, fmt.Sprintf("touch %s", path)); err != nil { - return err + if out, _, err := c.Exec(ctx, fmt.Sprintf("touch %s", path)); err != nil { + return errors.Wrap(err, out) } - chunks := chunkString(content, 3000) + chunks := chunkString(content, 2000) for _, chunk := range chunks { b64chunk := base64.StdEncoding.EncodeToString([]byte(chunk)) - _, _, err := c.Exec(ctx, fmt.Sprintf("echo %s | base64 -d >> %s", b64chunk, path)) + out, _, err := c.Exec(ctx, fmt.Sprintf("echo %s | base64 -d >> %s", b64chunk, path)) if err != nil { - return err + return errors.Wrap(err, out) } } return nil