diff --git a/Sources/Sentry/SentryFileManager.m b/Sources/Sentry/SentryFileManager.m index 128d8b980d7..5f8509992ff 100644 --- a/Sources/Sentry/SentryFileManager.m +++ b/Sources/Sentry/SentryFileManager.m @@ -252,11 +252,19 @@ - (void)removeFileAtPath:(NSString *)path - (NSString *)storeEnvelope:(SentryEnvelope *)envelope { + NSData *envelopeData = [SentrySerialization dataWithEnvelope:envelope error:nil]; + NSString *path = + [self.envelopesPath stringByAppendingPathComponent:[self uniqueAscendingJsonName]]; + @synchronized(self) { - NSString *result = [self storeData:[SentrySerialization dataWithEnvelope:envelope error:nil] - toUniqueJSONPath:self.envelopesPath]; + SENTRY_LOG_DEBUG(@"Writing envelope to path: %@", path); + + if (![self writeData:envelopeData toPath:path]) { + SENTRY_LOG_WARN(@"Failed to store envelope."); + } + [self handleEnvelopesLimit]; - return result; + return path; } } @@ -416,18 +424,6 @@ - (NSDate *_Nullable)readTimestampLastInForeground return [NSDate sentry_fromIso8601String:timestampString]; } -- (NSString *)storeData:(NSData *)data toUniqueJSONPath:(NSString *)path -{ - @synchronized(self) { - NSString *finalPath = [path stringByAppendingPathComponent:[self uniqueAscendingJsonName]]; - SENTRY_LOG_DEBUG(@"Writing to file: %@", finalPath); - if (![self writeData:data toPath:finalPath]) { - SENTRY_LOG_WARN(@"Failed to store data."); - } - return finalPath; - } -} - - (BOOL)writeData:(NSData *)data toPath:(NSString *)path { NSError *error; @@ -442,14 +438,6 @@ - (BOOL)writeData:(NSData *)data toPath:(NSString *)path return YES; } -- (NSString *)storeDictionary:(NSDictionary *)dictionary toPath:(NSString *)path -{ - NSData *saveData = [SentrySerialization dataWithJSONObject:dictionary]; - return nil != saveData ? [self storeData:saveData toUniqueJSONPath:path] - : path; // TODO: Should we return null instead? Whoever is using this - // return value is being tricked. -} - - (void)storeAppState:(SentryAppState *)appState { NSData *data = [SentrySerialization dataWithJSONObject:[appState serialize]]; diff --git a/Sources/Sentry/include/SentryFileManager.h b/Sources/Sentry/include/SentryFileManager.h index 0f5ae265cd2..d7f3ea9a30d 100644 --- a/Sources/Sentry/include/SentryFileManager.h +++ b/Sources/Sentry/include/SentryFileManager.h @@ -67,8 +67,6 @@ SENTRY_NO_INIT - (NSArray *)allFilesInFolder:(NSString *)path; -- (NSString *)storeDictionary:(NSDictionary *)dictionary toPath:(NSString *)path; - - (void)storeAppState:(SentryAppState *)appState; - (void)moveAppStateToPreviousAppState; - (SentryAppState *_Nullable)readAppState; diff --git a/Tests/SentryTests/Helper/SentryFileManagerTests.swift b/Tests/SentryTests/Helper/SentryFileManagerTests.swift index 8f35cb14a72..d762a968d81 100644 --- a/Tests/SentryTests/Helper/SentryFileManagerTests.swift +++ b/Tests/SentryTests/Helper/SentryFileManagerTests.swift @@ -216,12 +216,6 @@ class SentryFileManagerTests: XCTestCase { sut.removeFile(atPath: "x") XCTAssertFalse(logOutput.loggedMessages.contains(where: { $0.contains("[error]") })) } - - func testFailingStoreDictionary() { - sut.store(["date": Date() ], toPath: "") - let files = sut.allFiles(inFolder: "x") - XCTAssertTrue(files.isEmpty) - } func testDefaultMaxEnvelopes() { for _ in 0...(fixture.maxCacheItems + 1) {