File tree Expand file tree Collapse file tree 2 files changed +12
-23
lines changed Expand file tree Collapse file tree 2 files changed +12
-23
lines changed Original file line number Diff line number Diff line change @@ -207,16 +207,21 @@ func runUpload(cmd *cobra.Command, args []string) error {
207
207
}
208
208
209
209
if uploadForce {
210
- var err error
211
- if ! uploadCreateWinLIAMI {
212
- err = API .RemoveImage (uploadAMIName , s3BucketName , s3ObjectPath )
213
- } else {
214
- err = API .RemoveImage (uploadAMIName , "" , "" )
215
- }
210
+ err := API .RemoveImage (uploadAMIName )
216
211
if err != nil {
217
212
fmt .Fprintf (os .Stderr , "%v\n " , err )
218
213
os .Exit (1 )
219
214
}
215
+ // Since we are force uploading delete the s3 object used previously too
216
+ // if it exists. A "NoSuchKey" err means it didn't exist and we can ignore.
217
+ if uploadSourceObject == "" && uploadSourceSnapshot == "" {
218
+ if err := API .DeleteObject (s3BucketName , s3ObjectPath ); err != nil {
219
+ if ! strings .Contains (err .Error (), "NoSuchKey" ) {
220
+ fmt .Fprintf (os .Stderr , "unable to delete object: %v\n " , err )
221
+ os .Exit (1 )
222
+ }
223
+ }
224
+ }
220
225
}
221
226
222
227
// if no snapshot was specified, check for an existing one or a
Original file line number Diff line number Diff line change @@ -478,23 +478,7 @@ func (a *API) deregisterImageIfExists(name string) error {
478
478
}
479
479
480
480
// Remove all uploaded data associated with an AMI.
481
- func (a * API ) RemoveImage (name , s3BucketName , s3ObjectPath string ) error {
482
- // Delete S3 object if bucket and path are specified.
483
- if s3BucketName != "" && s3ObjectPath != "" {
484
- err := a .DeleteObject (s3BucketName , s3ObjectPath )
485
- if err != nil {
486
- if awsErr , ok := err .(awserr.Error ); ok {
487
- if awsErr .Code () != "NoSuchKey" {
488
- return err
489
- }
490
- } else {
491
- return err
492
- }
493
- } else {
494
- plog .Infof ("Deleted existing S3 object bucket:%s path:%s" , s3BucketName , s3ObjectPath )
495
- }
496
- }
497
-
481
+ func (a * API ) RemoveImage (name string ) error {
498
482
// compatibility with old versions of this code, which created HVM
499
483
// AMIs with an "-hvm" suffix
500
484
err := a .deregisterImageIfExists (name + "-hvm" )
You can’t perform that action at this time.
0 commit comments