diff --git a/src/archiver.c b/src/archiver.c index fbb91a8..89b2927 100644 --- a/src/archiver.c +++ b/src/archiver.c @@ -1301,6 +1301,8 @@ char *simple_archiver_error_to_string(enum SDArchiverStateReturns error) { return "Failed to extract symlink (internal error)"; case SDAS_FAILED_TO_CHANGE_CWD: return "Failed to change current working directory"; + case SDAS_INVALID_WRITE_VERSION: + return "Unsupported write version file format"; default: return "Unknown error"; } @@ -1332,6 +1334,20 @@ void simple_archiver_free_state(SDArchiverState **state) { int simple_archiver_write_all(FILE *out_f, SDArchiverState *state, const SDArchiverLinkedList *filenames) { + switch (state->parsed->write_version) { + case 0: + return simple_archiver_write_v0(out_f, state, filenames); + case 1: + return simple_archiver_write_v1(out_f, state, filenames); + default: + fprintf(stderr, "ERROR: Unsupported write version %u!\n", + state->parsed->write_version); + return SDAS_INVALID_WRITE_VERSION; + } +} + +int simple_archiver_write_v0(FILE *out_f, SDArchiverState *state, + const SDArchiverLinkedList *filenames) { // First create a "set" of absolute paths to given filenames. __attribute__((cleanup(simple_archiver_hash_map_free))) SDArchiverHashMap *abs_filenames = simple_archiver_hash_map_init(); @@ -1471,6 +1487,13 @@ int simple_archiver_write_all(FILE *out_f, SDArchiverState *state, return SDAS_SUCCESS; } +int simple_archiver_write_v1(FILE *out_f, SDArchiverState *state, + const SDArchiverLinkedList *filenames) { + // TODO Impl. + fprintf(stderr, "Writing v1 unimplemented\n"); + return SDAS_INTERNAL_ERROR; +} + int simple_archiver_parse_archive_info(FILE *in_f, int_fast8_t do_extract, const SDArchiverState *state) { uint8_t buf[32]; diff --git a/src/archiver.h b/src/archiver.h index 51b6abc..2b8fbf2 100644 --- a/src/archiver.h +++ b/src/archiver.h @@ -51,7 +51,8 @@ enum SDArchiverStateReturns { SDAS_INTERNAL_ERROR, SDAS_FAILED_TO_CREATE_MAP, SDAS_FAILED_TO_EXTRACT_SYMLINK, - SDAS_FAILED_TO_CHANGE_CWD + SDAS_FAILED_TO_CHANGE_CWD, + SDAS_INVALID_WRITE_VERSION }; /// Returned pointer must not be freed. @@ -65,6 +66,12 @@ void simple_archiver_free_state(SDArchiverState **state); int simple_archiver_write_all(FILE *out_f, SDArchiverState *state, const SDArchiverLinkedList *filenames); +int simple_archiver_write_v0(FILE *out_f, SDArchiverState *state, + const SDArchiverLinkedList *filenames); + +int simple_archiver_write_v1(FILE *out_f, SDArchiverState *state, + const SDArchiverLinkedList *filenames); + /// Returns zero on success. int simple_archiver_parse_archive_info(FILE *in_f, int_fast8_t do_extract, const SDArchiverState *state); diff --git a/src/parser.c b/src/parser.c index 5da4653..2bc5b25 100644 --- a/src/parser.c +++ b/src/parser.c @@ -169,6 +169,9 @@ void simple_archiver_print_usage(void) { fprintf(stderr, "--temp-files-dir