Skip to content

Commit

Permalink
simplestreams: Fix creation date parsing format (#14402)
Browse files Browse the repository at this point in the history
Parse creation date in 24-hour format instead of 12 hour format where
am/pm is not differentiated. Also replace usage of `ValueInSlice` with
`slices.Contains`.

Based on comment:
4b26fc2#commitcomment-148595914
  • Loading branch information
tomponline authored Nov 6, 2024
2 parents 04ad8b4 + 3045ddd commit 9ac2433
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions shared/simplestreams/products.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package simplestreams

import (
"fmt"
"slices"
"strings"
"time"

"github.com/canonical/lxd/shared"
"github.com/canonical/lxd/shared/api"
"github.com/canonical/lxd/shared/osarch"
)
Expand Down Expand Up @@ -70,7 +70,7 @@ func (s *Products) ToLXD() ([]api.Image, map[string][][]string) {
downloads := map[string][][]string{}

images := []api.Image{}
nameLayoutLong := "20060102_0304" // Date and time.
nameLayoutLong := "20060102_1504" // Date and time.
nameLayoutShort := "20060102" // Date only.
eolLayout := "2006-01-02"

Expand Down Expand Up @@ -107,7 +107,7 @@ func (s *Products) ToLXD() ([]api.Image, map[string][][]string) {
addImage := func(meta *ProductVersionItem, root *ProductVersionItem) error {
// Look for deltas
deltas := []ProductVersionItem{}
if root != nil && shared.ValueInSlice(root.FileType, []string{"squashfs", "disk-kvm.img"}) {
if root != nil && slices.Contains([]string{"squashfs", "disk-kvm.img"}, root.FileType) {
for _, item := range version.Items {
if item.FileType == fmt.Sprintf("%s.vcdiff", root.FileType) {
deltas = append(deltas, item)
Expand Down Expand Up @@ -251,7 +251,7 @@ func (s *Products) ToLXD() ([]api.Image, map[string][][]string) {
// Locate source image fingerprint
var srcFingerprint string
for _, item := range srcImage.Items {
if !shared.ValueInSlice(item.FileType, lxdCompatItems) {
if !slices.Contains(lxdCompatItems, item.FileType) {
continue
}

Expand Down Expand Up @@ -288,15 +288,15 @@ func (s *Products) ToLXD() ([]api.Image, map[string][][]string) {

// Locate a valid LXD image
for _, item := range version.Items {
if shared.ValueInSlice(item.FileType, lxdCompatCombinedItems) {
if slices.Contains(lxdCompatCombinedItems, item.FileType) {
err := addImage(&item, nil)
if err != nil {
continue
}
} else if shared.ValueInSlice(item.FileType, lxdCompatItems) {
} else if slices.Contains(lxdCompatItems, item.FileType) {
// Locate the root files
for _, subItem := range version.Items {
if shared.ValueInSlice(subItem.FileType, []string{"disk1.img", "disk-kvm.img", "uefi1.img", "root.tar.xz", "squashfs"}) {
if slices.Contains([]string{"disk1.img", "disk-kvm.img", "uefi1.img", "root.tar.xz", "squashfs"}, subItem.FileType) {
err := addImage(&item, &subItem)
if err != nil {
continue
Expand Down

0 comments on commit 9ac2433

Please sign in to comment.