Skip to content

Commit

Permalink
Remove existing assets if the size does not match.
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgavin committed Apr 6, 2022
1 parent 06cf2d3 commit a11479a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion internal/push/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,16 @@ func (pushService *pushService) uploadReleaseAsset(release *github.RepositoryRel
func (pushService *pushService) createOrUpdateReleaseAsset(release *github.RepositoryRelease, existingAssets []*github.ReleaseAsset, assetPathStat os.FileInfo) error {
for _, existingAsset := range existingAssets {
if existingAsset.GetName() == assetPathStat.Name() {
if int64(existingAsset.GetSize()) == assetPathStat.Size() {
actualSize := int64(existingAsset.GetSize())
expectedSize := assetPathStat.Size()
if actualSize == expectedSize {
return nil
} else {
log.Warnf("Removing existing release asset %s because it was only partially-uploaded (had size %d, but should have been %d)...", existingAsset.GetName(), actualSize, expectedSize)
_, err := pushService.githubEnterpriseClient.Repositories.DeleteReleaseAsset(pushService.ctx, pushService.destinationRepositoryOwner, pushService.destinationRepositoryName, existingAsset.GetID())
if err != nil {
return errors.Wrap(err, "Error deleting existing release asset.")
}
}
}
}
Expand Down Expand Up @@ -333,6 +341,7 @@ func (pushService *pushService) pushReleases() error {
}
for _, releasePathStat := range releasePathStats {
releaseName := releasePathStat.Name()
log.Debugf("Pushing CodeQL bundles release %s...", releaseName)
release, err := pushService.createOrUpdateRelease(releaseName)
if err != nil {
return err
Expand Down

0 comments on commit a11479a

Please sign in to comment.