diff options
| author | Lukas Oesch <lukas.oesch@ost.ch> | 2026-05-11 21:16:55 +0200 |
|---|---|---|
| committer | Lukas Oesch <lukas.oesch@ost.ch> | 2026-05-11 21:16:55 +0200 |
| commit | 5853b580c74411ecf196d241449411e0d01f0532 (patch) | |
| tree | 39efc6b7bc14da1c1c15a1b7993aadcc23848ca5 /kernel/src/filesystem/dentry.cpp | |
| parent | 0ffee4e5dbc20dd7f1f7991d1f8dab698fc9b7a0 (diff) | |
| parent | c958b72922b89fff35c0b8e0bbf21ad42a667022 (diff) | |
| download | kernel-5853b580c74411ecf196d241449411e0d01f0532.tar.xz kernel-5853b580c74411ecf196d241449411e0d01f0532.zip | |
Merge branch 'refactor-dentry-get-full-path' into 'develop-BA-FS26'
Refactor get_full_path remove recursion
See merge request teachos/kernel!31
Diffstat (limited to 'kernel/src/filesystem/dentry.cpp')
| -rw-r--r-- | kernel/src/filesystem/dentry.cpp | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/kernel/src/filesystem/dentry.cpp b/kernel/src/filesystem/dentry.cpp index 1cf8730..a77ce23 100644 --- a/kernel/src/filesystem/dentry.cpp +++ b/kernel/src/filesystem/dentry.cpp @@ -22,6 +22,10 @@ namespace kernel::filesystem { kapi::system::panic("[FILESYSTEM] dentry constructed with null inode."); } + if (m_name.empty()) + { + kapi::system::panic("[FILESYSTEM] dentry constructed with empty name."); + } } auto dentry::get_inode() const -> kstd::shared_ptr<inode> const & @@ -39,20 +43,27 @@ namespace kernel::filesystem return m_name.view(); } - // NOLINTNEXTLINE(misc-no-recursion) - auto dentry::get_full_path() const -> kstd::string + auto dentry::get_absolute_path() const -> kstd::string { - if (m_parent) + kstd::string path = m_name; + + auto parent = m_parent; + while (parent) { - auto parent_path = m_parent->get_full_path(); - if (parent_path != "/") + auto parent_name = parent->m_name; + if (parent_name == "/") { - parent_path += '/'; + path = "/" + path; } - return parent_path + m_name.view(); + else + { + path = parent_name + "/" + path; + } + + parent = parent->m_parent; } - return m_name.view(); + return path; } auto dentry::add_child(kstd::shared_ptr<dentry> const & child) -> void |
