]> git.seodisparate.com - SimpleArchiver/commitdiff
Migrate UsersInfos struct to Parsed struct
authorStephen Seo <seo.disparate@gmail.com>
Thu, 2 Jan 2025 04:24:55 +0000 (13:24 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Thu, 2 Jan 2025 04:24:55 +0000 (13:24 +0900)
src/archiver.c
src/archiver.h
src/parser.c
src/parser.h

index c8062b1c53e0ba1eb4d649b23ba1d52b8503f433..d62c08795573c1777d799b2a4492481619800631 100644 (file)
@@ -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) {
index d40ae8096d228a699f2548493290b44fd72db4f1..44a782621cfda69af616b4802d193734b6f71741 100644 (file)
@@ -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 {
index ddc556e9513547326a85f109b3577dd2979de4e8..0b7ef56c544b75bb47aa9ef3c36be7dd25b20257 100644 (file)
@@ -24,6 +24,7 @@
 #include <string.h>
 
 #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(
index 71cd7c6aba38f0f5e2101aab36e92c3c61e233d5..f2a42842662995a1cce0ba7e8f5843ed7fa07ad2 100644 (file)
@@ -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 {