diff options
author | OpenGnSys Support Team <soporte-og@soleta.eu> | 2024-05-24 12:57:18 +0200 |
---|---|---|
committer | OpenGnSys Support Team <soporte-og@soleta.eu> | 2024-05-29 17:19:20 +0200 |
commit | a3af24d94a5a0881169e00cf7d02cdcd5bf6bfc7 (patch) | |
tree | 76a66422ea54f1305c7d440ed92bddf60acf21cf /src/client.c | |
parent | 7f8d874338fbafb35e7b79d17f224da8b918bebb (diff) |
src: replace old function to update image information
replace old legacy code, no functional changes are intended.
Diffstat (limited to 'src/client.c')
-rw-r--r-- | src/client.c | 98 |
1 files changed, 91 insertions, 7 deletions
diff --git a/src/client.c b/src/client.c index 93bd8f8..9c4ec59 100644 --- a/src/client.c +++ b/src/client.c @@ -497,6 +497,96 @@ static int og_resp_refresh(json_t *data, struct og_client *cli) return 0; } +static bool og_dbi_update_image(struct og_dbi *dbi, + const struct og_image_legacy *img_info, + const char *computer_id) +{ + const char *msglog; + dbi_result result; + int repo_id, sw_id; + + /* find repository identifier by repository ip and computer ID. */ + result = dbi_conn_queryf(dbi->conn, + "SELECT repositorios.idrepositorio" + " FROM repositorios" + " LEFT JOIN ordenadores USING (idrepositorio)" + " WHERE repositorios.ip='%s' AND ordenadores.idordenador=%s", + img_info->repo, computer_id); + if (!result) { + dbi_conn_error(dbi->conn, &msglog); + syslog(LOG_ERR, "failed to query database (%s:%d) %s\n", + __func__, __LINE__, msglog); + return false; + } + if (!dbi_result_next_row(result)) { + syslog(LOG_ERR, + "repository does not exist in database (%s:%d)\n", + __func__, __LINE__); + dbi_result_free(result); + return false; + } + repo_id = dbi_result_get_uint(result, "idrepositorio"); + dbi_result_free(result); + + /* find software id by computer ID, disk number and partition. */ + result = dbi_conn_queryf(dbi->conn, + "SELECT idperfilsoft" + " FROM ordenadores_particiones" + " WHERE idordenador=%s AND numdisk=%s AND numpar=%s", + computer_id, img_info->disk, img_info->part); + if (!result) { + dbi_conn_error(dbi->conn, &msglog); + syslog(LOG_ERR, "failed to query database (%s:%d) %s\n", + __func__, __LINE__, msglog); + return false; + } + if (!dbi_result_next_row(result)) { + syslog(LOG_ERR, + "software profile does not exist in database (%s:%d)\n", + __func__, __LINE__); + dbi_result_free(result); + return false; + } + sw_id = dbi_result_get_uint(result, "idperfilsoft"); + dbi_result_free(result); + + /* update image table with this new image. */ + result = dbi_conn_queryf(dbi->conn, + "UPDATE imagenes" + " SET idordenador=%s, numdisk=%s, numpar=%s, codpar=%s," + " idperfilsoft=%d, idrepositorio=%d," + " fechacreacion=NOW(), revision=revision+1" + " WHERE idimagen=%s", + computer_id, img_info->disk, img_info->part, img_info->code, + sw_id, repo_id, img_info->image_id); + + if (!result) { + dbi_conn_error(dbi->conn, &msglog); + syslog(LOG_ERR, "failed to query database (%s:%d) %s\n", + __func__, __LINE__, msglog); + return false; + } + dbi_result_free(result); + + /* attach image to partition. */ + result = dbi_conn_queryf(dbi->conn, + "UPDATE ordenadores_particiones" + " SET idimagen=%s, revision=(SELECT revision FROM imagenes WHERE idimagen=%s)," + " fechadespliegue=NOW()" + " WHERE idordenador=%s AND numdisk=%s AND numpar=%s", + img_info->image_id, img_info->image_id, + computer_id, img_info->disk, img_info->part); + if (!result) { + dbi_conn_error(dbi->conn, &msglog); + syslog(LOG_ERR, "failed to query database (%s:%d) %s\n", + __func__, __LINE__, msglog); + return false; + } + dbi_result_free(result); + + return true; +} + static int update_image_info(struct og_dbi *dbi, const char *image_id, const char *clonator, const char *compressor, const char *filesystem, const uint64_t datasize, @@ -628,13 +718,7 @@ static int og_resp_image_create(json_t *data, struct og_client *cli) return -1; } - res = actualizaCreacionImagen(dbi, - img_legacy.image_id, - img_legacy.disk, - img_legacy.part, - img_legacy.code, - img_legacy.repo, - soft_legacy.id); + res = og_dbi_update_image(dbi, &img_legacy, soft_legacy.id); if (!res) { og_dbi_close(dbi); syslog(LOG_ERR, "Problem updating client configuration\n"); |