diff --git a/include/dwarfs/global_entry_data.h b/include/dwarfs/global_entry_data.h index d8f53bb9..a694b8cb 100644 --- a/include/dwarfs/global_entry_data.h +++ b/include/dwarfs/global_entry_data.h @@ -28,17 +28,59 @@ namespace dwarfs { -// TODO: clean up class global_entry_data { public: global_entry_data(bool no_time) : no_time_(no_time) {} - void add_uid(uint16_t uid) { add(uid, uids, next_uid_index); } + void add_uid(uint16_t uid) { add(uid, uids_, next_uid_index_); } + void add_gid(uint16_t gid) { add(gid, gids_, next_gid_index_); } + void add_mode(uint16_t mode) { add(mode, modes_, next_mode_index_); } - void add_gid(uint16_t gid) { add(gid, gids, next_gid_index); } + void add_time(uint64_t time) { + if (time < timestamp_base_) { + timestamp_base_ = time; + } + } - void add_mode(uint16_t mode) { add(mode, modes, next_mode_index); } + void add_name(std::string const& name) { names_.emplace(name, 0); } + void add_link(std::string const& link) { links_.emplace(link, 0); } + + void index() { + index(names_); + index(links_); + } + + uint16_t get_uid_index(uint16_t uid) const { return uids_.at(uid); } + uint16_t get_gid_index(uint16_t gid) const { return gids_.at(gid); } + uint16_t get_mode_index(uint16_t mode) const { return modes_.at(mode); } + + uint32_t get_name_index(std::string const& name) const { + return names_.at(name); + } + + uint32_t get_link_index(std::string const& link) const { + return links_.at(link); + } + + uint64_t get_time_offset(uint64_t time) const { + return no_time_ ? 0 : time - timestamp_base_; + } + + std::vector get_uids() const; + std::vector get_gids() const; + std::vector get_modes() const; + + std::vector get_names() const; + std::vector get_links() const; + + uint64_t get_timestamp_base() const { return timestamp_base_; } + + private: + template + std::vector get_vector(std::unordered_map const& map) const; + + static void index(std::unordered_map& map); void add(uint16_t val, std::unordered_map& map, uint16_t& next_index) { @@ -47,64 +89,15 @@ class global_entry_data { } } - void add_time(uint64_t time) { - if (time < timestamp_base) { - timestamp_base = time; - } - } - - void add_name(std::string const& name) { names.emplace(name, 0); } - - void add_link(std::string const& link) { links.emplace(link, 0); } - - void index() { - index(names); - index(links); - } - - void index(std::unordered_map& map); - - uint16_t get_uid_index(uint16_t uid) const { return uids.at(uid); } - - uint16_t get_gid_index(uint16_t gid) const { return gids.at(gid); } - - uint16_t get_mode_index(uint16_t mode) const { return modes.at(mode); } - - uint32_t get_name_index(std::string const& name) const { - return names.at(name); - } - - uint32_t get_link_index(std::string const& link) const { - return links.at(link); - } - - uint64_t get_time_offset(uint64_t time) const { - return no_time_ ? 0 : time - timestamp_base; - } - - std::vector get_uids() const; - - std::vector get_gids() const; - - std::vector get_modes() const; - - std::vector get_names() const; - - std::vector get_links() const; - - // TODO: make private - template - std::vector get_vector(std::unordered_map const& map) const; - - std::unordered_map uids; - std::unordered_map gids; - std::unordered_map modes; - std::unordered_map names; - std::unordered_map links; - uint16_t next_uid_index{0}; - uint16_t next_gid_index{0}; - uint16_t next_mode_index{0}; - uint64_t timestamp_base{std::numeric_limits::max()}; + std::unordered_map uids_; + std::unordered_map gids_; + std::unordered_map modes_; + std::unordered_map names_; + std::unordered_map links_; + uint16_t next_uid_index_{0}; + uint16_t next_gid_index_{0}; + uint16_t next_mode_index_{0}; + uint64_t timestamp_base_{std::numeric_limits::max()}; bool no_time_; }; diff --git a/src/dwarfs/global_entry_data.cpp b/src/dwarfs/global_entry_data.cpp index 3bfc283f..af0a2a57 100644 --- a/src/dwarfs/global_entry_data.cpp +++ b/src/dwarfs/global_entry_data.cpp @@ -35,23 +35,23 @@ global_entry_data::get_vector(std::unordered_map const& map) const { } std::vector global_entry_data::get_uids() const { - return get_vector(uids); + return get_vector(uids_); } std::vector global_entry_data::get_gids() const { - return get_vector(gids); + return get_vector(gids_); } std::vector global_entry_data::get_modes() const { - return get_vector(modes); + return get_vector(modes_); } std::vector global_entry_data::get_names() const { - return get_vector(names); + return get_vector(names_); } std::vector global_entry_data::get_links() const { - return get_vector(links); + return get_vector(links_); } void global_entry_data::index(std::unordered_map& map) { diff --git a/src/dwarfs/scanner.cpp b/src/dwarfs/scanner.cpp index c21a661d..e9f25244 100644 --- a/src/dwarfs/scanner.cpp +++ b/src/dwarfs/scanner.cpp @@ -467,7 +467,7 @@ void scanner_::scan(filesystem_writer& fsw, mv2.modes = ge_data.get_modes(); mv2.names = ge_data.get_names(); mv2.links = ge_data.get_links(); - mv2.timestamp_base = ge_data.timestamp_base; + mv2.timestamp_base = ge_data.get_timestamp_base(); mv2.chunk_index_offset = first_file_inode; mv2.block_size = UINT32_C(1) << cfg_.block_size_bits; mv2.total_fs_size = prog.original_size;