Skip to content

Commit 65c78f3

Browse files
ref: Move storeData into storeEnvelope (#2966)
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.
1 parent 861d361 commit 65c78f3

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

Sources/Sentry/SentryFileManager.m

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,19 @@ - (void)removeFileAtPath:(NSString *)path
254254

255255
- (NSString *)storeEnvelope:(SentryEnvelope *)envelope
256256
{
257+
NSData *envelopeData = [SentrySerialization dataWithEnvelope:envelope error:nil];
258+
NSString *path =
259+
[self.envelopesPath stringByAppendingPathComponent:[self uniqueAscendingJsonName]];
260+
257261
@synchronized(self) {
258-
NSString *result = [self storeData:[SentrySerialization dataWithEnvelope:envelope error:nil]
259-
toUniqueJSONPath:self.envelopesPath];
262+
SENTRY_LOG_DEBUG(@"Writing envelope to path: %@", path);
263+
264+
if (![self writeData:envelopeData toPath:path]) {
265+
SENTRY_LOG_WARN(@"Failed to store envelope.");
266+
}
267+
260268
[self handleEnvelopesLimit];
261-
return result;
269+
return path;
262270
}
263271
}
264272

@@ -418,18 +426,6 @@ - (NSDate *_Nullable)readTimestampLastInForeground
418426
return [NSDate sentry_fromIso8601String:timestampString];
419427
}
420428

421-
- (NSString *)storeData:(NSData *)data toUniqueJSONPath:(NSString *)path
422-
{
423-
@synchronized(self) {
424-
NSString *finalPath = [path stringByAppendingPathComponent:[self uniqueAscendingJsonName]];
425-
SENTRY_LOG_DEBUG(@"Writing to file: %@", finalPath);
426-
if (![self writeData:data toPath:finalPath]) {
427-
SENTRY_LOG_WARN(@"Failed to store data.");
428-
}
429-
return finalPath;
430-
}
431-
}
432-
433429
- (BOOL)writeData:(NSData *)data toPath:(NSString *)path
434430
{
435431
NSError *error;

0 commit comments

Comments
 (0)