Use walk_inode_order in dwarfsextract

This commit is contained in:
Marcus Holland-Moritz 2021-03-05 02:09:19 +01:00
parent 00ccfee5d5
commit 85948323d9

View File

@ -144,22 +144,6 @@ int dwarfsextract(int argc, char** argv) {
: nullptr)); : nullptr));
} }
// TODO: This can surely be implemented more efficiently inside libdwarfs
// using entry indices / inode numbers, which should reduce the
// amount of memory needed by roughly a factor of 8.
std::vector<std::pair<entry_view, directory_view>> entries;
fs.walk([&](auto entry, auto parent) {
if (!S_ISDIR(entry.mode())) {
entries.emplace_back(entry, parent);
}
});
std::sort(entries.begin(), entries.end(), [](auto& a, auto& b) {
return a.first.inode() < b.first.inode();
});
auto lr = ::archive_entry_linkresolver_new(); auto lr = ::archive_entry_linkresolver_new();
::archive_entry_linkresolver_set_strategy(lr, ::archive_format(a)); ::archive_entry_linkresolver_set_strategy(lr, ::archive_format(a));
@ -178,7 +162,11 @@ int dwarfsextract(int argc, char** argv) {
} }
}; };
for (auto& [entry, parent] : entries) { fs.walk_inode_order([&](auto entry, auto parent) {
if (entry.inode() == 0) {
return;
}
auto ae = ::archive_entry_new(); auto ae = ::archive_entry_new();
struct ::stat stbuf; struct ::stat stbuf;
@ -221,7 +209,7 @@ int dwarfsextract(int argc, char** argv) {
do_archive(spare, *ev); do_archive(spare, *ev);
::archive_entry_free(spare); ::archive_entry_free(spare);
} }
} });
// As we're visiting *all* hardlinks, we should never see any deferred // As we're visiting *all* hardlinks, we should never see any deferred
// entries. // entries.