Skip to content

Commit

Permalink
incusd/instance/qemu: Fix random ordering in ETag
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Graber <[email protected]>
Sponsored-by: https://webdock.io
  • Loading branch information
stgraber committed Nov 28, 2024
1 parent 820c995 commit 6d5825a
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions internal/server/instance/drivers/driver_qemu.go
Original file line number Diff line number Diff line change
Expand Up @@ -7865,9 +7865,7 @@ func (d *qemu) Render(options ...func(response any) error) (any, any, error) {
}

if d.IsSnapshot() {
// Prepare the ETag
etag := []any{d.expiryDate}

// Prepare the response.
snapState := api.InstanceSnapshot{
CreatedAt: d.creationDate,
ExpandedConfig: d.expandedConfig,
Expand All @@ -7892,13 +7890,14 @@ func (d *qemu) Render(options ...func(response any) error) (any, any, error) {
}
}

// Prepare the ETag.
etag := []any{d.expiryDate}

return &snapState, etag, nil
}

// Prepare the ETag
etag := []any{d.architecture, d.localConfig, d.localDevices, d.ephemeral, d.profiles}
// Prepare the response.
statusCode := d.statusCode()

instState := api.Instance{
ExpandedConfig: d.expandedConfig,
ExpandedDevices: d.expandedDevices.CloneNative(),
Expand Down Expand Up @@ -7927,6 +7926,20 @@ func (d *qemu) Render(options ...func(response any) error) (any, any, error) {
}
}

// Prepare the ETag.
etag := []any{d.architecture, d.ephemeral, d.profiles, d.localDevices.Sorted()}

configKeys := make([]string, 0, len(d.localConfig))
for k := range d.localConfig {
configKeys = append(configKeys, k)
}

sort.Strings(configKeys)

for _, k := range configKeys {
etag = append(etag, fmt.Sprintf("%s=%s", k, d.localConfig[k]))
}

return &instState, etag, nil
}

Expand Down

0 comments on commit 6d5825a

Please sign in to comment.