vfs_directory: try to fix compilation on gcc 14.1

This commit is contained in:
Megamouse 2024-05-11 08:51:12 +02:00
parent 7ac097255e
commit 5fb6be4bf6
1 changed files with 20 additions and 17 deletions

View File

@ -13,16 +13,17 @@
#endif #endif
#include <thread> #include <thread>
#include <map>
LOG_CHANNEL(vfs_log, "VFS"); LOG_CHANNEL(vfs_log, "VFS");
struct vfs_directory struct vfs_directory
{ {
// Real path (empty if root or not exists) // Real path (empty if root or not exists)
std::string path{}; std::string path;
// Virtual subdirectories (vector because only vector allows incomplete types) // Virtual subdirectories
std::vector<std::pair<std::string, vfs_directory>> dirs{}; std::map<std::string, std::unique_ptr<vfs_directory>> dirs;
}; };
struct vfs_manager struct vfs_manager
@ -107,13 +108,13 @@ bool vfs::mount(std::string_view vpath, std::string_view path, bool is_dir)
} }
// Find or add // Find or add
const auto last = list.back(); vfs_directory* last = list.back();
for (auto& dir : last->dirs) for (auto& [path, dir] : last->dirs)
{ {
if (dir.first == name) if (path == name)
{ {
list.push_back(&dir.second); list.push_back(dir.get());
break; break;
} }
} }
@ -121,7 +122,9 @@ bool vfs::mount(std::string_view vpath, std::string_view path, bool is_dir)
if (last == list.back()) if (last == list.back())
{ {
// Add new entry // Add new entry
list.push_back(&last->dirs.emplace_back(name, vfs_directory{}).second); std::unique_ptr<vfs_directory> new_entry = std::make_unique<vfs_directory>();
list.push_back(new_entry.get());
last->dirs.emplace(name, std::move(new_entry));
} }
} }
} }
@ -174,13 +177,13 @@ bool vfs::unmount(std::string_view vpath)
// Remove the matching node if we reached the maximum depth // Remove the matching node if we reached the maximum depth
if (depth + 1 == entry_list.size()) if (depth + 1 == entry_list.size())
{ {
vfs_log.notice("Unmounting '%s' = '%s'", it->first, it->second.path); vfs_log.notice("Unmounting '%s' = '%s'", it->first, it->second->path);
it = dir.dirs.erase(it); it = dir.dirs.erase(it);
continue; continue;
} }
// Otherwise continue searching in the next level of depth // Otherwise continue searching in the next level of depth
unmount_children(it->second, depth + 1); unmount_children(*it->second, depth + 1);
} }
++it; ++it;
@ -247,7 +250,7 @@ std::string vfs::get(std::string_view vpath, std::vector<std::string>* out_dir,
{ {
for (auto& pair : dir->dirs) for (auto& pair : dir->dirs)
{ {
if (!pair.second.path.empty()) if (!pair.second->path.empty())
{ {
out_dir->emplace_back(pair.first); out_dir->emplace_back(pair.first);
} }
@ -312,13 +315,13 @@ std::string vfs::get(std::string_view vpath, std::vector<std::string>* out_dir,
continue; continue;
} }
for (auto& dir : last->dirs) for (auto& [path, dir] : last->dirs)
{ {
if (dir.first == name) if (path == name)
{ {
list.back() = &dir.second; list.back() = dir.get();
if (dir.second.path == "/"sv) if (dir->path == "/"sv)
{ {
if (vpath.size() <= 1) if (vpath.size() <= 1)
{ {
@ -409,7 +412,7 @@ std::string vfs::retrieve(std::string_view path, const vfs_directory* node, std:
{ {
mount_path->back() = name; mount_path->back() = name;
if (std::string res = vfs::retrieve(path, &dir, mount_path); !res.empty()) if (std::string res = vfs::retrieve(path, dir.get(), mount_path); !res.empty())
{ {
// Avoid app_home // Avoid app_home
// Prefer dev_bdvd over dev_hdd0 // Prefer dev_bdvd over dev_hdd0
@ -421,7 +424,7 @@ std::string vfs::retrieve(std::string_view path, const vfs_directory* node, std:
} }
} }
if (dir.path == "/"sv) if (dir->path == "/"sv)
{ {
host_root_name = name; host_root_name = name;
} }