metadata_v2: cleanup directory_view

This commit is contained in:
Marcus Holland-Moritz 2020-11-28 23:19:16 +01:00
parent 87d547aaae
commit 6896b53c28
3 changed files with 37 additions and 23 deletions

View File

@ -33,38 +33,43 @@
namespace dwarfs {
template <typename T>
class metadata_;
class entry_view
: public ::apache::thrift::frozen::View<thrift::metadata::entry> {
using EntryView = ::apache::thrift::frozen::View<thrift::metadata::entry>;
using Meta =
::apache::thrift::frozen::MappedFrozen<thrift::metadata::metadata>;
public:
entry_view(EntryView ev, Meta const* meta)
: EntryView(ev)
, meta_(meta) {}
template <typename T>
friend class metadata_;
public:
std::string_view name() const;
uint16_t mode() const;
uint16_t getuid() const;
uint16_t getgid() const;
private:
entry_view(EntryView ev, Meta const* meta)
: EntryView(ev)
, meta_(meta) {}
Meta const* meta_;
};
class directory_view
: public ::apache::thrift::frozen::View<thrift::metadata::entry> {
class directory_view {
using EntryView = ::apache::thrift::frozen::View<thrift::metadata::entry>;
using DirView = ::apache::thrift::frozen::View<thrift::metadata::directory>;
using Meta =
::apache::thrift::frozen::MappedFrozen<thrift::metadata::metadata>;
public:
directory_view(EntryView ev, Meta const* meta)
: EntryView(ev)
, meta_(meta) {}
template <typename T>
friend class metadata_;
public:
uint32_t inode() const { return entry_.inode(); }
uint32_t parent_inode() const;
uint32_t first_entry() const;
uint32_t entry_count() const;
@ -72,10 +77,15 @@ class directory_view
boost::integer_range<uint32_t> entry_range() const;
private:
directory_view(EntryView ev, Meta const* meta)
: entry_(ev)
, meta_(meta) {}
DirView getdir() const;
DirView getdir(uint32_t ino) const;
uint32_t entry_count(DirView self) const;
EntryView entry_;
Meta const* meta_;
};
@ -85,6 +95,9 @@ class chunk_range {
using Meta =
::apache::thrift::frozen::MappedFrozen<thrift::metadata::metadata>;
template <typename T>
friend class metadata_;
public:
class iterator
: public boost::iterator_facade<iterator, chunk_view const,
@ -92,16 +105,17 @@ class chunk_range {
public:
iterator() = default;
iterator(Meta const* meta, uint32_t it)
: meta_(meta)
, it_(it) {}
iterator(iterator const& other)
: meta_(other.meta_)
, it_(other.it_) {}
private:
friend class boost::iterator_core_access;
friend class chunk_range;
iterator(Meta const* meta, uint32_t it)
: meta_(meta)
, it_(it) {}
bool equal(iterator const& other) const {
return meta_ == other.meta_ && it_ == other.it_;
@ -128,11 +142,6 @@ class chunk_range {
mutable chunk_view view_;
};
chunk_range(Meta const* meta, uint32_t begin, uint32_t end)
: meta_(meta)
, begin_(begin)
, end_(end) {}
iterator begin() const { return iterator(meta_, begin_); }
iterator end() const { return iterator(meta_, end_); }
@ -142,6 +151,11 @@ class chunk_range {
bool empty() const { return end_ == begin_; }
private:
chunk_range(Meta const* meta, uint32_t begin, uint32_t end)
: meta_(meta)
, begin_(begin)
, end_(end) {}
Meta const* meta_;
uint32_t begin_{0};
uint32_t end_{0};

View File

@ -40,7 +40,7 @@ uint16_t entry_view::getgid() const { return meta_->gids()[group_index()]; }
::apache::thrift::frozen::View<thrift::metadata::directory>
directory_view::getdir() const {
return getdir(inode());
return getdir(entry_.inode());
}
::apache::thrift::frozen::View<thrift::metadata::directory>
@ -52,7 +52,7 @@ uint32_t directory_view::entry_count() const { return entry_count(getdir()); }
uint32_t directory_view::entry_count(
::apache::thrift::frozen::View<thrift::metadata::directory> self) const {
auto next = getdir(inode() + 1);
auto next = getdir(entry_.inode() + 1);
return next.first_entry() - self.first_entry();
}

View File

@ -84,6 +84,8 @@ void analyze_frozen(std::ostream& os,
const uint16_t READ_ONLY_MASK = ~(S_IWUSR | S_IWGRP | S_IWOTH);
} // namespace
template <typename LoggerPolicy>
class metadata_ : public metadata_v2::impl {
public:
@ -536,8 +538,6 @@ metadata_<LoggerPolicy>::get_chunks(int inode) const {
return rv;
}
} // namespace
void metadata_v2::get_stat_defaults(struct ::stat* defaults) {
::memset(defaults, 0, sizeof(struct ::stat));
defaults->st_uid = ::geteuid();