From 42ff6542bec40cdcf88473cfbeb00f353fb1874e Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Fri, 17 May 2024 22:15:00 +0800 Subject: [PATCH 1/2] fix: create tempDir is exist --- cmd/commands/upgrade.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cmd/commands/upgrade.go b/cmd/commands/upgrade.go index 5ff18aff..a48e797c 100644 --- a/cmd/commands/upgrade.go +++ b/cmd/commands/upgrade.go @@ -140,9 +140,18 @@ func upgradeCmd(ctx *cli.Context) error { } tempDir := filepath.Join(exeDir, "vfox_upgrade") tempFile = filepath.Join(tempDir, tempFile) - if err := os.Mkdir(tempDir, 0755); err != nil { - return cli.Exit("Failed to create directory: "+err.Error(), 1) + + // create tempDir is exist + if _, err := os.Stat(tempDir); os.IsNotExist(err) { + if err := os.Mkdir(tempDir, 0755); err != nil { + return cli.Exit("Failed to create directory: "+err.Error(), 1) + } + } else if err != nil { + return cli.Exit("Error checking directory: "+err.Error(), 1) + } else { + fmt.Println("Directory already exists") } + defer func() { if err := os.RemoveAll(tempDir); err != nil { fmt.Println("Error removing directory: ", err) From 595359397bc269ffb2ff58b7400b10e5f0b846d0 Mon Sep 17 00:00:00 2001 From: gaibu <1016771049@qq.com> Date: Fri, 17 May 2024 22:23:00 +0800 Subject: [PATCH 2/2] fix: create tempDir if not exist --- cmd/commands/upgrade.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/commands/upgrade.go b/cmd/commands/upgrade.go index a48e797c..d431507c 100644 --- a/cmd/commands/upgrade.go +++ b/cmd/commands/upgrade.go @@ -141,7 +141,7 @@ func upgradeCmd(ctx *cli.Context) error { tempDir := filepath.Join(exeDir, "vfox_upgrade") tempFile = filepath.Join(tempDir, tempFile) - // create tempDir is exist + // create tempDir if not exist if _, err := os.Stat(tempDir); os.IsNotExist(err) { if err := os.Mkdir(tempDir, 0755); err != nil { return cli.Exit("Failed to create directory: "+err.Error(), 1)