|
1 | | -/* |
2 | | - * Prototype for extract API |
3 | | - * |
4 | | - * |
5 | | - * */ |
6 | | - |
| 1 | +/* acquire/acquire_extract.h */ |
7 | 2 | #ifndef LIBACQUIRE_ACQUIRE_EXTRACT_H |
8 | 3 | #define LIBACQUIRE_ACQUIRE_EXTRACT_H |
9 | 4 |
|
10 | 5 | /** |
11 | 6 | * @file acquire_extract.h |
12 | | - * @brief Extraction of compressed archives. |
| 7 | + * @brief Public API for synchronous and asynchronous archive extraction. |
13 | 8 | * |
14 | | - * Provides functions to decompress and extract files from archives, |
15 | | - * supporting common formats like ZIP, TAR, GZ, etc. |
16 | | - * NOTE: Always `#include` this when adding new extraction |
17 | | - * implementations, to ensure implementation matches the prototype. |
18 | | - * |
19 | | - * The extract API is for expanding the contents of archives |
| 9 | + * This module provides a handle-based API for both blocking and non-blocking |
| 10 | + * archive extraction. The archive format is detected automatically by the |
| 11 | + * backend (e.g., libarchive). |
20 | 12 | */ |
21 | 13 |
|
| 14 | +#include "acquire_handle.h" |
| 15 | +#include "libacquire_export.h" |
| 16 | + |
22 | 17 | #ifdef __cplusplus |
23 | 18 | extern "C" { |
24 | 19 | #endif /* __cplusplus */ |
25 | 20 |
|
26 | | -#include "libacquire_export.h" |
27 | | - |
28 | | -enum Archive { |
29 | | - LIBACQUIRE_ZIP, |
30 | | - LIBACQUIRE_INFER, |
31 | | - LIBACQUIRE_UNSUPPORTED_ARCHIVE |
32 | | -}; |
| 21 | +/* --- Asynchronous API --- */ |
33 | 22 |
|
34 | 23 | /** |
35 | | - * @brief Extract an archive file into a specified directory. |
| 24 | + * @brief Begins an asynchronous extraction (non-blocking). |
| 25 | + * |
| 26 | + * This function initializes the extraction process. The actual work happens |
| 27 | + * during calls to `acquire_extract_async_poll`. |
36 | 28 | * |
37 | | - * Supports formats based on `enum Archive` discriminant. |
| 29 | + * @param handle An initialized acquire handle. |
| 30 | + * @param archive_path The path to the source archive file (e.g., .zip, |
| 31 | + * .tar.gz). |
| 32 | + * @param dest_path The directory to extract files into. |
| 33 | + * @return 0 on success, non-zero on failure. |
| 34 | + */ |
| 35 | +extern LIBACQUIRE_EXPORT int |
| 36 | +acquire_extract_async_start(struct acquire_handle *handle, |
| 37 | + const char *archive_path, const char *dest_path); |
| 38 | + |
| 39 | +/** |
| 40 | + * @brief Polls the status of an asynchronous extraction, processing one entry. |
38 | 41 | * |
39 | | - * @param archive `enum Archive` discriminant type of archive. |
40 | | - * @param archive_filepath Path to the archive file. |
41 | | - * @param output_folder Directory path where contents should be extracted. |
| 42 | + * In a non-blocking application, this should be called repeatedly until it |
| 43 | + * no longer returns `ACQUIRE_IN_PROGRESS`. Each call processes one file or |
| 44 | + * directory entry from the archive. |
42 | 45 | * |
43 | | - * @return `EXIT_SUCCESS` if extraction succeeds; |
44 | | - * `EXIT_FAILURE` or non-`EXIT_SUCCESS` otherwise. |
| 46 | + * @param handle The handle for the in-progress operation. |
| 47 | + * @return The current status of the operation. |
45 | 48 | */ |
46 | | -extern LIBACQUIRE_EXPORT int extract_archive(enum Archive archive, |
47 | | - const char *archive_filepath, |
48 | | - const char *output_folder); |
| 49 | +extern LIBACQUIRE_EXPORT enum acquire_status |
| 50 | +acquire_extract_async_poll(struct acquire_handle *handle); |
49 | 51 |
|
50 | 52 | /** |
51 | | - * @brief Determine archive type based on extension |
| 53 | + * @brief Requests cancellation of an asynchronous extraction. |
52 | 54 | * |
53 | | - * TODO: magic bytes whence `LIBACQUIRE_INFER` |
| 55 | + * The cancellation will be processed on the next call to |
| 56 | + * `acquire_extract_async_poll`. |
54 | 57 | * |
55 | | - * @param extension Simple end of filepath, like ".zip" or ".tar.gz". |
| 58 | + * @param handle The handle for the operation to be cancelled. |
| 59 | + */ |
| 60 | +extern LIBACQUIRE_EXPORT void |
| 61 | +acquire_extract_async_cancel(struct acquire_handle *handle); |
| 62 | + |
| 63 | +/* --- Synchronous API --- */ |
| 64 | + |
| 65 | +/** |
| 66 | + * @brief Extracts an archive synchronously (blocking). |
| 67 | + * |
| 68 | + * This is a helper function that wraps the asynchronous API, calling `poll` |
| 69 | + * in a loop until the operation is complete. |
56 | 70 | * |
57 | | - * @return `enum Archive` discriminant; including potential values of |
58 | | - * `LIBACQUIRE_UNSUPPORTED_ARCHIVE` xor `LIBACQUIRE_INFER`. |
| 71 | + * @param handle An initialized acquire handle. |
| 72 | + * @param archive_path The path to the source archive file. |
| 73 | + * @param dest_path The directory to extract files into. |
| 74 | + * @return 0 on success, non-zero on failure. Details can be retrieved from the |
| 75 | + * handle. |
59 | 76 | */ |
60 | | -extern LIBACQUIRE_EXPORT enum Archive extension2archive(const char *extension); |
| 77 | +extern LIBACQUIRE_EXPORT int acquire_extract_sync(struct acquire_handle *handle, |
| 78 | + const char *archive_path, |
| 79 | + const char *dest_path); |
61 | 80 |
|
62 | | -#if defined(LIBACQUIRE_IMPLEMENTATION) && defined(LIBACQUIRE_EXTRACT_IMPL) |
63 | | -#include <acquire_string_extras.h> |
| 81 | +/* --- Deprecated Symbols --- */ |
64 | 82 |
|
65 | | -enum Archive extension2archive(const char *const extension) { |
66 | | - if (strncasecmp(extension, ".zip", 6) == 0) |
67 | | - return LIBACQUIRE_ZIP; |
68 | | - else if (strlen(extension) == 0) |
69 | | - return LIBACQUIRE_UNSUPPORTED_ARCHIVE; |
70 | | - else |
71 | | - return LIBACQUIRE_INFER; |
72 | | -} |
| 83 | +/** |
| 84 | + * @deprecated This enum is no longer used in the public API and will be |
| 85 | + * removed in a future version. Archive format is now auto-detected. |
| 86 | + */ |
| 87 | +enum Archive { |
| 88 | + LIBACQUIRE_ZIP, |
| 89 | + LIBACQUIRE_INFER, |
| 90 | + LIBACQUIRE_UNSUPPORTED_ARCHIVE |
| 91 | +}; |
| 92 | + |
| 93 | +/** |
| 94 | + * @deprecated This function is no longer needed for the public API and will be |
| 95 | + * removed in a future version. |
| 96 | + */ |
| 97 | +extern LIBACQUIRE_EXPORT enum Archive extension2archive(const char *extension); |
73 | 98 |
|
74 | | -#endif /* defined(LIBACQUIRE_IMPLEMENTATION) && \ |
75 | | - defined(LIBACQUIRE_EXTRACT_IMPL) */ |
| 99 | +/** |
| 100 | + * @deprecated This function is deprecated in favor of `acquire_extract_sync`. |
| 101 | + * It will be removed in a future version. |
| 102 | + */ |
| 103 | +extern LIBACQUIRE_EXPORT int extract_archive(enum Archive archive, |
| 104 | + const char *archive_filepath, |
| 105 | + const char *output_folder); |
76 | 106 |
|
77 | 107 | #ifdef __cplusplus |
78 | 108 | } |
79 | 109 | #endif /* __cplusplus */ |
80 | 110 |
|
81 | | -#endif /* ! LIBACQUIRE_ACQUIRE_EXTRACT_H */ |
| 111 | +#endif /* !LIBACQUIRE_ACQUIRE_EXTRACT_H */ |
0 commit comments