Skip to content

Commit c55fb16

Browse files
committed
Change unpacking to use unpack_input struct
1 parent e7224f1 commit c55fb16

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

include/libevp/evp.hpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@ namespace libevp {
1515
std::vector<DIR_PATH> files;
1616
};
1717

18+
struct unpack_input {
19+
FILE_PATH archive;
20+
std::vector<evp_fd> files;
21+
};
22+
1823
public:
1924
evp() = default;
2025
evp(const evp&) = delete;
@@ -52,8 +57,7 @@ namespace libevp {
5257
* status == evp_result_status::ok unpacked successfully;
5358
* status == evp_result_status::failure an error occurred during unpacking, message contains details;
5459
*/
55-
LIBEVP_API evp_result unpack(const FILE_PATH& evp, const DIR_PATH& output_dir,
56-
std::vector<evp_fd>* fds = nullptr);
60+
LIBEVP_API evp_result unpack(const unpack_input& input, const DIR_PATH& output);
5761

5862
/*
5963
* Asynchronously packs files in dir into a .evp archive.
@@ -77,8 +81,7 @@ namespace libevp {
7781
* @param fds -> (optional) fds of files to unpack
7882
* @param context -> pointer to context that has callbacks
7983
*/
80-
LIBEVP_API void unpack_async(const FILE_PATH& evp, const DIR_PATH& output_dir,
81-
std::vector<evp_fd>* fds = nullptr, evp_context* context = nullptr);
84+
LIBEVP_API void unpack_async(const unpack_input& input, const DIR_PATH& output, evp_context* context = nullptr);
8285

8386
/*
8487
* Validate files packed inside .evp archive.

source/libevp/evp.cpp

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ namespace libevp {
5151
static evp_result pack_impl(const evp::pack_input input, FILE_PATH evp,
5252
evp_context_internal& context);
5353

54-
static evp_result unpack_impl(FILE_PATH evp, DIR_PATH output,
55-
std::vector<evp_fd>* fds, evp_context_internal& context);
54+
static evp_result unpack_impl(evp::unpack_input input, DIR_PATH output,
55+
evp_context_internal& context);
5656
};
5757
}
5858

@@ -73,10 +73,10 @@ evp_result evp::pack(const pack_input& input, const FILE_PATH& evp) {
7373
}
7474
}
7575

76-
evp_result evp::unpack(const FILE_PATH& evp, const DIR_PATH& output_dir, std::vector<evp_fd>* fds) {
76+
evp_result evp::unpack(const unpack_input& input, const DIR_PATH& output) {
7777
try {
7878
evp_context_internal context_internal(nullptr);
79-
return evp_impl::unpack_impl(evp, output_dir, fds, context_internal);
79+
return evp_impl::unpack_impl(input, output, context_internal);
8080
}
8181
catch (const std::exception& e) {
8282
evp_result result;
@@ -105,12 +105,12 @@ void evp::pack_async(const pack_input& input, const FILE_PATH& evp, evp_context*
105105
t.detach();
106106
}
107107

108-
void evp::unpack_async(const FILE_PATH& evp, const DIR_PATH& output_dir, std::vector<evp_fd>* fds, evp_context* context) {
109-
std::thread t([evp, output_dir, fds, context] {
108+
void evp::unpack_async(const unpack_input& input, const DIR_PATH& output, evp_context* context) {
109+
std::thread t([input, output, context] {
110110
evp_context_internal context_internal(context);
111111

112112
try {
113-
evp_impl::unpack_impl(evp, output_dir, fds, context_internal);
113+
evp_impl::unpack_impl(input, output, context_internal);
114114
}
115115
catch (const std::exception& e) {
116116
evp_result result;
@@ -568,22 +568,22 @@ evp_result evp_impl::pack_impl(const evp::pack_input input, FILE_PATH evp,
568568
return result;
569569
}
570570

571-
evp_result evp_impl::unpack_impl(FILE_PATH evp, DIR_PATH output,
572-
std::vector<evp_fd>* fds, evp_context_internal& context)
571+
evp_result evp_impl::unpack_impl(evp::unpack_input input, DIR_PATH output,
572+
evp_context_internal& context)
573573
{
574574
evp_result result, res;
575575
result.status = evp_result::status::failure;
576576

577577
///////////////////////////////////////////////////////////////////////////
578578
// VERIFY
579579

580-
if (!evp.is_absolute())
581-
evp = std::filesystem::absolute(evp);
580+
if (!input.archive.is_absolute())
581+
input.archive = std::filesystem::absolute(input.archive);
582582

583583
if (!output.is_absolute())
584584
output = std::filesystem::absolute(output);
585585

586-
res = validate_evp_archive(evp, true);
586+
res = validate_evp_archive(input.archive, true);
587587
if (!res) {
588588
result.message = EVP_STR_FORMAT("Failed to validate input archive path. | {}", res.message);
589589

@@ -600,16 +600,14 @@ evp_result evp_impl::unpack_impl(FILE_PATH evp, DIR_PATH output,
600600
}
601601

602602
std::unordered_set<uint32_t> requested_fds = {};
603-
if (fds) {
604-
for (evp_fd& fd : *fds) {
605-
requested_fds.insert(fd.data_offset);
606-
}
603+
for (evp_fd& fd : input.files) {
604+
requested_fds.insert(fd.data_offset);
607605
}
608606

609607
///////////////////////////////////////////////////////////////////////////
610608
// UNPACK
611609

612-
fstream_read stream(evp);
610+
fstream_read stream(input.archive);
613611
if (!stream.is_valid()) {
614612
result.message = EVP_STR_FORMAT("Failed to open input archive for reading.");
615613

@@ -638,7 +636,7 @@ evp_result evp_impl::unpack_impl(FILE_PATH evp, DIR_PATH output,
638636
return result;
639637
}
640638

641-
if (fds && !requested_fds.contains(fd.data_offset)) {
639+
if (requested_fds.size() != 0 && !requested_fds.contains(fd.data_offset)) {
642640
context.invoke_update(prog_change);
643641
continue;
644642
}

0 commit comments

Comments
 (0)