mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
ln: Implement correct handling of directories as link targets
This commit is contained in:
parent
26d4a44a0f
commit
864221cb02
Notes:
sideshowbarker
2024-07-17 10:39:39 +09:00
Author: https://github.com/timschumi Commit: https://github.com/SerenityOS/serenity/commit/864221cb02 Pull-request: https://github.com/SerenityOS/serenity/pull/14688
1 changed files with 12 additions and 7 deletions
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue