Skip to content

Commit

Permalink
Fix plugins not loading, due to 0byte files being skipped
Browse files Browse the repository at this point in the history
  • Loading branch information
danngreen committed Nov 21, 2024
1 parent 081382b commit 31bf7e4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
11 changes: 5 additions & 6 deletions firmware/src/fs/asset_drive/untar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,11 @@ bool Archive::extract_files(std::function<uint32_t(std::string_view, std::span<c
auto name = entry.name;

if (entry.type == TarEntry::File) {
auto filedata = extract_file_entry(entry);
if (filedata.size()) {
pr_dump("Extracted %zu bytes for %s\n", filedata.size(), name.c_str());
write(name, filedata);
if (auto filedata = extract_file_entry(entry)) {
pr_dump("Extracted %zu bytes for %s\n", filedata->size(), name.c_str());
write(name, *filedata);
} else {
pr_dump("Skipped invalid file with size %zu\n", entry.size);
pr_warn("Skipped invalid file with size %zu\n", entry.size);
}
} else {
pr_trace("Skipping non-file entry %s\n", name.c_str());
Expand All @@ -141,7 +140,7 @@ bool Archive::extract_files(std::function<uint32_t(std::string_view, std::span<c
return true;
}

std::vector<char> Archive::extract_file_entry(TarEntry const &entry) {
std::optional<std::vector<char>> Archive::extract_file_entry(TarEntry const &entry) {
image_seek_absolute(512 + entry.file_offset);

if (entry.size < MaxEntrySizeBytes) {
Expand Down
3 changes: 2 additions & 1 deletion firmware/src/fs/asset_drive/untar.hh
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <cstdint>
#include <functional>
#include <list>
#include <optional>
#include <span>
#include <string>
#include <string_view>
Expand Down Expand Up @@ -39,7 +40,7 @@ public:
private:
bool image_read(char *buf, int size);
bool image_read(TarRaw *buf, int size);
std::vector<char> extract_file_entry(TarEntry const &entry);
std::optional<std::vector<char>> extract_file_entry(TarEntry const &entry);
void image_seek_relative(int advance);
void image_seek_absolute(unsigned new_pos);
};
Expand Down

0 comments on commit 31bf7e4

Please sign in to comment.