From 9a0adaf8189532cb5f3b7cc3fead4dd12f0a5752 Mon Sep 17 00:00:00 2001 From: Ariel Demarco Date: Tue, 5 Nov 2024 12:45:12 -0300 Subject: [PATCH] Deleting dropped report after fetching it --- Sources/EmbraceCrash/EmbraceCrashReporter.swift | 1 + .../EmbraceCrashReporterTests.swift | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Sources/EmbraceCrash/EmbraceCrashReporter.swift b/Sources/EmbraceCrash/EmbraceCrashReporter.swift index a23db244..ed2fa9a0 100644 --- a/Sources/EmbraceCrash/EmbraceCrashReporter.swift +++ b/Sources/EmbraceCrash/EmbraceCrashReporter.swift @@ -146,6 +146,7 @@ public final class EmbraceCrashReporter: NSObject, CrashReporter { // Check if we drop crashes for a specific signal using the signalsBlockList if let crashSignal = self.getCrashSignal(fromReport: report), self.shouldDropCrashReport(withSignal: crashSignal) { + self.deleteCrashReport(id: id.intValue) continue } diff --git a/Tests/EmbraceCrashTests/EmbraceCrashReporterTests.swift b/Tests/EmbraceCrashTests/EmbraceCrashReporterTests.swift index 0348c854..36376b16 100644 --- a/Tests/EmbraceCrashTests/EmbraceCrashReporterTests.swift +++ b/Tests/EmbraceCrashTests/EmbraceCrashReporterTests.swift @@ -155,6 +155,8 @@ class EmbraceCrashReporterTests: XCTestCase { XCTAssertEqual(reports.count, 1) // and report shouldn't be the one with the SIGTERM signal XCTAssertEqual(reports[0].internalId, 1) + // and dropped report should have been deleted + self.thenShouldntExistReport(withName: "appId-report-0000000000000002.json") expectation.fulfill() } @@ -203,7 +205,8 @@ class EmbraceCrashReporterTests: XCTestCase { XCTAssertEqual(reports.count, 1) // and report shouldn't be the one with the SIGABRT signal XCTAssertEqual(reports[0].internalId, 2) - + // and dropped report should have been deleted + self.thenShouldntExistReport(withName: "appId-report-0000000000000001.json") expectation.fulfill() } @@ -224,6 +227,15 @@ private extension EmbraceCrashReporterTests { try FileManager.default.copyItem(atPath: report, toPath: basePath + toFilePath) } + func thenShouldntExistReport(withName name: String) { + do { + let basePath = try XCTUnwrap(crashReporter.basePath) + XCTAssertFalse(FileManager.default.fileExists(atPath: basePath + "/Reports/" + name)) + } catch let ex { + XCTFail(ex.localizedDescription) + } + } + func givenCrashReporter() { crashReporter = EmbraceCrashReporter(queue: MockQueue()) crashReporter.install(context: context, logger: logger)