From 8eb1ac215b79c979965a845885efafab36f2e968 Mon Sep 17 00:00:00 2001 From: Gary Talent Date: Mon, 27 Jan 2025 00:10:25 -0600 Subject: [PATCH] [studio] Fix not to try moving a parent directory to its child --- src/olympic/studio/modlib/src/project.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/olympic/studio/modlib/src/project.cpp b/src/olympic/studio/modlib/src/project.cpp index 1aa311a0..609c1d12 100644 --- a/src/olympic/studio/modlib/src/project.cpp +++ b/src/olympic/studio/modlib/src/project.cpp @@ -46,6 +46,10 @@ static ox::Result> listAllRecursive(ox::FileSystem &fs, o return std::move(out); } +[[nodiscard]] +static constexpr bool isParentOf(ox::StringViewCR parent, ox::StringViewCR child) noexcept { + return beginsWith(child, parent); +} Project::Project(keel::Context &ctx, ox::String path, ox::StringViewCR projectDataDir): m_kctx(ctx), @@ -99,6 +103,9 @@ ox::Error Project::moveItem(ox::StringViewCR src, ox::StringViewCR dest) noexcep } ox::Error Project::moveDir(ox::StringViewCR src, ox::StringViewCR dest) noexcept { + if (isParentOf(src, dest)) { + return ox::Error{1, "cannot move parent to a child directory"}; + } OX_REQUIRE(files, listAllRecursive(m_fs, src)); OX_RETURN_ERROR(m_fs.move(src, dest)); fileMoved.emit(src, dest, ox::UUID{});