From 01dcb954e59c62228ab171f17f40f7c90dcecbcb Mon Sep 17 00:00:00 2001 From: apio Date: Wed, 1 May 2024 18:55:34 +0200 Subject: [PATCH] cp: Show an error message when attempting to copy a directory into a file --- apps/cp.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/apps/cp.cpp b/apps/cp.cpp index de858bac..d80ce302 100644 --- a/apps/cp.cpp +++ b/apps/cp.cpp @@ -81,6 +81,11 @@ Result copy_tree(StringView source, StringView destination, bool verbose, { path = TRY(String::from_string_view(destination)); 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));