mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-14 06:48:39 -04:00
Cleanup metadata implementation
This commit is contained in:
parent
4442d2b75a
commit
a5937458da
@ -179,15 +179,25 @@ class metadata_ : public metadata_v2::impl {
|
|||||||
|
|
||||||
bool empty() const override { return data_.empty(); }
|
bool empty() const override { return data_.empty(); }
|
||||||
|
|
||||||
void walk(std::function<void(entry_view)> const& func) const override;
|
void walk(std::function<void(entry_view)> const& func) const override {
|
||||||
|
walk_impl(func);
|
||||||
|
}
|
||||||
|
|
||||||
void walk(std::function<void(entry_view, directory_view)> const& func)
|
void walk(std::function<void(entry_view, directory_view)> const& func)
|
||||||
const override;
|
const override {
|
||||||
|
walk_impl(func);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
walk_inode_order(std::function<void(entry_view)> const& func) const override;
|
walk_inode_order(std::function<void(entry_view)> const& func) const override {
|
||||||
|
walk_inode_order_impl(func);
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
walk_inode_order(std::function<void(entry_view, directory_view)> const& func)
|
walk_inode_order(std::function<void(entry_view, directory_view)> const& func)
|
||||||
const override;
|
const override {
|
||||||
|
walk_inode_order_impl(func);
|
||||||
|
}
|
||||||
|
|
||||||
std::optional<entry_view> find(const char* path) const override;
|
std::optional<entry_view> find(const char* path) const override;
|
||||||
std::optional<entry_view> find(int inode) const override;
|
std::optional<entry_view> find(int inode) const override;
|
||||||
@ -357,8 +367,19 @@ class metadata_ : public metadata_v2::impl {
|
|||||||
void walk(uint32_t parent_ix, uint32_t entry_ix, set_type<int>& seen,
|
void walk(uint32_t parent_ix, uint32_t entry_ix, set_type<int>& seen,
|
||||||
T&& func) const;
|
T&& func) const;
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void walk_tree(T&& func) const {
|
||||||
|
set_type<int> seen;
|
||||||
|
auto root = meta_.entry_index()[0];
|
||||||
|
walk(root, root, seen, std::forward<T>(func));
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Signature>
|
template <typename Signature>
|
||||||
void walk_impl(std::function<Signature> const& func) const;
|
void walk_impl(std::function<Signature> const& func) const {
|
||||||
|
walk_tree([&](uint32_t entry, uint32_t parent) {
|
||||||
|
walk_call(func, entry, parent);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
template <typename Signature>
|
template <typename Signature>
|
||||||
void walk_inode_order_impl(std::function<Signature> const& func) const;
|
void walk_inode_order_impl(std::function<Signature> const& func) const;
|
||||||
@ -605,74 +626,47 @@ template <typename T>
|
|||||||
void metadata_<LoggerPolicy>::walk(uint32_t parent_ix, uint32_t entry_ix,
|
void metadata_<LoggerPolicy>::walk(uint32_t parent_ix, uint32_t entry_ix,
|
||||||
set_type<int>& seen, T&& func) const {
|
set_type<int>& seen, T&& func) const {
|
||||||
func(entry_ix, parent_ix);
|
func(entry_ix, parent_ix);
|
||||||
|
|
||||||
auto entry = make_entry_view(entry_ix);
|
auto entry = make_entry_view(entry_ix);
|
||||||
|
|
||||||
if (S_ISDIR(entry.mode())) {
|
if (S_ISDIR(entry.mode())) {
|
||||||
auto inode = entry.inode();
|
auto inode = entry.inode();
|
||||||
|
|
||||||
if (!seen.emplace(inode).second) {
|
if (!seen.emplace(inode).second) {
|
||||||
DWARFS_THROW(runtime_error, "cycle detected during directory walk");
|
DWARFS_THROW(runtime_error, "cycle detected during directory walk");
|
||||||
}
|
}
|
||||||
|
|
||||||
auto dir = make_directory_view(entry);
|
auto dir = make_directory_view(entry);
|
||||||
|
|
||||||
for (auto cur : dir.entry_range()) {
|
for (auto cur : dir.entry_range()) {
|
||||||
walk(entry_ix, cur, seen, func);
|
walk(entry_ix, cur, seen, func);
|
||||||
}
|
}
|
||||||
|
|
||||||
seen.erase(inode);
|
seen.erase(inode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename LoggerPolicy>
|
|
||||||
template <typename Signature>
|
|
||||||
void metadata_<LoggerPolicy>::walk_impl(
|
|
||||||
std::function<Signature> const& func) const {
|
|
||||||
set_type<int> seen;
|
|
||||||
walk(
|
|
||||||
meta_.entry_index()[0], meta_.entry_index()[0], seen,
|
|
||||||
[&](uint32_t entry, uint32_t parent) { walk_call(func, entry, parent); });
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename LoggerPolicy>
|
|
||||||
void metadata_<LoggerPolicy>::walk(
|
|
||||||
std::function<void(entry_view)> const& func) const {
|
|
||||||
walk_impl(func);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename LoggerPolicy>
|
|
||||||
void metadata_<LoggerPolicy>::walk(
|
|
||||||
std::function<void(entry_view, directory_view)> const& func) const {
|
|
||||||
walk_impl(func);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename LoggerPolicy>
|
template <typename LoggerPolicy>
|
||||||
template <typename Signature>
|
template <typename Signature>
|
||||||
void metadata_<LoggerPolicy>::walk_inode_order_impl(
|
void metadata_<LoggerPolicy>::walk_inode_order_impl(
|
||||||
std::function<Signature> const& func) const {
|
std::function<Signature> const& func) const {
|
||||||
std::vector<std::pair<uint32_t, uint32_t>> entries;
|
std::vector<std::pair<uint32_t, uint32_t>> entries;
|
||||||
set_type<int> seen;
|
|
||||||
walk(meta_.entry_index()[0], meta_.entry_index()[0], seen,
|
walk_tree([&](uint32_t entry_ix, uint32_t parent_ix) {
|
||||||
[&](uint32_t entry_ix, uint32_t parent_ix) {
|
entries.emplace_back(entry_ix, parent_ix);
|
||||||
entries.emplace_back(entry_ix, parent_ix);
|
});
|
||||||
});
|
|
||||||
std::sort(entries.begin(), entries.end(),
|
std::sort(entries.begin(), entries.end(),
|
||||||
[this](auto const& a, auto const& b) {
|
[this](auto const& a, auto const& b) {
|
||||||
return meta_.entries()[a.first].inode() <
|
return meta_.entries()[a.first].inode() <
|
||||||
meta_.entries()[b.first].inode();
|
meta_.entries()[b.first].inode();
|
||||||
});
|
});
|
||||||
|
|
||||||
for (auto [entry, parent] : entries) {
|
for (auto [entry, parent] : entries) {
|
||||||
walk_call(func, entry, parent);
|
walk_call(func, entry, parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename LoggerPolicy>
|
|
||||||
void metadata_<LoggerPolicy>::walk_inode_order(
|
|
||||||
std::function<void(entry_view)> const& func) const {
|
|
||||||
walk_inode_order_impl(func);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename LoggerPolicy>
|
|
||||||
void metadata_<LoggerPolicy>::walk_inode_order(
|
|
||||||
std::function<void(entry_view, directory_view)> const& func) const {
|
|
||||||
walk_inode_order_impl(func);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename LoggerPolicy>
|
template <typename LoggerPolicy>
|
||||||
std::optional<entry_view>
|
std::optional<entry_view>
|
||||||
metadata_<LoggerPolicy>::find(directory_view dir, std::string_view name) const {
|
metadata_<LoggerPolicy>::find(directory_view dir, std::string_view name) const {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user