Skip to content

Commit

Permalink
Migrate UsersInfos struct to Parsed struct
Browse files Browse the repository at this point in the history
  • Loading branch information
Stephen-Seo committed Jan 2, 2025
1 parent 5d7d823 commit 333d38a
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
14 changes: 6 additions & 8 deletions src/archiver.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
2 changes: 0 additions & 2 deletions src/archiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/*
Expand All @@ -39,7 +38,6 @@ typedef struct SDArchiverState {
size_t count;
size_t max;
size_t digits;
UsersInfos users_infos;
} SDArchiverState;

typedef enum SDArchiverStateReturns {
Expand Down
3 changes: 3 additions & 0 deletions src/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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(
Expand Down
2 changes: 2 additions & 0 deletions src/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

// Local includes.
#include "data_structures/linked_list.h"
#include "users.h"

typedef struct SDArchiverParsed {
/// Each bit is a flag.
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 333d38a

Please sign in to comment.