mirror of
https://github.com/mhx/dwarfs.git
synced 2025-09-08 11:59:48 -04:00
Be more explicit about naming symlinks
This commit is contained in:
parent
579dc1a556
commit
514b644358
@ -49,11 +49,11 @@ class global_entry_data {
|
||||
void add_ctime(uint64_t time);
|
||||
|
||||
void add_name(std::string const& name) { names_.emplace(name, 0); }
|
||||
void add_link(std::string const& link) { links_.emplace(link, 0); }
|
||||
void add_link(std::string const& link) { symlinks_.emplace(link, 0); }
|
||||
|
||||
void index() {
|
||||
index(names_);
|
||||
index(links_);
|
||||
index(symlinks_);
|
||||
}
|
||||
|
||||
uint16_t get_uid_index(uint16_t uid) const;
|
||||
@ -61,7 +61,7 @@ class global_entry_data {
|
||||
uint16_t get_mode_index(uint16_t mode) const;
|
||||
|
||||
uint32_t get_name_index(std::string const& name) const;
|
||||
uint32_t get_link_index(std::string const& link) const;
|
||||
uint32_t get_symlink_index(std::string const& link) const;
|
||||
|
||||
uint64_t get_mtime_offset(uint64_t time) const;
|
||||
uint64_t get_atime_offset(uint64_t time) const;
|
||||
@ -72,7 +72,7 @@ class global_entry_data {
|
||||
std::vector<uint16_t> get_modes() const;
|
||||
|
||||
std::vector<std::string> get_names() const;
|
||||
std::vector<std::string> get_links() const;
|
||||
std::vector<std::string> get_symlinks() const;
|
||||
|
||||
uint64_t get_timestamp_base() const;
|
||||
|
||||
@ -98,7 +98,7 @@ class global_entry_data {
|
||||
map_type<uint16_t, uint16_t> gids_;
|
||||
map_type<uint16_t, uint16_t> modes_;
|
||||
map_type<std::string, uint32_t> names_;
|
||||
map_type<std::string, uint32_t> links_;
|
||||
map_type<std::string, uint32_t> symlinks_;
|
||||
uint16_t next_uid_index_{0};
|
||||
uint16_t next_gid_index_{0};
|
||||
uint16_t next_mode_index_{0};
|
||||
|
@ -59,8 +59,8 @@ class progress {
|
||||
std::atomic<size_t> files_scanned{0};
|
||||
std::atomic<size_t> dirs_found{0};
|
||||
std::atomic<size_t> dirs_scanned{0};
|
||||
std::atomic<size_t> links_found{0};
|
||||
std::atomic<size_t> links_scanned{0};
|
||||
std::atomic<size_t> symlinks_found{0};
|
||||
std::atomic<size_t> symlinks_scanned{0};
|
||||
std::atomic<size_t> specials_found{0};
|
||||
std::atomic<size_t> duplicate_files{0};
|
||||
std::atomic<size_t> hardlinks{0};
|
||||
|
@ -172,7 +172,7 @@ void console_writer::update(const progress& p, bool last) {
|
||||
<< newline;
|
||||
}
|
||||
|
||||
oss << p.dirs_scanned << " dirs, " << p.links_scanned << "/"
|
||||
oss << p.dirs_scanned << " dirs, " << p.symlinks_scanned << "/"
|
||||
<< p.hardlinks << " soft/hard links, " << p.files_scanned << "/"
|
||||
<< p.files_found << " files, " << p.specials_found << " other"
|
||||
<< newline
|
||||
|
@ -51,8 +51,8 @@ std::vector<std::string> global_entry_data::get_names() const {
|
||||
return get_vector(names_);
|
||||
}
|
||||
|
||||
std::vector<std::string> global_entry_data::get_links() const {
|
||||
return get_vector(links_);
|
||||
std::vector<std::string> global_entry_data::get_symlinks() const {
|
||||
return get_vector(symlinks_);
|
||||
}
|
||||
|
||||
void global_entry_data::index(map_type<std::string, uint32_t>& map) {
|
||||
@ -100,8 +100,8 @@ uint32_t global_entry_data::get_name_index(std::string const& name) const {
|
||||
return DWARFS_NOTHROW(names_.at(name));
|
||||
}
|
||||
|
||||
uint32_t global_entry_data::get_link_index(std::string const& link) const {
|
||||
return DWARFS_NOTHROW(links_.at(link));
|
||||
uint32_t global_entry_data::get_symlink_index(std::string const& link) const {
|
||||
return DWARFS_NOTHROW(symlinks_.at(link));
|
||||
}
|
||||
|
||||
void global_entry_data::add_uid(uint16_t uid) {
|
||||
|
@ -115,32 +115,32 @@ class metadata_ final : public metadata_v2::impl {
|
||||
, root_(meta_.entries()[meta_.entry_index()[0]], &meta_)
|
||||
, log_(lgr)
|
||||
, inode_offset_(inode_offset)
|
||||
, link_index_offset_(find_index_offset(inode_rank::INO_LNK))
|
||||
, symlink_index_offset_(find_index_offset(inode_rank::INO_LNK))
|
||||
, chunk_index_offset_(find_index_offset(inode_rank::INO_REG))
|
||||
, dev_index_offset_(find_index_offset(inode_rank::INO_DEV))
|
||||
, nlinks_(build_nlinks(options))
|
||||
, options_(options) {
|
||||
LOG_DEBUG << "link index offset: " << link_index_offset_;
|
||||
LOG_DEBUG << "symlink index offset: " << symlink_index_offset_;
|
||||
LOG_DEBUG << "chunk index offset: " << chunk_index_offset_;
|
||||
LOG_DEBUG << "device index offset: " << dev_index_offset_;
|
||||
|
||||
if (int(meta_.directories().size() - 1) != link_index_offset_) {
|
||||
if (int(meta_.directories().size() - 1) != symlink_index_offset_) {
|
||||
DWARFS_THROW(
|
||||
runtime_error,
|
||||
fmt::format("metadata inconsistency: number of directories ({}) does "
|
||||
"not match link index ({})",
|
||||
meta_.directories().size() - 1, link_index_offset_));
|
||||
meta_.directories().size() - 1, symlink_index_offset_));
|
||||
}
|
||||
|
||||
if (int(meta_.link_index().size()) !=
|
||||
(chunk_index_offset_ - link_index_offset_)) {
|
||||
if (int(meta_.symlink_index().size()) !=
|
||||
(chunk_index_offset_ - symlink_index_offset_)) {
|
||||
DWARFS_THROW(
|
||||
runtime_error,
|
||||
fmt::format(
|
||||
"metadata inconsistency: number of links ({}) does not match "
|
||||
"chunk/link index delta ({} - {} = {})",
|
||||
meta_.link_index().size(), chunk_index_offset_,
|
||||
link_index_offset_, chunk_index_offset_ - link_index_offset_));
|
||||
"metadata inconsistency: number of symlinks ({}) does not match "
|
||||
"chunk/symlink index delta ({} - {} = {})",
|
||||
meta_.symlink_index().size(), chunk_index_offset_,
|
||||
symlink_index_offset_, chunk_index_offset_ - symlink_index_offset_));
|
||||
}
|
||||
|
||||
if (int(meta_.chunk_index().size() - 1) !=
|
||||
@ -395,7 +395,7 @@ class metadata_ final : public metadata_v2::impl {
|
||||
|
||||
std::string_view link_value(entry_view entry) const {
|
||||
return meta_
|
||||
.links()[meta_.link_index()[entry.inode() - link_index_offset_]];
|
||||
.symlinks()[meta_.symlink_index()[entry.inode() - symlink_index_offset_]];
|
||||
}
|
||||
|
||||
uint64_t get_device_id(int inode) const {
|
||||
@ -433,7 +433,7 @@ class metadata_ final : public metadata_v2::impl {
|
||||
entry_view root_;
|
||||
log_proxy<LoggerPolicy> log_;
|
||||
const int inode_offset_;
|
||||
const int link_index_offset_;
|
||||
const int symlink_index_offset_;
|
||||
const int chunk_index_offset_;
|
||||
const int dev_index_offset_;
|
||||
const std::vector<uint32_t> nlinks_;
|
||||
|
@ -209,9 +209,9 @@ class pipe_set_inode_visitor : public visitor_base {
|
||||
uint32_t& inode_no_;
|
||||
};
|
||||
|
||||
class names_and_links_visitor : public entry_visitor {
|
||||
class names_and_symlinks_visitor : public entry_visitor {
|
||||
public:
|
||||
explicit names_and_links_visitor(global_entry_data& data)
|
||||
explicit names_and_symlinks_visitor(global_entry_data& data)
|
||||
: data_(data) {}
|
||||
|
||||
void visit(file* p) override { data_.add_name(p->name()); }
|
||||
@ -417,9 +417,9 @@ scanner_<LoggerPolicy>::scan_tree(const std::string& path, progress& prog) {
|
||||
break;
|
||||
|
||||
case entry::E_LINK:
|
||||
prog.links_found++;
|
||||
prog.symlinks_found++;
|
||||
pe->scan(*os_, prog);
|
||||
prog.links_scanned++;
|
||||
prog.symlinks_scanned++;
|
||||
break;
|
||||
|
||||
case entry::E_DEVICE:
|
||||
@ -506,7 +506,7 @@ void scanner_<LoggerPolicy>::scan(filesystem_writer& fsw,
|
||||
global_entry_data ge_data(options_);
|
||||
thrift::metadata::metadata mv2;
|
||||
|
||||
mv2.link_index.resize(first_file_inode - first_link_inode);
|
||||
mv2.symlink_index.resize(first_file_inode - first_link_inode);
|
||||
|
||||
LOG_INFO << "assigning device inodes...";
|
||||
uint32_t first_device_inode = first_file_inode + im.count();
|
||||
@ -522,8 +522,8 @@ void scanner_<LoggerPolicy>::scan(filesystem_writer& fsw,
|
||||
LOG_INFO << "building metadata...";
|
||||
|
||||
wg_.add_job([&] {
|
||||
LOG_INFO << "saving names and links...";
|
||||
names_and_links_visitor nlv(ge_data);
|
||||
LOG_INFO << "saving names and symlinks...";
|
||||
names_and_symlinks_visitor nlv(ge_data);
|
||||
root->accept(nlv);
|
||||
|
||||
ge_data.index();
|
||||
@ -532,8 +532,8 @@ void scanner_<LoggerPolicy>::scan(filesystem_writer& fsw,
|
||||
root->walk([&](entry* ep) {
|
||||
ep->update(ge_data);
|
||||
if (auto lp = dynamic_cast<link*>(ep)) {
|
||||
DWARFS_NOTHROW(mv2.link_index.at(ep->inode_num() - first_link_inode)) =
|
||||
ge_data.get_link_index(lp->linkname());
|
||||
DWARFS_NOTHROW(mv2.symlink_index.at(ep->inode_num() - first_link_inode)) =
|
||||
ge_data.get_symlink_index(lp->linkname());
|
||||
}
|
||||
});
|
||||
});
|
||||
@ -607,7 +607,7 @@ void scanner_<LoggerPolicy>::scan(filesystem_writer& fsw,
|
||||
mv2.gids = ge_data.get_gids();
|
||||
mv2.modes = ge_data.get_modes();
|
||||
mv2.names = ge_data.get_names();
|
||||
mv2.links = ge_data.get_links();
|
||||
mv2.symlinks = ge_data.get_symlinks();
|
||||
mv2.timestamp_base = ge_data.get_timestamp_base();
|
||||
mv2.block_size = UINT32_C(1) << cfg_.block_size_bits;
|
||||
mv2.total_fs_size = prog.original_size;
|
||||
|
@ -141,7 +141,7 @@ struct metadata {
|
||||
5: required list<UInt32> entry_index,
|
||||
|
||||
// link index, indexed by (inode - link_index_offset)
|
||||
6: required list<UInt32> link_index,
|
||||
6: required list<UInt32> symlink_index,
|
||||
|
||||
// user ids, for lookup by index in entry.owner
|
||||
7: required list<UInt16> uids,
|
||||
@ -155,8 +155,8 @@ struct metadata {
|
||||
// entry names, for lookup by index in entry.name_index
|
||||
10: required list<string> names,
|
||||
|
||||
// link targets, for lookup by index from link_index
|
||||
11: required list<string> links,
|
||||
// link targets, for lookup by index from symlink_index
|
||||
11: required list<string> symlinks,
|
||||
|
||||
// timestamp base for all entry timestamps
|
||||
12: required UInt64 timestamp_base,
|
||||
|
Loading…
x
Reference in New Issue
Block a user