summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlejandro Sirgo Rica <asirgo@soleta.eu>2024-10-04 12:39:22 +0200
committerAlejandro Sirgo Rica <asirgo@soleta.eu>2024-10-04 12:39:22 +0200
commitca3503b716a9189a4cadd8e75cc701fe5dd00c9e (patch)
tree2b8c53dba90e9c7529a1f1362dfcc56c074cda01 /src
parentd6d15a753ea9abc98f8e401adc031b67679b34c6 (diff)
src: remove placeholder image in failed image/createv1.2.5-21
Delete image data after a failed image creation.
Diffstat (limited to 'src')
-rw-r--r--src/client.c44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/client.c b/src/client.c
index 5842372..bc66b4b 100644
--- a/src/client.c
+++ b/src/client.c
@@ -1274,8 +1274,49 @@ static int og_agent_http_response_code(const char *buf)
return -1;
}
+static int og_clear_image_placeholder()
+{
+ uint32_t image_id = 0;
+ struct og_dbi *dbi;
+ dbi_result result;
+
+ dbi = og_dbi_open(&ogconfig.db);
+ if (!dbi) {
+ syslog(LOG_ERR, "cannot open connection database (%s:%d)\n",
+ __func__, __LINE__);
+ return -1;
+ }
+
+ result = dbi_conn_queryf(dbi->conn,
+ "SELECT idimagen FROM imagenes WHERE fechacreacion IS NULL");
+ if (!result) {
+ syslog(LOG_ERR, "failed to query database\n");
+ return -1;
+ }
+
+ if (!dbi_result_next_row(result)) {
+ dbi_result_free(result);
+ og_dbi_close(dbi);
+ return 0;
+ }
+
+ image_id = dbi_result_get_uint(result, "idimagen");
+ dbi_result_free(result);
+
+ syslog(LOG_INFO, "Trying to delete uninitialized image with id %d\n", image_id);
+
+ if (og_dbi_delete_image(dbi, image_id) < 0) {
+ og_dbi_close(dbi);
+ return -1;
+ }
+
+ og_dbi_close(dbi);
+ return 0;
+}
+
int og_agent_state_process_response(struct og_client *cli)
{
+ enum og_cmd_type cmd_type = cli->last_cmd;
int ret, err = -1, code;
json_error_t json_err;
bool success;
@@ -1326,6 +1367,9 @@ int og_agent_state_process_response(struct og_client *cli)
else
cli->last_cmd_result = OG_FAILURE;
+ if (!success && cmd_type == OG_CMD_IMAGE_CREATE)
+ og_clear_image_placeholder();
+
if (code != 200 && code != 103) {
cli->last_cmd_id = 0;
return ret;