1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 00:57:45 +00:00

LibCore: Prevent infinite recursion in Directory::ensure_directory()

If a relative path was passed in, then repeatedly asking for its parent
will never reach `/`. The top-level path in that case is `.`.
This commit is contained in:
Sam Atkins 2022-04-13 11:52:16 +01:00 committed by Andreas Kling
parent 3426592ee7
commit 6967d37678

View file

@ -61,7 +61,7 @@ ErrorOr<Directory> Directory::create(LexicalPath path, CreateDirectories create_
ErrorOr<void> Directory::ensure_directory(LexicalPath const& path) ErrorOr<void> Directory::ensure_directory(LexicalPath const& path)
{ {
if (path.basename() == "/") if (path.basename() == "/" || path.basename() == ".")
return {}; return {};
TRY(ensure_directory(path.parent())); TRY(ensure_directory(path.parent()));