mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 23:50:19 +00:00
LibFileSystemAccessClient+CrashReporter: Introduce FSAC::File and use it
The new result returned just a file stream, which wasn't sufficient enough for most applications because it didn't provide a filename. This patch will make a new File object that has both a file stream and a filename.
This commit is contained in:
parent
247db3fdd0
commit
2cbe2dd3c0
Notes:
sideshowbarker
2024-07-17 03:35:16 +09:00
Author: https://github.com/krkk Commit: https://github.com/SerenityOS/serenity/commit/2cbe2dd3c0 Pull-request: https://github.com/SerenityOS/serenity/pull/16548 Reviewed-by: https://github.com/AtkinsSJ ✅ Reviewed-by: https://github.com/LucasChollet
3 changed files with 27 additions and 3 deletions
|
@ -280,7 +280,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
return;
|
||||
}
|
||||
|
||||
auto file = file_or_error.release_value();
|
||||
auto file = file_or_error.release_value().release_stream();
|
||||
if (auto result = file->write(full_backtrace.to_byte_buffer()); result.is_error())
|
||||
GUI::MessageBox::show(window, DeprecatedString::formatted("Couldn't save file: {}.", result.release_error()), "Saving backtrace failed"sv, GUI::MessageBox::Type::Error);
|
||||
};
|
||||
|
|
|
@ -205,9 +205,14 @@ void Client::handle_prompt_end(i32 request_id, i32 error, Optional<IPC::File> co
|
|||
return;
|
||||
}
|
||||
|
||||
auto file_or_error = Core::Stream::File::adopt_fd(ipc_file->take_fd(), Core::Stream::OpenMode::ReadWrite);
|
||||
auto file_or_error = [&]() -> ErrorOr<File> {
|
||||
auto stream = TRY(Core::Stream::File::adopt_fd(ipc_file->take_fd(), Core::Stream::OpenMode::ReadWrite));
|
||||
auto filename = TRY(String::from_deprecated_string(*chosen_file));
|
||||
return File({}, move(stream), filename);
|
||||
}();
|
||||
if (file_or_error.is_error()) {
|
||||
resolve_any_promise(file_or_error.release_error());
|
||||
return;
|
||||
}
|
||||
|
||||
request_data.promise.get<PromiseType<Result>>()->resolve(file_or_error.release_value());
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#pragma once
|
||||
|
||||
#include <AK/HashMap.h>
|
||||
#include <AK/String.h>
|
||||
#include <FileSystemAccessServer/FileSystemAccessClientEndpoint.h>
|
||||
#include <FileSystemAccessServer/FileSystemAccessServerEndpoint.h>
|
||||
#include <LibCore/File.h>
|
||||
|
@ -18,8 +19,26 @@
|
|||
|
||||
namespace FileSystemAccessClient {
|
||||
|
||||
class Client;
|
||||
class File {
|
||||
public:
|
||||
File(Badge<Client>, NonnullOwnPtr<Core::Stream::File> stream, String filename)
|
||||
: m_stream(move(stream))
|
||||
, m_filename(filename)
|
||||
{
|
||||
}
|
||||
|
||||
Core::Stream::File& stream() const { return *m_stream; }
|
||||
NonnullOwnPtr<Core::Stream::File> release_stream() { return move(m_stream); }
|
||||
String filename() const { return m_filename; }
|
||||
|
||||
private:
|
||||
NonnullOwnPtr<Core::Stream::File> m_stream;
|
||||
String m_filename;
|
||||
};
|
||||
|
||||
using DeprecatedResult = ErrorOr<NonnullRefPtr<Core::File>>;
|
||||
using Result = ErrorOr<NonnullOwnPtr<Core::Stream::File>>;
|
||||
using Result = ErrorOr<File>;
|
||||
|
||||
class Client final
|
||||
: public IPC::ConnectionToServer<FileSystemAccessClientEndpoint, FileSystemAccessServerEndpoint>
|
||||
|
|
Loading…
Reference in a new issue