From 5ea5152e0227e8aac654934713f650547148d726 Mon Sep 17 00:00:00 2001 From: mlycore Date: Mon, 18 Dec 2023 11:20:01 +0800 Subject: [PATCH 1/2] feat: add stderr to cmd output Signed-off-by: mlycore --- pitr/agent/pkg/cmds/cmd.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pitr/agent/pkg/cmds/cmd.go b/pitr/agent/pkg/cmds/cmd.go index 77a98f53..e39a3475 100644 --- a/pitr/agent/pkg/cmds/cmd.go +++ b/pitr/agent/pkg/cmds/cmd.go @@ -142,7 +142,7 @@ func Exec(name string, args ...string) (string, error) { if err = cmd.Wait(); err != nil { if ee, ok := err.(*exec.ExitError); ok { - return "", fmt.Errorf("exec failure[ee=%s,stdout=%s], wrap:%w", ee, string(reader), cons.CmdOperateFailed) + return "", fmt.Errorf("exec failure[ee=%s,stdout=%s,stderr=%s], wrap:%w", ee, string(reader), string(ereader), cons.CmdOperateFailed) } return "", fmt.Errorf("%s err: %s", cmd.String(), string(ereader)) } From 05739d0b9f5be0d6e87a8f22cb433ecd3dca7cd9 Mon Sep 17 00:00:00 2001 From: mlycore Date: Mon, 18 Dec 2023 11:20:14 +0800 Subject: [PATCH 2/2] feat: create directory before check Signed-off-by: mlycore --- pitr/agent/internal/handler/diskspace.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pitr/agent/internal/handler/diskspace.go b/pitr/agent/internal/handler/diskspace.go index 401d523c..b9807f9a 100644 --- a/pitr/agent/internal/handler/diskspace.go +++ b/pitr/agent/internal/handler/diskspace.go @@ -40,6 +40,10 @@ func DiskSpace(ctx *fiber.Ctx) error { return fmt.Errorf("invalid parameter, err wrap: %w", err) } + if err := os.MkdirAll(in.DiskPath, 0755); err != nil { + return fmt.Errorf("mkdir [%s] failure, err wrap: %w", in.DiskPath, err) + } + // show disk space cmd := fmt.Sprintf("df -h %s", in.DiskPath) output, err := cmds.Exec(os.Getenv("SHELL"), cmd)