summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibGUI/TextEditor.cpp
diff options
context:
space:
mode:
authorTimothy <timmot@users.noreply.github.com>2021-06-30 06:13:06 -0700
committerAndreas Kling <kling@serenityos.org>2021-07-10 15:33:46 +0200
commit73ae5200a9701f104726b673752752250beafa4d (patch)
treebd021cab74749eb840ddddc88c1cdb536ab53e6c /Userland/Libraries/LibGUI/TextEditor.cpp
parent41ce2debda1de75f80a4971afbf5ec7dcddf5ba3 (diff)
downloadserenity-73ae5200a9701f104726b673752752250beafa4d.zip
TextEditor+LibGUI: Use unveil and FileSystemAccessServer
Making use of the new FileSystemAccessServer we are able to use unveil without restricting our ability to open and save files. A file argument will be unveiled automatically however all other files require user action via the FileSystemAccessServer to gain access.
Diffstat (limited to 'Userland/Libraries/LibGUI/TextEditor.cpp')
-rw-r--r--Userland/Libraries/LibGUI/TextEditor.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/Userland/Libraries/LibGUI/TextEditor.cpp b/Userland/Libraries/LibGUI/TextEditor.cpp
index 3a9617d0e8..bf7e18fa4d 100644
--- a/Userland/Libraries/LibGUI/TextEditor.cpp
+++ b/Userland/Libraries/LibGUI/TextEditor.cpp
@@ -1198,7 +1198,7 @@ void TextEditor::timer_event(Core::TimerEvent&)
update_cursor();
}
-bool TextEditor::write_to_file(const String& path)
+bool TextEditor::write_to_file(String const& path)
{
int fd = open(path.characters(), O_WRONLY | O_CREAT | O_TRUNC, 0666);
if (fd < 0) {
@@ -1206,6 +1206,11 @@ bool TextEditor::write_to_file(const String& path)
return false;
}
+ return write_to_file_and_close(fd);
+}
+
+bool TextEditor::write_to_file_and_close(int fd)
+{
ScopeGuard fd_guard = [fd] { close(fd); };
off_t file_size = 0;