Skip to content

Truly independent web browser

LibWebView: Remove migration of crash reports into profiles

Timothy Flynn573317a5182f
diff --git a/Libraries/LibWebView/Application.cpp b/Libraries/LibWebView/Application.cpp
index 5a831827c3b..780241c8874 100644
--- a/Libraries/LibWebView/Application.cpp
+++ b/Libraries/LibWebView/Application.cpp
@@ -663,15 +663,10 @@ ErrorOr<void> Application::initialize(Main::Arguments const& arguments)
}
}
- // Reports belong to the profile they came from, whose own setting decides what happens to them. A temporary
- // profile takes nothing over, since it would take it to its grave.
+ // Reports belong to the profile they came from, whose own setting decides what happens to them.
CrashReport::set_sandbox_is_disabled(m_browser_options.disable_sandbox);
auto& crash_report_store = CrashReportStore::the();
crash_report_store.set_directory(LexicalPath::join(profile().paths().data, "CrashReports"sv).string());
- if (!profile().is_temporary()) {
- if (auto result = crash_report_store.adopt_reports_from(CrashReportStore::default_directory()); result.is_error())
- warnln("Could not move crash reports into the profile: {}", result.error());
- }
if (captures_browser_crashes()) {
if (auto result = crash_report_store.initialize_browser_crash_handler(); result.is_error())
warnln("Could not prepare Browser crash reporting: {}", result.error());
diff --git a/Libraries/LibWebView/CrashReportStore.cpp b/Libraries/LibWebView/CrashReportStore.cpp
index bf91716b6e8..ae77b924f5e 100644
--- a/Libraries/LibWebView/CrashReportStore.cpp
+++ b/Libraries/LibWebView/CrashReportStore.cpp
@@ -20,7 +20,6 @@
#include <LibCore/Process.h>
#include <LibCore/StandardPaths.h>
#include <LibCore/System.h>
-#include <LibFileSystem/FileSystem.h>
#include <LibWebView/CrashReport.h>
#include <LibWebView/CrashReportStore.h>
#include <LibWebView/ProcessManager.h>
@@ -169,37 +168,11 @@ static ErrorOr<Optional<Core::Directory>> open_seen_directory_if_exists(Core::Di
}
// Moving is atomic, so a report is always in exactly one of the two directories. Moving it where it already is succeeds.
-static timespec modified_time(struct stat const&);
-
-// A profile can live on another file system than the place reports used to be kept, which rename cannot reach.
-static ErrorOr<void> copy_report_across_file_systems(Core::Directory const& from, Core::Directory const& to, ByteString const& name, struct stat const& status)
-{
- auto text = TRY(read_owned_file(from, name));
- auto file = TRY(to.open(name, Core::File::OpenMode::Write | Core::File::OpenMode::MustBeNew | Core::File::OpenMode::NoFollow, 0400));
- ArmedScopeGuard remove_incomplete_copy = [&] { (void)unlinkat(to.fd(), name.characters(), 0); };
- TRY(file->write_until_depleted(text.bytes()));
-
- // A report's age is based on this, so the copy has to expire when the report would have.
- auto modified = modified_time(status);
- timespec times[2] { modified, modified };
- if (futimens(file->fd(), times) < 0 || fsync(file->fd()) < 0)
- return Error::from_errno(errno);
- remove_incomplete_copy.disarm();
-
- if (unlinkat(from.fd(), name.characters(), 0) < 0)
- return Error::from_errno(errno);
- return {};
-}
-
static ErrorOr<void> move_report(Core::Directory const& from, Core::Directory const& to, ByteString const& name)
{
struct stat status {};
if (is_owned_regular_file_at(from, name, status)) {
- if (auto result = Core::System::renameat(from.fd(), name, to.fd(), name); result.is_error()) {
- if (result.error().code() != EXDEV)
- return result.release_error();
- TRY(copy_report_across_file_systems(from, to, name, status));
- }
+ TRY(Core::System::renameat(from.fd(), name, to.fd(), name));
// The move is only durable once both directories are, or a report could be offered again.
if (fsync(to.fd()) < 0 || fsync(from.fd()) < 0)
return Error::from_errno(errno);
@@ -222,18 +195,6 @@ static void remove_website(Core::Directory const& directory, StringView report_n
(void)unlinkat(directory.fd(), website_file_name(report_name).characters(), 0);
}
-static void move_all_reports(Core::Directory const& from, Core::Directory const& to)
-{
- Core::DirIterator iterator(from.path().string(), Core::DirIterator::SkipDots);
- while (iterator.has_next()) {
- auto name = iterator.next_path();
- if (!CrashReportStore::is_saved_report_name(name))
- continue;
- if (auto result = move_report(from, to, name); result.is_error())
- warnln("Could not move crash report {}: {}", name, result.error());
- }
-}
-
static timespec modified_time(struct stat const& status)
{
# if defined(AK_OS_MACOS)
@@ -351,9 +312,9 @@ static void remove_orphaned_websites(Core::Directory const& directory)
}
}
-static ErrorOr<void> remove_reports_in_directory(ByteString const& path, Optional<UnixDateTime> earliest_time)
+ErrorOr<void> CrashReportStore::remove_reports(Optional<UnixDateTime> earliest_time) const
{
- auto directory = TRY(open_report_directory(path));
+ auto directory = TRY(open_report_directory(m_directory));
remove_reports_older_than(directory, earliest_time);
remove_orphaned_websites(directory);
if (auto seen_directory = TRY(open_seen_directory_if_exists(directory)); seen_directory.has_value())
@@ -361,16 +322,6 @@ static ErrorOr<void> remove_reports_in_directory(ByteString const& path, Optiona
return {};
}
-// A report that could not be moved in stays where it was, but it is still ours to delete.
-ErrorOr<void> CrashReportStore::remove_reports(Optional<UnixDateTime> earliest_time) const
-{
- ErrorOr<void> adopted_directory_result {};
- if (m_adopted_directory.has_value() && FileSystem::exists(*m_adopted_directory))
- adopted_directory_result = remove_reports_in_directory(*m_adopted_directory, earliest_time);
- TRY(remove_reports_in_directory(m_directory, earliest_time));
- return adopted_directory_result;
-}
-
ErrorOr<void> CrashReportStore::remove_expired_reports(UnixDateTime now) const
{
return remove_reports(now - maximum_unsent_report_age);
@@ -411,22 +362,6 @@ Optional<String> CrashReportStore::website(ByteString const& name) const
return String::from_utf8_with_replacement_character(contents.value().view());
}
-ErrorOr<void> CrashReportStore::adopt_reports_from(ByteString const& directory)
-{
- if (directory == m_directory || !FileSystem::exists(directory))
- return {};
- m_adopted_directory = directory;
-
- auto from = TRY(open_report_directory(directory, Core::Directory::CreateDirectories::No));
- auto to = TRY(open_report_directory(m_directory));
- move_all_reports(from, to);
- if (auto seen_from = TRY(open_seen_directory_if_exists(from)); seen_from.has_value()) {
- auto seen_to = TRY(open_seen_directory(to));
- move_all_reports(*seen_from, seen_to);
- }
- return {};
-}
-
ErrorOr<void> CrashReportStore::remove_websites_saved_since(UnixDateTime since) const
{
auto directory = TRY(open_report_directory(m_directory));
@@ -628,7 +563,6 @@ ErrorOr<Vector<ByteString>> CrashReportStore::pending_report_names(UnixDateTime)
ErrorOr<void> CrashReportStore::mark_seen(ByteString const&) const { return {}; }
ErrorOr<void> CrashReportStore::remove_report(ByteString const&) const { return {}; }
ErrorOr<void> CrashReportStore::remove_all_reports() const { return {}; }
-ErrorOr<void> CrashReportStore::adopt_reports_from(ByteString const&) { return {}; }
ErrorOr<void> CrashReportStore::save_website(ByteString const&, StringView) const { return {}; }
Optional<String> CrashReportStore::website(ByteString const&) const { return {}; }
ErrorOr<void> CrashReportStore::remove_websites_saved_since(UnixDateTime) const { return {}; }
diff --git a/Libraries/LibWebView/CrashReportStore.h b/Libraries/LibWebView/CrashReportStore.h
index 68fe355256b..ed5c4cafd47 100644
--- a/Libraries/LibWebView/CrashReportStore.h
+++ b/Libraries/LibWebView/CrashReportStore.h
@@ -35,9 +35,6 @@ public:
ByteString const& directory() const { return m_directory; }
void set_directory(ByteString directory) { m_directory = move(directory); }
- // Moves in every saved report of another store, which is how reports from before they belonged to a profile arrive.
- ErrorOr<void> adopt_reports_from(ByteString const& directory);
-
ErrorOr<SavedReport> saved_report(ByteString const& name) const;
// The website a waiting report's crash happened on. It sits next to the report rather than in it, so that it stays
@@ -72,7 +69,6 @@ private:
ErrorOr<void> remove_reports(Optional<UnixDateTime> earliest_time) const;
ByteString m_directory;
- Optional<ByteString> m_adopted_directory;
};
}
diff --git a/Tests/LibWebView/TestCrashReportStore.cpp b/Tests/LibWebView/TestCrashReportStore.cpp
index 4e270280b10..8a44a8f9634 100644
--- a/Tests/LibWebView/TestCrashReportStore.cpp
+++ b/Tests/LibWebView/TestCrashReportStore.cpp
@@ -533,52 +533,3 @@ TEST_CASE(waiting_reports_are_limited_and_the_oldest_go_first)
EXPECT(waiting.contains_slow(names.last()));
EXPECT(!store.website(names.first()).has_value());
}
-
-TEST_CASE(reports_that_could_not_be_adopted_are_still_removed)
-{
- cleanup();
- ScopeGuard guard = cleanup;
-
- auto expired_name = report_name("2026-09-01T00-00-00Z"sv);
- auto recent_name = report_name("2026-10-09T00-00-00Z"sv);
- write_file(expired_name, "An expired report\n"sv, now - AK::Duration::from_seconds(31ll * 24 * 60 * 60));
- write_file(recent_name, "A recent report\n"sv);
-
- // A directory in the way of each report makes moving it fail.
- auto profile_directory = LexicalPath::join(test_directory(), "Profile"sv).string();
- MUST(Core::Directory::create(LexicalPath::join(profile_directory, expired_name), Core::Directory::CreateDirectories::Yes));
- MUST(Core::Directory::create(LexicalPath::join(profile_directory, recent_name), Core::Directory::CreateDirectories::Yes));
-
- WebView::CrashReportStore store { profile_directory };
- MUST(store.adopt_reports_from(test_directory()));
- auto left_behind = [](ByteString const& name) { return FileSystem::exists(LexicalPath::join(test_directory(), name).string()); };
- EXPECT(left_behind(expired_name));
- EXPECT(left_behind(recent_name));
-
- MUST(store.remove_expired_reports(now));
- EXPECT(!left_behind(expired_name));
- EXPECT(left_behind(recent_name));
-
- MUST(store.remove_all_reports());
- EXPECT(!left_behind(recent_name));
-}
-
-TEST_CASE(failing_to_clean_up_the_adopted_directory_still_cleans_up_the_store)
-{
- cleanup();
- ScopeGuard guard = cleanup;
-
- auto adopted_directory = LexicalPath::join(test_directory(), "Adopted"sv).string();
- MUST(Core::Directory::create(adopted_directory, Core::Directory::CreateDirectories::Yes));
-
- auto store = test_store();
- MUST(store.adopt_reports_from(adopted_directory));
- auto name = MUST(store.store_report(WebView::ProcessType::WebContent, "A report\n"sv, now));
-
- // A file in place of the directory makes opening it fail.
- MUST(FileSystem::remove(adopted_directory, FileSystem::RecursionMode::Allowed));
- write_file("Adopted"sv, "Not a directory\n"sv);
-
- EXPECT(store.remove_all_reports().is_error());
- EXPECT(!FileSystem::exists(LexicalPath::join(test_directory(), name).string()));
-}