From 01498060867623f76f5b9eaba7beebe85bfcbe4f Mon Sep 17 00:00:00 2001 From: Craig Peterson Date: Wed, 19 Apr 2017 15:48:58 -0600 Subject: [PATCH] pointers are hard --- build/masterRelease/main.go | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/build/masterRelease/main.go b/build/masterRelease/main.go index 273317d96..a6fafb9c3 100644 --- a/build/masterRelease/main.go +++ b/build/masterRelease/main.go @@ -44,24 +44,28 @@ func main() { for _, f := range files { log.Printf("--- %s", f) - var found *github.ReleaseAsset - var foundOld *github.ReleaseAsset + var found github.ReleaseAsset + var exists bool + var foundOld bool for _, ass := range rel.Assets { if ass.GetName() == f { - found = &ass + exists = true + found = ass } if ass.GetName() == f+".old" { - foundOld = &ass + foundOld = true } } - if foundOld != nil { + + if foundOld { log.Fatalf("%s.old was already found. Previous deploy likely failed. Please check and manually delete.", f) } - if found != nil { - n := found.GetName() + ".old" + if exists { + oldN := found.GetName() + n := oldN + ".old" found.Name = &n - log.Printf("Renaming old asset %s(%d) to .old", found.GetName(), found.GetID()) - _, _, err = c.Repositories.EditReleaseAsset(bg(), owner, repo, found.GetID(), found) + log.Printf("Renaming old asset %s(%d) to %s", oldN, found.GetID(), found.GetName()) + _, _, err = c.Repositories.EditReleaseAsset(bg(), owner, repo, found.GetID(), &found) check(err) } @@ -73,7 +77,7 @@ func main() { _, _, err = c.Repositories.UploadReleaseAsset(bg(), owner, repo, rel.GetID(), upOpts, f) check(err) - if found != nil { + if exists { log.Println("Deleting old asset") _, err = c.Repositories.DeleteReleaseAsset(bg(), owner, repo, found.GetID()) check(err)