Skip to content

Commit

Permalink
fix: create tempDir if not exist (#276)
Browse files Browse the repository at this point in the history
* fix: create tempDir is exist

* fix: create tempDir if not exist
  • Loading branch information
mchgood authored May 20, 2024
1 parent 3c0bff0 commit 57f3803
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions cmd/commands/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 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)
}
} 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)
Expand Down

0 comments on commit 57f3803

Please sign in to comment.