Create user folder on registering

This commit is contained in:
2026-06-17 17:34:07 +02:00
parent 8132ecd9d8
commit 2910c44352

View File

@@ -123,6 +123,7 @@ bool read_users_file(char *file_path, Users *users) {
if (line.count == 0) {
noh_log(NOH_ERROR, "%s %zu: Line not in username:hash format.", file_path, i);
noh_string_free(&users_file);
return false;
}
@@ -145,7 +146,9 @@ bool write_users_file(char *file_path, Users *users, User *user_to_skip) {
noh_string_append_cstr(&users_file, "\n");
}
return noh_string_write_file(&users_file, file_path);
bool result = noh_string_write_file(&users_file, file_path);
noh_string_free(&users_file);
return result;
}
@@ -193,6 +196,11 @@ bool register_user(Noh_String_View library_path, Noh_String_View username, Noh_S
user->hash = noh_sv_from_string(hashed);
if (!write_users_file(users_file_path.elems, &users, NULL)) noh_return_defer(false);
// Create user folder if needed.
Noh_String user_folder_path = build_path(false, &library_path, &username);
noh_string_append_null(&user_folder_path);
if (!noh_mkdir_if_needed(user_folder_path.elems)) noh_return_defer(false);
noh_return_defer(true);
}
@@ -201,6 +209,11 @@ bool register_user(Noh_String_View library_path, Noh_String_View username, Noh_S
noh_da_append(&users, ((User){ .username = username, .hash = noh_sv_from_string(hashed) }));
if (!write_users_file(users_file_path.elems, &users, NULL)) noh_return_defer(false);
// Create user folder if needed.
Noh_String user_folder_path = build_path(false, &library_path, &username);
noh_string_append_null(&user_folder_path);
if (!noh_mkdir_if_needed(user_folder_path.elems)) noh_return_defer(false);
defer:
noh_da_free(&users);
return result;