From 85c61ab14c7b594359316df20ae9607e2509dc66 Mon Sep 17 00:00:00 2001 From: wanyaoqi Date: Wed, 16 Sep 2020 20:50:12 +0800 Subject: [PATCH] fix set host image cache properties --- pkg/hostman/storageman/imagecache_local.go | 4 ++-- pkg/hostman/storageman/remotefile/remotefile.go | 12 +++++++++--- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/pkg/hostman/storageman/imagecache_local.go b/pkg/hostman/storageman/imagecache_local.go index 08f90843e7..3f3e38dd0f 100644 --- a/pkg/hostman/storageman/imagecache_local.go +++ b/pkg/hostman/storageman/imagecache_local.go @@ -191,8 +191,8 @@ func (l *SLocalImageCache) prepare(ctx context.Context, zone, srcUrl, format str } func (l *SLocalImageCache) fetch(ctx context.Context, zone, srcUrl, format string) bool { - if (fileutils2.Exists(l.GetPath()) && - l.remoteFile.VerifyIntegrity()) || l.remoteFile.Fetch() { + if (fileutils2.Exists(l.GetPath()) && l.remoteFile.VerifyIntegrity()) || + l.remoteFile.Fetch() { if len(l.Manager.GetId()) > 0 { _, err := hostutils.RemoteStoragecacheCacheImage(ctx, l.Manager.GetId(), l.imageId, "ready", l.GetPath()) diff --git a/pkg/hostman/storageman/remotefile/remotefile.go b/pkg/hostman/storageman/remotefile/remotefile.go index f718142a4a..7b7c67b488 100644 --- a/pkg/hostman/storageman/remotefile/remotefile.go +++ b/pkg/hostman/storageman/remotefile/remotefile.go @@ -259,7 +259,13 @@ func (r *SRemoteFile) downloadInternal(getData bool, preChksum string) bool { } func (r *SRemoteFile) setProperties(header http.Header) { - r.chksum = header.Get("X-Image-Meta-Checksum") - r.format = header.Get("X-Image-Meta-Disk_format") - r.name = header.Get("X-Image-Meta-Name") + if chksum := header.Get("X-Image-Meta-Checksum"); len(chksum) > 0 { + r.chksum = chksum + } + if format := header.Get("X-Image-Meta-Disk_format"); len(format) > 0 { + r.format = format + } + if name := header.Get("X-Image-Meta-Name"); len(name) > 0 { + r.name = name + } }