From 3647eb5779800e226645e1f6d670f244d7ce813c Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Thu, 27 Apr 2023 10:47:52 +0200 Subject: [PATCH 1/2] ref: Remove unused FileManager.storeDictionary Remove the unused method storeDictionary:toPath. --- Sources/Sentry/SentryFileManager.m | 8 -------- Sources/Sentry/include/SentryFileManager.h | 2 -- Tests/SentryTests/Helper/SentryFileManagerTests.swift | 6 ------ 3 files changed, 16 deletions(-) diff --git a/Sources/Sentry/SentryFileManager.m b/Sources/Sentry/SentryFileManager.m index 128d8b980d7..5f021b8ac82 100644 --- a/Sources/Sentry/SentryFileManager.m +++ b/Sources/Sentry/SentryFileManager.m @@ -442,14 +442,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) { From de54b9e6777bd05a5b69b1864b74f6e875e42b84 Mon Sep 17 00:00:00 2001 From: Philipp Hofmann Date: Thu, 27 Apr 2023 11:04:57 +0200 Subject: [PATCH 2/2] ref: Move storeData into storeEnvelope The storeData method was only used by storeEnvelope. Both methods used @synchronized. Now the storeData is moved into storeEnvelope and only one invocation of @ synchronized is needed. --- Sources/Sentry/SentryFileManager.m | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/Sources/Sentry/SentryFileManager.m b/Sources/Sentry/SentryFileManager.m index 128d8b980d7..9adeebc77e8 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;