mirror of https://git.48k.eu/ogserver
rest: prevent repo deletion if it is in use
Check if the repo is used by any client before the deletion in /repository/deletemaster
parent
5e21716afb
commit
31d426b018
24
src/rest.c
24
src/rest.c
|
@ -5233,6 +5233,30 @@ static int og_cmd_post_repository_delete(struct og_rest_ctx *ctx)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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,
|
result = dbi_conn_queryf(dbi->conn,
|
||||||
"DELETE FROM repositorios "
|
"DELETE FROM repositorios "
|
||||||
"WHERE idrepositorio=%u OR alias=%u",
|
"WHERE idrepositorio=%u OR alias=%u",
|
||||||
|
|
Loading…
Reference in New Issue