Ver código fonte

LibFileSystem+Userland: Rename size() to size_from_stat()

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.
implicitfield 1 ano atrás
pai
commit
896f213c6f

+ 1 - 1
Userland/Applications/SoundPlayer/Playlist.cpp

@@ -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();

+ 1 - 1
Userland/Libraries/LibFileSystem/FileSystem.cpp

@@ -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;

+ 1 - 1
Userland/Libraries/LibFileSystem/FileSystem.h

@@ -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);

+ 1 - 1
Userland/Services/WebServer/Client.cpp

@@ -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;

+ 1 - 1
Userland/Services/WebServer/Client.h

@@ -28,7 +28,7 @@ private:
 
     struct ContentInfo {
         String type;
-        size_t length {};
+        u64 length {};
     };
 
     ErrorOr<void, WrappedError> on_ready_to_read();