Skip to content

Commit

Permalink
LibFileSystem+Userland: Rename size() to size_from_stat()
Browse files Browse the repository at this point in the history
This reflects what the functions does more accurately, and allows for
adding functions to get sizes through other methods.

This also corrects the return type of said function, as size_t may only
hold sizes up to 4GB on 32-bit platforms.
  • Loading branch information
implicitfield authored and ADKaster committed Feb 24, 2024
1 parent d3c6e31 commit 896f213
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Userland/Applications/SoundPlayer/Playlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void Playlist::try_fill_missing_info(Vector<M3UEntry>& entries, StringView path)
entry.path = ByteString::formatted("{}/{}", playlist_path.dirname(), entry.path);

if (!entry.extended_info->file_size_in_bytes.has_value()) {
auto size = FileSystem::size(entry.path);
auto size = FileSystem::size_from_stat(entry.path);
if (size.is_error())
continue;
entry.extended_info->file_size_in_bytes = size.value();
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibFileSystem/FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ ErrorOr<void> remove(StringView path, RecursionMode mode)
return {};
}

ErrorOr<size_t> size(StringView path)
ErrorOr<off_t> size_from_stat(StringView path)
{
auto st = TRY(Core::System::stat(path));
return st.st_size;
Expand Down
2 changes: 1 addition & 1 deletion Userland/Libraries/LibFileSystem/FileSystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ ErrorOr<void> copy_directory(StringView destination_path, StringView source_path
ErrorOr<void> copy_file_or_directory(StringView destination_path, StringView source_path, RecursionMode = RecursionMode::Allowed, LinkMode = LinkMode::Disallowed, AddDuplicateFileMarker = AddDuplicateFileMarker::Yes, PreserveMode = PreserveMode::Nothing);
ErrorOr<void> move_file(StringView destination_path, StringView source_path, PreserveMode = PreserveMode::Nothing);
ErrorOr<void> remove(StringView path, RecursionMode);
ErrorOr<size_t> size(StringView path);
ErrorOr<off_t> size_from_stat(StringView path);
bool can_delete_or_move(StringView path);

ErrorOr<ByteString> read_link(StringView link_path);
Expand Down
2 changes: 1 addition & 1 deletion Userland/Services/WebServer/Client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ ErrorOr<bool> Client::handle_request(HTTP::HttpRequest const& request)

auto const info = ContentInfo {
.type = TRY(String::from_utf8(Core::guess_mime_type_based_on_filename(real_path.bytes_as_string_view()))),
.length = TRY(FileSystem::size(real_path.bytes_as_string_view()))
.length = static_cast<u64>(TRY(FileSystem::size_from_stat(real_path.bytes_as_string_view())))
};
TRY(send_response(*stream, request, move(info)));
return true;
Expand Down
2 changes: 1 addition & 1 deletion Userland/Services/WebServer/Client.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Client final : public Core::EventReceiver {

struct ContentInfo {
String type;
size_t length {};
u64 length {};
};

ErrorOr<void, WrappedError> on_ready_to_read();
Expand Down

0 comments on commit 896f213

Please sign in to comment.