mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-23 09:51:57 -05:00
ln: Implement correct handling of directories as link targets
This commit is contained in:
parent
26d4a44a0f
commit
864221cb02
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…
Add table
Reference in a new issue