From 333d38ac03df28eb1e3fd430299514e97c9f643e Mon Sep 17 00:00:00 2001 From: Stephen Seo Date: Thu, 2 Jan 2025 13:24:55 +0900 Subject: [PATCH] Migrate UsersInfos struct to Parsed struct --- src/archiver.c | 14 ++++++-------- src/archiver.h | 2 -- src/parser.c | 3 +++ src/parser.h | 2 ++ 4 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/archiver.c b/src/archiver.c index c8062b1..d62c087 100644 --- a/src/archiver.c +++ b/src/archiver.c @@ -1937,7 +1937,7 @@ int internal_write_dir_entries(void *data, void *ud) { if (state->parsed->write_version == 3) { u32 = stat_buf.st_uid; const char *username = simple_archiver_hash_map_get( - state->users_infos.UidToUname, &u32, sizeof(uint32_t)); + state->parsed->users_infos.UidToUname, &u32, sizeof(uint32_t)); if (username) { unsigned long length = strlen(username); if (length > 0xFFFF) { @@ -1968,7 +1968,7 @@ int internal_write_dir_entries(void *data, void *ud) { u32 = stat_buf.st_gid; const char *groupname = simple_archiver_hash_map_get( - state->users_infos.GidToGname, &u32, sizeof(uint32_t)); + state->parsed->users_infos.GidToGname, &u32, sizeof(uint32_t)); if (groupname) { unsigned long length = strlen(groupname); if (length > 0xFFFF) { @@ -2064,14 +2064,12 @@ SDArchiverState *simple_archiver_init_state(const SDArchiverParsed *parsed) { state->count = 0; state->max = 0; state->digits = 10; - state->users_infos = simple_archiver_users_get_system_info(); return state; } void simple_archiver_free_state(SDArchiverState **state) { if (state && *state) { - simple_archiver_users_free_users_infos(&(*state)->users_infos); free(*state); *state = NULL; } @@ -4418,7 +4416,7 @@ int simple_archiver_write_v3(FILE *out_f, SDArchiverState *state, u32 = stat_buf.st_uid; char *username = simple_archiver_hash_map_get( - state->users_infos.UidToUname, + state->parsed->users_infos.UidToUname, &u32, sizeof(uint32_t)); if (username) { @@ -4444,7 +4442,7 @@ int simple_archiver_write_v3(FILE *out_f, SDArchiverState *state, u32 = stat_buf.st_gid; char *groupname = simple_archiver_hash_map_get( - state->users_infos.GidToGname, + state->parsed->users_infos.GidToGname, &u32, sizeof(uint32_t)); if (groupname) { @@ -4615,7 +4613,7 @@ int simple_archiver_write_v3(FILE *out_f, SDArchiverState *state, u32 = file_info_struct->uid; char *username = simple_archiver_hash_map_get( - state->users_infos.UidToUname, &u32, sizeof(uint32_t)); + state->parsed->users_infos.UidToUname, &u32, sizeof(uint32_t)); if (username) { unsigned long name_length = strlen(username); if (name_length > 0xFFFF) { @@ -4639,7 +4637,7 @@ int simple_archiver_write_v3(FILE *out_f, SDArchiverState *state, u32 = file_info_struct->gid; char *groupname = simple_archiver_hash_map_get( - state->users_infos.GidToGname, &u32, sizeof(uint32_t)); + state->parsed->users_infos.GidToGname, &u32, sizeof(uint32_t)); if (groupname) { unsigned long group_length = strlen(groupname); if (group_length > 0xFFFF) { diff --git a/src/archiver.h b/src/archiver.h index d40ae80..44a7826 100644 --- a/src/archiver.h +++ b/src/archiver.h @@ -27,7 +27,6 @@ #include "data_structures/hash_map.h" #include "data_structures/linked_list.h" #include "parser.h" -#include "users.h" typedef struct SDArchiverState { /* @@ -39,7 +38,6 @@ typedef struct SDArchiverState { size_t count; size_t max; size_t digits; - UsersInfos users_infos; } SDArchiverState; typedef enum SDArchiverStateReturns { diff --git a/src/parser.c b/src/parser.c index ddc556e..0b7ef56 100644 --- a/src/parser.c +++ b/src/parser.c @@ -24,6 +24,7 @@ #include #include "platforms.h" +#include "users.h" #if SIMPLE_ARCHIVER_PLATFORM == SIMPLE_ARCHIVER_PLATFORM_LINUX || \ SIMPLE_ARCHIVER_PLATFORM == SIMPLE_ARCHIVER_PLATFORM_MAC || \ SIMPLE_ARCHIVER_PLATFORM == SIMPLE_ARCHIVER_PLATFORM_COSMOPOLITAN @@ -239,6 +240,7 @@ SDArchiverParsed simple_archiver_create_parsed(void) { parsed.gid = 0; parsed.file_permissions = 0; parsed.dir_permissions = 0; + parsed.users_infos = simple_archiver_users_get_system_info(); return parsed; } @@ -585,6 +587,7 @@ void simple_archiver_free_parsed(SDArchiverParsed *parsed) { free(parsed->working_files); parsed->working_files = NULL; } + simple_archiver_users_free_users_infos(&parsed->users_infos); } SDArchiverLinkedList *simple_archiver_parsed_to_filenames( diff --git a/src/parser.h b/src/parser.h index 71cd7c6..f2a4284 100644 --- a/src/parser.h +++ b/src/parser.h @@ -24,6 +24,7 @@ // Local includes. #include "data_structures/linked_list.h" +#include "users.h" typedef struct SDArchiverParsed { /// Each bit is a flag. @@ -76,6 +77,7 @@ typedef struct SDArchiverParsed { /// 0b xxx1 xxxx xxxx - other execute uint_fast16_t file_permissions; uint_fast16_t dir_permissions; + UsersInfos users_infos; } SDArchiverParsed; typedef struct SDArchiverFileInfo {