mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 09:04:59 +00:00
LibFileSystem+Userland: Return ByteString from absolute_path()
This commit is contained in:
parent
fb644d08ac
commit
cdf17efb9a
7 changed files with 12 additions and 14 deletions
|
@ -28,18 +28,16 @@ ErrorOr<ByteString> current_working_directory()
|
|||
return Core::System::getcwd();
|
||||
}
|
||||
|
||||
ErrorOr<String> absolute_path(StringView path)
|
||||
ErrorOr<ByteString> absolute_path(StringView path)
|
||||
{
|
||||
if (exists(path))
|
||||
return TRY(real_path(path));
|
||||
return TRY(real_path(path)).to_byte_string();
|
||||
|
||||
if (path.starts_with("/"sv))
|
||||
return TRY(String::from_byte_string(LexicalPath::canonicalized_path(path)));
|
||||
return LexicalPath::canonicalized_path(path);
|
||||
|
||||
auto working_directory = TRY(current_working_directory());
|
||||
auto full_path = LexicalPath::join(working_directory, path).string();
|
||||
|
||||
return TRY(String::from_byte_string(LexicalPath::canonicalized_path(full_path)));
|
||||
return LexicalPath::absolute_path(working_directory, path);
|
||||
}
|
||||
|
||||
ErrorOr<String> real_path(StringView path)
|
||||
|
|
|
@ -19,7 +19,7 @@ namespace FileSystem {
|
|||
#define DEFAULT_PATH_SV "/usr/local/sbin:/usr/local/bin:/usr/bin:/bin"sv
|
||||
|
||||
ErrorOr<ByteString> current_working_directory();
|
||||
ErrorOr<String> absolute_path(StringView path);
|
||||
ErrorOr<ByteString> absolute_path(StringView path);
|
||||
ErrorOr<String> real_path(StringView path);
|
||||
|
||||
bool exists(StringView path);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue