Fix multiple modules adding the same subdirectory

This commit is contained in:
LoveSy 2022-03-19 12:18:34 +08:00 committed by John Wu
parent 2fb49ad780
commit dd5a3416bf

View File

@ -319,9 +319,9 @@ dir_node::iterator dir_node::insert(iterator it, uint8_t type, const Func &fn, b
else else
it = children.emplace_hint(--it, node->_name, node); it = children.emplace_hint(--it, node->_name, node);
} else { } else {
if (get_same && it->second->node_type == type) if (get_same && it->second->node_type != type)
return it; return children.end();
return children.end(); return it;
} }
} else { } else {
node = fn(node); node = fn(node);
@ -436,10 +436,14 @@ bool dir_node::collect_files(const char *module, int dfd) {
} }
if (entry->d_type == DT_DIR) { if (entry->d_type == DT_DIR) {
// Need check cause emplace could fail due to previous module dir replace dir_node *dn;
if (auto dn = emplace_or_get<inter_node>(entry->d_name, entry->d_name, module); if (auto it = children.find(entry->d_name); it == children.end()) {
dn && !dn->collect_files(module, dirfd(dir.get()))) { dn = emplace<inter_node>(entry->d_name, entry->d_name, module);
// Upgrade node to module due to '.replace' } else {
dn = iterator_to_node<dir_node>(upgrade<tmpfs_node>(it));
dn->set_exist(true);
}
if (dn && !dn->collect_files(module, dirfd(dir.get()))) {
upgrade<module_node>(dn->name(), module); upgrade<module_node>(dn->name(), module);
} }
} else { } else {
@ -484,8 +488,11 @@ void tmpfs_node::mount() {
return; return;
string src = mirror_path(); string src = mirror_path();
const string &dest = node_path(); const string &dest = node_path();
file_attr a; file_attr a{};
getattr(src.data(), &a); if (access(src.data(), F_OK) == 0)
getattr(src.data(), &a);
else
getattr(parent()->node_path().data(), &a);
mkdir(dest.data(), 0); mkdir(dest.data(), 0);
if (!isa<tmpfs_node>(parent())) { if (!isa<tmpfs_node>(parent())) {
// We don't need another layer of tmpfs if parent is skel // We don't need another layer of tmpfs if parent is skel