From d8b78bb9221866a544066b551c6d31188adf4035 Mon Sep 17 00:00:00 2001 From: Roberto Hueso Gómez Date: Wed, 14 Oct 2020 14:43:15 +0200 Subject: #942 Extend GET /images function This extension removes replaces the field 'filename' for 'name' and adds new fields (software_id, type and id). These new fields are useful when restoring an image. Request: GET /images Response: 200 OK { "disk": { "free": 37091418112, "total": 52573995008 }, "images": [ { "datasize": 5939200000, "id": 25, "modified": "Wed Oct 14 11:49:00 2020", "name": "archlinux", "permissions": "744", "size": 1844222333, "software_id": 19, "type": 1 } ] } --- src/dbi.h | 4 +++- src/rest.c | 24 ++++++++++++++++++------ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/dbi.h b/src/dbi.h index 8cd6fe6..1daaeb8 100644 --- a/src/dbi.h +++ b/src/dbi.h @@ -51,10 +51,12 @@ struct og_image_legacy { struct og_image { char name[OG_DB_IMAGE_NAME_MAXLEN + 1]; char description[OG_DB_IMAGE_DESCRIPTION_MAXLEN + 1]; - const char *filename; + uint64_t software_id; uint64_t center_id; uint64_t datasize; uint64_t group_id; + uint64_t type; + uint64_t id; struct stat image_stats; }; diff --git a/src/rest.c b/src/rest.c index 8b28b1d..d77a754 100644 --- a/src/rest.c +++ b/src/rest.c @@ -1595,7 +1595,7 @@ static int og_get_image_stats(const char *name, const char *dir = ogconfig.repo.dir; char filename[PATH_MAX + 1]; - snprintf(filename, sizeof(filename), "%s/%s", dir, name); + snprintf(filename, sizeof(filename), "%s/%s.img", dir, name); if (stat(filename, image_stats) < 0) { syslog(LOG_ERR, "%s image does not exists", name); return -1; @@ -1646,8 +1646,8 @@ static json_t *og_json_image_alloc(struct og_image *image) modified = ctime(&image->image_stats.st_mtime); modified[strlen(modified) - 1] = '\0'; - json_object_set_new(image_json, "filename", - json_string(image->filename)); + json_object_set_new(image_json, "name", + json_string(image->name)); json_object_set_new(image_json, "datasize", json_integer(image->datasize)); json_object_set_new(image_json, "size", @@ -1656,6 +1656,12 @@ static json_t *og_json_image_alloc(struct og_image *image) json_string(modified)); json_object_set_new(image_json, "permissions", json_string(perms_string)); + json_object_set_new(image_json, "software_id", + json_integer(image->software_id)); + json_object_set_new(image_json, "type", + json_integer(image->type)); + json_object_set_new(image_json, "id", + json_integer(image->id)); return image_json; } @@ -1693,17 +1699,23 @@ static int og_cmd_images(char *buffer_reply) result = dbi_conn_queryf(dbi->conn, "SELECT i.nombreca, o.nombreordenador, " " i.clonator, i.compressor, " - " i.filesystem, i.datasize " + " i.filesystem, i.datasize, " + " i.idperfilsoft, i.tipo, " + " i.idimagen " "FROM imagenes i " "LEFT JOIN ordenadores o " "ON i.idordenador = o.idordenador"); while (dbi_result_next_row(result)) { image = (struct og_image){0}; - image.filename = dbi_result_get_string(result, "nombreca"); image.datasize = dbi_result_get_ulonglong(result, "datasize"); + image.software_id = dbi_result_get_ulonglong(result, "idperfilsoft"); + image.type = dbi_result_get_ulonglong(result, "tipo"); + image.id = dbi_result_get_ulonglong(result, "idimagen"); + snprintf(image.name, sizeof(image.name), "%s", + dbi_result_get_string(result, "nombreca")); - if (og_get_image_stats(image.filename, &image.image_stats)) { + if (og_get_image_stats(image.name, &image.image_stats)) { continue; } -- cgit v1.2.3-18-g5258