summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/Applications/FileManager/FileOperationProgressWidget.cpp11
-rw-r--r--Userland/Applications/FileManager/FileOperationProgressWidget.h6
-rw-r--r--Userland/Applications/FileManager/FileUtils.cpp10
3 files changed, 16 insertions, 11 deletions
diff --git a/Userland/Applications/FileManager/FileOperationProgressWidget.cpp b/Userland/Applications/FileManager/FileOperationProgressWidget.cpp
index 6baf0f5421..8df185d1dc 100644
--- a/Userland/Applications/FileManager/FileOperationProgressWidget.cpp
+++ b/Userland/Applications/FileManager/FileOperationProgressWidget.cpp
@@ -18,7 +18,7 @@
namespace FileManager {
-FileOperationProgressWidget::FileOperationProgressWidget(FileOperation operation, NonnullRefPtr<Core::File> helper_pipe)
+FileOperationProgressWidget::FileOperationProgressWidget(FileOperation operation, NonnullOwnPtr<Core::Stream::BufferedFile> helper_pipe, int helper_pipe_fd)
: m_operation(operation)
, m_helper_pipe(move(helper_pipe))
{
@@ -69,14 +69,17 @@ FileOperationProgressWidget::FileOperationProgressWidget(FileOperation operation
VERIFY_NOT_REACHED();
}
- m_notifier = Core::Notifier::construct(m_helper_pipe->fd(), Core::Notifier::Read);
+ m_notifier = Core::Notifier::construct(helper_pipe_fd, Core::Notifier::Read);
m_notifier->on_ready_to_read = [this] {
- auto line = m_helper_pipe->read_line();
- if (line.is_null()) {
+ auto line_buffer = ByteBuffer::create_zeroed(1 * KiB).release_value_but_fixme_should_propagate_errors();
+ auto line_length_or_error = m_helper_pipe->read_line(line_buffer.bytes());
+ if (line_length_or_error.is_error() || line_length_or_error.value() == 0) {
did_error("Read from pipe returned null."sv);
return;
}
+ StringView line { line_buffer.bytes().data(), line_length_or_error.value() };
+
auto parts = line.split_view(' ');
VERIFY(!parts.is_empty());
diff --git a/Userland/Applications/FileManager/FileOperationProgressWidget.h b/Userland/Applications/FileManager/FileOperationProgressWidget.h
index 9b10da898b..1706a8307b 100644
--- a/Userland/Applications/FileManager/FileOperationProgressWidget.h
+++ b/Userland/Applications/FileManager/FileOperationProgressWidget.h
@@ -8,6 +8,7 @@
#include "FileUtils.h"
#include <LibCore/ElapsedTimer.h>
+#include <LibCore/Stream.h>
#include <LibGUI/Widget.h>
namespace FileManager {
@@ -19,7 +20,8 @@ public:
virtual ~FileOperationProgressWidget() override;
private:
- FileOperationProgressWidget(FileOperation, NonnullRefPtr<Core::File> helper_pipe);
+ // FIXME: The helper_pipe_fd parameter is only needed because we can't get the fd from a Core::Stream.
+ FileOperationProgressWidget(FileOperation, NonnullOwnPtr<Core::Stream::BufferedFile> helper_pipe, int helper_pipe_fd);
void did_finish();
void did_error(StringView message);
@@ -32,6 +34,6 @@ private:
FileOperation m_operation;
RefPtr<Core::Notifier> m_notifier;
- RefPtr<Core::File> m_helper_pipe;
+ OwnPtr<Core::Stream::BufferedFile> m_helper_pipe;
};
}
diff --git a/Userland/Applications/FileManager/FileUtils.cpp b/Userland/Applications/FileManager/FileUtils.cpp
index da986dfb01..96fcb4cec0 100644
--- a/Userland/Applications/FileManager/FileUtils.cpp
+++ b/Userland/Applications/FileManager/FileUtils.cpp
@@ -8,7 +8,7 @@
#include "FileUtils.h"
#include "FileOperationProgressWidget.h"
#include <AK/LexicalPath.h>
-#include <LibCore/File.h>
+#include <LibCore/Stream.h>
#include <LibCore/System.h>
#include <LibGUI/MessageBox.h>
#include <unistd.h>
@@ -87,9 +87,6 @@ ErrorOr<void> run_file_operation(FileOperation operation, Vector<String> const&
auto window = TRY(GUI::Window::try_create());
TRY(file_operation_windows.try_set(window));
- auto pipe_input_file = TRY(Core::File::try_create());
- pipe_input_file->open(pipe_fds[0], Core::OpenMode::ReadOnly, Core::File::ShouldCloseFileDescriptor::Yes);
-
switch (operation) {
case FileOperation::Copy:
window->set_title("Copying Files...");
@@ -104,7 +101,10 @@ ErrorOr<void> run_file_operation(FileOperation operation, Vector<String> const&
VERIFY_NOT_REACHED();
}
- (void)TRY(window->try_set_main_widget<FileOperationProgressWidget>(operation, pipe_input_file));
+ auto pipe_input_file = TRY(Core::Stream::File::adopt_fd(pipe_fds[0], Core::Stream::OpenMode::Read));
+ auto buffered_pipe = TRY(Core::Stream::BufferedFile::create(move(pipe_input_file)));
+
+ (void)TRY(window->try_set_main_widget<FileOperationProgressWidget>(operation, move(buffered_pipe), pipe_fds[0]));
window->resize(320, 190);
if (parent_window)
window->center_within(*parent_window);