summaryrefslogtreecommitdiffstats
path: root/src/rest.c
diff options
context:
space:
mode:
authorAlejandro Sirgo Rica <asirgo@soleta.eu>2024-12-16 11:59:15 +0100
committerAlejandro Sirgo Rica <asirgo@soleta.eu>2024-12-16 11:59:15 +0100
commit31d426b01847f5b386f285043b453702f9525ee9 (patch)
treee10ab8e08c153be48fcb32a7404596cd4c822236 /src/rest.c
parent5e21716afba461a4debae8f99f0e6e967766bb28 (diff)
rest: prevent repo deletion if it is in useHEADmaster
Check if the repo is used by any client before the deletion in /repository/delete
Diffstat (limited to 'src/rest.c')
-rw-r--r--src/rest.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/rest.c b/src/rest.c
index 17878b0..6a614b2 100644
--- a/src/rest.c
+++ b/src/rest.c
@@ -5234,6 +5234,30 @@ static int og_cmd_post_repository_delete(struct og_rest_ctx *ctx)
}
result = dbi_conn_queryf(dbi->conn,
+ "SELECT idrepositorio FROM ordenadores "
+ "WHERE idrepositorio=%u",
+ repo_id);
+
+ if (!result) {
+ dbi_conn_error(dbi->conn, &msglog);
+ syslog(LOG_ERR, "failed to query database (%s:%d) %s\n",
+ __func__, __LINE__, msglog);
+ og_dbi_close(dbi);
+ ctx->http_error = OG_HTTP_500_INTERNAL_SERVER_ERROR;
+ return -1;
+ }
+
+ if (dbi_result_get_numrows(result) > 0) {
+ syslog(LOG_ERR, "Repository of id %u in use by clients\n",
+ repo_id);
+ dbi_result_free(result);
+ og_dbi_close(dbi);
+ ctx->http_error = OG_HTTP_423_LOCKED;
+ return -1;
+ }
+ dbi_result_free(result);
+
+ result = dbi_conn_queryf(dbi->conn,
"DELETE FROM repositorios "
"WHERE idrepositorio=%u OR alias=%u",
repo_id, repo_id);