added mutex
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Make (push) Has been cancelled
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-CMake (push) Has been cancelled
Prepare Build and Testing executable binary / Prepare-Build-Testing-With-Meson (push) Has been cancelled

This commit is contained in:
wt committed 2025-04-18 15:47:36 +07:00
1 parent e74ab7a560
commit e6ec1527da
8 files changed
+36 -18

No files matched your search

+8 -5
View File
@@ -38,11 +38,13 @@ void delete_user(const httplib::Request& request, httplib::Response& response)
syslog(LOG_ERR, "access reject in delete user request");
return;
}
std::ifstream usersfile(USERS_FILE);
nlohmann::json all_users = nlohmann::json::parse(usersfile);
usersfile.close();
nlohmann::json all_users;
{
std::lock_guard<std::mutex> lock(usersfilemutex);
std::ifstream usersfile(USERS_FILE);
all_users = nlohmann::json::parse(usersfile);
usersfile.close();
}
std::string deluserid = userid;
if (json_body["userid"] != nullptr) {
deluserid = json_body["userid"];
@@ -79,6 +81,7 @@ void delete_user(const httplib::Request& request, httplib::Response& response)
syslog(LOG_ERR, "can't find this user in delete user request");
return;
}
std::lock_guard<std::mutex> lock(usersfilemutex);
std::ofstream usersfilew(USERS_FILE);
usersfilew << all_users.dump(4);
usersfilew.close();