cp: Show an error message when attempting to copy a directory into a file
All checks were successful
Build and test / build (push) Successful in 2m12s

This commit is contained in:
apio 2024-05-01 18:55:34 +02:00
parent 04649fce8a
commit 01dcb954e5
Signed by: apio
GPG Key ID: B8A7D06E42258954

View File

@ -81,6 +81,11 @@ Result<void> copy_tree(StringView source, StringView destination, bool verbose,
{ {
path = TRY(String::from_string_view(destination)); path = TRY(String::from_string_view(destination));
if (!os::FileSystem::exists(path.view(), false)) TRY(os::FileSystem::create_directory(path.view(), 0755)); if (!os::FileSystem::exists(path.view(), false)) TRY(os::FileSystem::create_directory(path.view(), 0755));
else
{
os::eprintln("cp: cannot overwrite non-directory '%s' with directory '%s'", path.chars(), source.chars());
return {};
}
} }
auto dir = TRY(os::Directory::open(source)); auto dir = TRY(os::Directory::open(source));