Skip to content

Commit 1097be1

Browse files
committed
incusd/image: Handle all alias cases
Signed-off-by: Stéphane Graber <[email protected]>
1 parent 809ec79 commit 1097be1

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

cmd/incusd/images.go

+12-5
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,6 @@ func getImgPostInfo(ctx context.Context, s *state.State, r *http.Request, buildd
820820
}
821821

822822
var exists bool
823-
824823
err = s.DB.Cluster.Transaction(ctx, func(ctx context.Context, tx *db.ClusterTx) error {
825824
// Check if the image already exists
826825
exists, err = tx.ImageExists(ctx, project, info.Fingerprint)
@@ -1017,7 +1016,6 @@ func imagesPost(d *Daemon, r *http.Request) response.Response {
10171016
fingerprint := r.Header.Get("X-Incus-fingerprint")
10181017

10191018
var imageMetadata map[string]any
1020-
10211019
if !trusted && (secret == "" || fingerprint == "") {
10221020
return response.Forbidden(nil)
10231021
} else {
@@ -1193,9 +1191,18 @@ func imagesPost(d *Daemon, r *http.Request) response.Response {
11931191
}
11941192

11951193
// Apply any provided alias
1196-
aliases, ok := imageMetadata["aliases"]
1197-
if ok {
1198-
req.Aliases = aliases.([]api.ImageAlias)
1194+
if len(req.Aliases) == 0 {
1195+
aliases, ok := imageMetadata["aliases"]
1196+
if ok {
1197+
// Used to get aliases from push mode image copy operation.
1198+
aliases, ok := aliases.([]api.ImageAlias)
1199+
if ok {
1200+
req.Aliases = aliases
1201+
}
1202+
} else if len(info.Aliases) > 0 {
1203+
// Used to get aliases from HTTP headers on raw image imports.
1204+
req.Aliases = info.Aliases
1205+
}
11991206
}
12001207

12011208
err = s.DB.Cluster.Transaction(context.TODO(), func(ctx context.Context, tx *db.ClusterTx) error {

0 commit comments

Comments
 (0)