Compare commits

..

13 commits

Author SHA1 Message Date
f89e5f7640 Test/fix symlink test/extract in v1 file format
All checks were successful
Run Unit Tests / build-and-run-unit-tests (push) Successful in 11s
2024-09-30 19:17:57 +09:00
0ae80168e3 Fix v1 archive decompression
Previous implementation sent too many bytes to decompressor if size was
less than 1024.
2024-09-30 19:17:57 +09:00
d93f62a0cb Remove unnecessary printf used for testing 2024-09-30 19:17:57 +09:00
8f33d62392 Impl. extract with decompressor file format v1 2024-09-30 19:17:57 +09:00
52bbfa4e65 v1 extract skip non-specified args if exists 2024-09-30 19:17:57 +09:00
8bedc750ba Impl. setting stored UID/GID if EUID 0 2024-09-30 19:17:57 +09:00
aaebe09347 "Fix" Linux/Mac/Unix usage 2024-09-30 19:17:57 +09:00
0a776cae37 Impl. simple test/extract new file format (WIP)
TODO:
    Extract symlinks in new format (implemented but untested).
    Extract compressed files in new format.
2024-09-30 19:17:57 +09:00
f472ad1a6b Split up handling of archive file based on version 2024-09-30 19:17:57 +09:00
dcd2e531e6 Fix typo 2024-09-30 19:17:57 +09:00
ef49b37648 Fix typo in file format specification version 1 2024-09-30 19:17:57 +09:00
6ad609e7fc Create file format for format version 1
This is in preparation of improving compression by concatenating files
together before compressing them to reduce the per-file overhead.
2024-09-30 19:17:57 +09:00
b098fd6d69 Error if "-C <dir>" where "dir" doesn't exist
All checks were successful
Run Unit Tests / build-and-run-unit-tests (push) Successful in 5s
2024-09-30 19:16:29 +09:00
3 changed files with 32 additions and 6 deletions

View file

@ -67,12 +67,13 @@ int main(int argc, const char **argv) {
} }
} }
SDArchiverParsedStatus parsed_status;
__attribute__((cleanup(simple_archiver_list_free))) __attribute__((cleanup(simple_archiver_list_free)))
SDArchiverLinkedList *filenames = SDArchiverLinkedList *filenames =
simple_archiver_parsed_to_filenames(&parsed); simple_archiver_parsed_to_filenames(&parsed, &parsed_status);
if (!filenames) { if (!filenames || parsed_status != SDAPS_SUCCESS) {
fprintf(stderr, fprintf(stderr, "ERROR: %s!\n",
"ERROR: Failed to resolve filenames from positional arguments!\n"); simple_archiver_parsed_status_to_str(parsed_status));
return 8; return 8;
} }

View file

@ -131,6 +131,17 @@ int list_remove_same_str_fn(void *data, void *ud) {
return 0; return 0;
} }
char *simple_archiver_parsed_status_to_str(SDArchiverParsedStatus status) {
switch (status) {
case SDAPS_SUCCESS:
return "Success";
case SDAPS_NO_USER_CWD:
return "No user current working directory (-C <dir>)";
default:
return "Unknown error";
}
}
void simple_archiver_print_usage(void) { void simple_archiver_print_usage(void) {
fprintf(stderr, "Usage flags:\n"); fprintf(stderr, "Usage flags:\n");
fprintf(stderr, "-c : create archive file\n"); fprintf(stderr, "-c : create archive file\n");
@ -367,7 +378,7 @@ void simple_archiver_free_parsed(SDArchiverParsed *parsed) {
} }
SDArchiverLinkedList *simple_archiver_parsed_to_filenames( SDArchiverLinkedList *simple_archiver_parsed_to_filenames(
const SDArchiverParsed *parsed) { const SDArchiverParsed *parsed, SDArchiverParsedStatus *status_out) {
SDArchiverLinkedList *files_list = simple_archiver_list_init(); SDArchiverLinkedList *files_list = simple_archiver_list_init();
__attribute__((cleanup(simple_archiver_hash_map_free))) __attribute__((cleanup(simple_archiver_hash_map_free)))
SDArchiverHashMap *hash_map = simple_archiver_hash_map_init(); SDArchiverHashMap *hash_map = simple_archiver_hash_map_init();
@ -381,6 +392,9 @@ SDArchiverLinkedList *simple_archiver_parsed_to_filenames(
original_cwd = realpath(".", NULL); original_cwd = realpath(".", NULL);
if (chdir(parsed->user_cwd)) { if (chdir(parsed->user_cwd)) {
simple_archiver_list_free(&files_list); simple_archiver_list_free(&files_list);
if (status_out) {
*status_out = SDAPS_NO_USER_CWD;
}
return NULL; return NULL;
} }
} }
@ -607,5 +621,8 @@ SDArchiverLinkedList *simple_archiver_parsed_to_filenames(
} }
} }
if (status_out) {
*status_out = SDAPS_SUCCESS;
}
return files_list; return files_list;
} }

View file

@ -59,6 +59,14 @@ typedef struct SDArchiverFileInfo {
char *link_dest; char *link_dest;
} SDArchiverFileInfo; } SDArchiverFileInfo;
typedef enum SDArchiverParsedStatus {
SDAPS_SUCCESS,
SDAPS_NO_USER_CWD,
} SDArchiverParsedStatus;
/// Returned c-string does not need to be free'd.
char *simple_archiver_parsed_status_to_str(SDArchiverParsedStatus status);
void simple_archiver_print_usage(void); void simple_archiver_print_usage(void);
SDArchiverParsed simple_archiver_create_parsed(void); SDArchiverParsed simple_archiver_create_parsed(void);
@ -74,6 +82,6 @@ void simple_archiver_free_parsed(SDArchiverParsed *parsed);
/// Each entry in the linked list is an SDArchiverFileInfo object. /// Each entry in the linked list is an SDArchiverFileInfo object.
SDArchiverLinkedList *simple_archiver_parsed_to_filenames( SDArchiverLinkedList *simple_archiver_parsed_to_filenames(
const SDArchiverParsed *parsed); const SDArchiverParsed *parsed, SDArchiverParsedStatus *status_out);
#endif #endif