ln: Implement correct handling of directories as link targets

This commit is contained in:
Tim Schumacher 2022-07-25 16:33:07 +02:00 committed by Linus Groh
parent 26d4a44a0f
commit 864221cb02
Notes: sideshowbarker 2024-07-17 10:39:39 +09:00

View file

@ -30,15 +30,20 @@ ErrorOr<int> 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 <path>/<filename> 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) {