Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Deleting old envelopes for empty DSN #2562

Merged
merged 1 commit into from
Jan 3, 2023
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ This version adds a dependency on Swift.
- Fix ARC issue for FileManager (#2525)
- Remove delay for deleting old envelopes (#2541)
- Fix strong reference cycle for HttpTransport (#2552)
- Deleting old envelopes for empty DSN (#2562)

### Breaking Changes

Expand Down
17 changes: 14 additions & 3 deletions Sources/Sentry/SentryFileManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

NS_ASSUME_NONNULL_BEGIN

NSString *const EnvelopesPathComponent = @"envelopes";

@interface
SentryFileManager ()

Expand Down Expand Up @@ -173,8 +175,17 @@ - (void)deleteOldEnvelopesFromAllSentryPaths
continue;
}

// If the options don't have a DSN the sentry path doesn't contain a hash and the envelopes
// folder is stored in the base path.
NSString *envelopesPath;
if ([fullPath hasSuffix:EnvelopesPathComponent]) {
envelopesPath = fullPath;
} else {
envelopesPath = [fullPath stringByAppendingPathComponent:EnvelopesPathComponent];
}

// Then we will remove all old items from the envelopes subdirectory
[self deleteOldEnvelopesFromPath:[fullPath stringByAppendingPathComponent:@"envelopes"]];
[self deleteOldEnvelopesFromPath:envelopesPath];
}
}

Expand Down Expand Up @@ -472,7 +483,7 @@ - (void)moveBreadcrumbsToPreviousBreadcrumbs

- (void)moveState:(NSString *)stateFilePath toPreviousState:(NSString *)previousStateFilePath
{
SENTRY_LOG_DEBUG(@"Moving current app state to previous app state.");
SENTRY_LOG_DEBUG(@"Moving state %@ to previous %@.", stateFilePath, previousStateFilePath);
NSFileManager *fileManager = [NSFileManager defaultManager];

// We first need to remove the old previous state file,
Expand Down Expand Up @@ -664,7 +675,7 @@ - (void)createPathsWithOptions:(SentryOptions *_Nonnull)options
[self.sentryPath stringByAppendingPathComponent:@"breadcrumbs.2.state"];
self.timezoneOffsetFilePath =
[self.sentryPath stringByAppendingPathComponent:@"timezone.offset"];
self.envelopesPath = [self.sentryPath stringByAppendingPathComponent:@"envelopes"];
self.envelopesPath = [self.sentryPath stringByAppendingPathComponent:EnvelopesPathComponent];
}

- (BOOL)createDirectoryIfNotExists:(NSString *)path error:(NSError **)error
Expand Down
10 changes: 10 additions & 0 deletions Tests/SentryTests/Helper/SentryFileManagerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,17 @@ class SentryFileManagerTests: XCTestCase {
}

func testDeleteOldEnvelopes() throws {
try givenOldEnvelopes()

sut = fixture.getSut()

XCTAssertEqual(sut.getAllEnvelopes().count, 0)
}

func testDeleteOldEnvelopes_WithEmptyDSN() throws {
fixture.options.dsn = nil
sut = fixture.getSut()

try givenOldEnvelopes()

sut = fixture.getSut()
Expand Down