Skip to content

Commit

Permalink
Don't delete package dir if the failure is that it already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
dshafik committed Oct 4, 2017
1 parent 405a4ea commit 2fa7d64
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions akamai.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,22 +160,27 @@ func cmdInstall(c *cli.Context) error {
fmt.Printf("Attempting to fetch command from %s...", repo)

dirName := strings.TrimSuffix(filepath.Base(repo), ".git")
packageDir := srcPath + string(os.PathSeparator) + dirName
if _, err := os.Stat(packageDir); err == nil {
fmt.Println("... [" + color.RedString("FAIL") + "]")
return cli.NewExitError(color.RedString("Package directory already exists (%s)", packageDir), 1)
}

_, err = git.PlainClone(srcPath+string(os.PathSeparator)+dirName, false, &git.CloneOptions{
_, err = git.PlainClone(packageDir, false, &git.CloneOptions{
URL: repo,
Progress: nil,
})

if err != nil {
fmt.Println("... [" + color.RedString("FAIL") + "]")
os.RemoveAll(srcPath + string(os.PathSeparator) + dirName)
os.RemoveAll(packageDir)
return cli.NewExitError(color.RedString("Unable to clone repository: "+err.Error()), 1)
}

fmt.Println("... [" + color.GreenString("OK") + "]")

if !installPackage(srcPath+string(os.PathSeparator)+dirName, c.Bool("force")) {
os.RemoveAll(srcPath + string(os.PathSeparator) + dirName)
if !installPackage(packageDir, c.Bool("force")) {
os.RemoveAll(packageDir)
return cli.NewExitError("", 1)
}
}
Expand Down

0 comments on commit 2fa7d64

Please sign in to comment.