Skip to content

Commit

Permalink
incusd/instance/lxc: 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 6d5825a commit 4ef89d8
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions internal/server/instance/drivers/driver_lxc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3531,9 +3531,7 @@ func (d *lxc) 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 @@ -3558,12 +3556,13 @@ func (d *lxc) 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,
Expand Down Expand Up @@ -3593,6 +3592,20 @@ func (d *lxc) 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 4ef89d8

Please sign in to comment.