diff --git a/Userland/Utilities/ln.cpp b/Userland/Utilities/ln.cpp index dc935c99a93..fd48da50e8d 100644 --- a/Userland/Utilities/ln.cpp +++ b/Userland/Utilities/ln.cpp @@ -30,15 +30,20 @@ ErrorOr serenity_main(Main::Arguments arguments) path = path_buffer.view(); } - if (force) { - auto stat = Core::System::lstat(path); + auto stat = Core::System::lstat(path); - if (stat.is_error() && stat.error().code() != ENOENT) - return stat.error(); + if (stat.is_error() && stat.error().code() != ENOENT) + return stat.error(); - if (!stat.is_error()) { - TRY(Core::System::unlink(path)); - } + if (!stat.is_error() && S_ISDIR(stat.value().st_mode)) { + // The target path is a directory, so we presumably want / as the effective path. + path_buffer = LexicalPath::join(path, LexicalPath::basename(target)).string(); + path = path_buffer.view(); + stat = Core::System::lstat(path); + } + + if (force && !stat.is_error()) { + TRY(Core::System::unlink(path)); } if (symbolic) {