From 6d21e5ecb06c3793340832b9678f9e1fce15485d Mon Sep 17 00:00:00 2001 From: Zexi Li Date: Mon, 11 Oct 2021 12:40:30 +0800 Subject: [PATCH] fix(glance): s3 uploaded image removed --- pkg/image/models/images.go | 2 +- pkg/image/tasks/image_convert_task.go | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/pkg/image/models/images.go b/pkg/image/models/images.go index e60dc7e1d4..092ff30fe1 100644 --- a/pkg/image/models/images.go +++ b/pkg/image/models/images.go @@ -115,7 +115,7 @@ type SImage struct { // 镜像大小, 单位Byte Size int64 `nullable:"true" list:"user" create:"optional"` // 存储地址 - Location string `nullable:"true"` + Location string `nullable:"true" list:"user"` // 镜像格式 DiskFormat string `width:"20" charset:"ascii" nullable:"true" list:"user" create:"optional" default:"raw"` diff --git a/pkg/image/tasks/image_convert_task.go b/pkg/image/tasks/image_convert_task.go index d7eee82c08..0810c5478e 100644 --- a/pkg/image/tasks/image_convert_task.go +++ b/pkg/image/tasks/image_convert_task.go @@ -28,6 +28,7 @@ import ( "yunion.io/x/onecloud/pkg/cloudcommon/db/taskman" "yunion.io/x/onecloud/pkg/cloudcommon/notifyclient" "yunion.io/x/onecloud/pkg/image/models" + "yunion.io/x/onecloud/pkg/image/options" "yunion.io/x/onecloud/pkg/mcclient/modules/notify" "yunion.io/x/onecloud/pkg/util/procutils" ) @@ -89,8 +90,10 @@ func (self *PutImageTask) OnInit(ctx context.Context, obj db.IStandaloneModel, d if err != nil { log.Errorf("failed update image location %s", err) } else { - if err = procutils.NewCommand("rm", "-f", imagePath).Run(); err != nil { - log.Errorf("failed remove file %s: %s", imagePath, err) + if !strings.Contains(imagePath, options.Options.S3MountPoint) { + if err = procutils.NewCommand("rm", "-f", imagePath).Run(); err != nil { + log.Errorf("failed remove file %s: %s", imagePath, err) + } } } }