[studio] Fix not to try moving a parent directory to its child
All checks were successful
Build / build (push) Successful in 3m34s
All checks were successful
Build / build (push) Successful in 3m34s
This commit is contained in:
parent
e132f2fd1b
commit
8eb1ac215b
@ -46,6 +46,10 @@ static ox::Result<ox::Vector<ox::String>> listAllRecursive(ox::FileSystem &fs, o
|
|||||||
return std::move(out);
|
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):
|
Project::Project(keel::Context &ctx, ox::String path, ox::StringViewCR projectDataDir):
|
||||||
m_kctx(ctx),
|
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 {
|
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_REQUIRE(files, listAllRecursive(m_fs, src));
|
||||||
OX_RETURN_ERROR(m_fs.move(src, dest));
|
OX_RETURN_ERROR(m_fs.move(src, dest));
|
||||||
fileMoved.emit(src, dest, ox::UUID{});
|
fileMoved.emit(src, dest, ox::UUID{});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user