azure: return an early error if unaligned

If the image size isn't aligned to 512 bytes, the Azure API returns very hard
to understand error message. Let's do this check ourselves early so we can
return a sane error.

Signed-off-by: Ondřej Budai <ondrej@budai.cz>
This commit is contained in:
Ondřej Budai 2021-02-11 14:19:12 +01:00 committed by Tom Gundersen
parent 3ed3f2ed95
commit f67ca8b616

View file

@ -71,6 +71,10 @@ func UploadImage(credentials Credentials, metadata ImageMetadata, fileName strin
return fmt.Errorf("cannot stat the image: %v", err)
}
if stat.Size()%512 != 0 {
return errors.New("size for azure image must be aligned to 512 bytes")
}
// Hash the imageFile
imageFileHash := md5.New()
if _, err := io.Copy(imageFileHash, imageFile); err != nil {