summaryrefslogtreecommitdiffstats
path: root/src/rest.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/rest.c')
-rw-r--r--src/rest.c15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/rest.c b/src/rest.c
index 7685e05..c72d91e 100644
--- a/src/rest.c
+++ b/src/rest.c
@@ -2644,6 +2644,7 @@ static int og_cmd_create_image(json_t *element, struct og_msg_params *params)
struct og_dbi *dbi;
json_t *clients;
int err = 0;
+ bool found;
err = og_json_parse_create_image(element, params);
if (err < 0)
@@ -2665,23 +2666,29 @@ static int og_cmd_create_image(json_t *element, struct og_msg_params *params)
return -1;
}
- /* If there is a description, this means the image is not in the DB. */
- if (params->image.description[0]) {
+ found = og_dbi_get_image(dbi, &params->image);
+ if (!found) {
if (!og_msg_params_validate(params, OG_REST_PARAM_REPO)) {
+ syslog(LOG_ERR,
+ "missing repo parameter in request (%s:%d)\n",
+ __func__, __LINE__);
og_dbi_close(dbi);
return -1;
}
err = og_dbi_add_image(dbi, &params->image);
-
if (err < 0) {
og_dbi_close(dbi);
return err;
}
- snprintf(new_image_id, sizeof(new_image_id), "%u", err);
+ snprintf(new_image_id, sizeof(new_image_id), "%lu", params->image.id);
params->id = new_image_id;
json_object_set_new(element, "id", json_string(params->id));
+ } else {
+ syslog(LOG_INFO, "updating existing image `%s'\n", params->image.name);
+ snprintf(new_image_id, sizeof(new_image_id), "%lu", params->image.id);
+ params->id = new_image_id;
}
clients = json_copy(element);