Skip to content

Commit 12ec184

Browse files
committed
Merge branch 'main' into rz/chore/disable-system-events-extras
2 parents a9fed8c + 5625283 commit 12ec184

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

sentry/src/main/java/io/sentry/cache/EnvelopeCache.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,12 @@ public void movePreviousSession(
442442
final @NotNull File currentSessionFile, final @NotNull File previousSessionFile) {
443443
try (final @NotNull ISentryLifecycleToken ignored = sessionLock.acquire()) {
444444
if (previousSessionFile.exists()) {
445-
options.getLogger().log(DEBUG, "Previous session file already exists.");
446-
return;
445+
options.getLogger().log(DEBUG, "Previous session file already exists, deleting it.");
446+
if (!previousSessionFile.delete()) {
447+
options
448+
.getLogger()
449+
.log(WARNING, "Unable to delete previous session file: %s", previousSessionFile);
450+
}
447451
}
448452

449453
if (currentSessionFile.exists()) {

sentry/src/test/java/io/sentry/MovePreviousSessionTest.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,10 @@ class MovePreviousSessionTest {
150150

151151
(fixture.options.envelopeDiskCache as EnvelopeCache).waitPreviousSessionFlush()
152152

153-
// Files should remain unchanged when previous already exists
154-
assertTrue(currentSessionFile.exists())
153+
// Current session file should have been moved to previous
154+
assertFalse(currentSessionFile.exists())
155155
assertTrue(previousSessionFile.exists())
156-
assert(currentSessionFile.readText() == "current session")
157-
assert(previousSessionFile.readText() == "previous session")
156+
assert(previousSessionFile.readText() == "current session")
158157

159158
fixture.cleanup()
160159
}

sentry/src/test/java/io/sentry/cache/EnvelopeCacheTest.kt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ class EnvelopeCacheTest {
447447
}
448448

449449
@Test
450-
fun `movePreviousSession does nothing when previous session file already exists`() {
450+
fun `movePreviousSession deletes file and moves session when previous session file already exists`() {
451451
val cache = fixture.getSUT()
452452

453453
val currentSessionFile = EnvelopeCache.getCurrentSessionFile(fixture.options.cacheDirPath!!)
@@ -465,10 +465,9 @@ class EnvelopeCacheTest {
465465
// Call movePreviousSession when previous already exists
466466
cache.movePreviousSession(currentSessionFile, previousSessionFile)
467467

468-
// Both files should remain unchanged
469-
assertTrue(currentSessionFile.exists())
468+
// Current session should be moved to previous
469+
assertFalse(currentSessionFile.exists())
470470
assertTrue(previousSessionFile.exists())
471-
assertEquals("current session content", currentSessionFile.readText())
472-
assertEquals("existing previous content", previousSessionFile.readText())
471+
assertEquals("current session content", previousSessionFile.readText())
473472
}
474473
}

0 commit comments

Comments
 (0)