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