Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 11 additions & 23 deletions Sources/Sentry/SentryFileManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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;
Expand All @@ -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]];
Expand Down
2 changes: 0 additions & 2 deletions Sources/Sentry/include/SentryFileManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ SENTRY_NO_INIT

- (NSArray<NSString *> *)allFilesInFolder:(NSString *)path;

- (NSString *)storeDictionary:(NSDictionary *)dictionary toPath:(NSString *)path;

- (void)storeAppState:(SentryAppState *)appState;
- (void)moveAppStateToPreviousAppState;
- (SentryAppState *_Nullable)readAppState;
Expand Down
6 changes: 0 additions & 6 deletions Tests/SentryTests/Helper/SentryFileManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down