mirror of
https://github.com/austinried/subtracks.git
synced 2026-11-10 23:21:59 +01:00
feat: clean up the 1.x app's leftover data on upgrade
The React Native 1.x app shipped as com.subtracks and left an AsyncStorage database (RKStorage), an older `servers` dump and a downloaded/cached artwork+audio tree in app-specific storage. v3 reads none of those paths, so an update would otherwise leave the data behind, reachable only by wiping the whole app. Remove them once at startup, gated on one of those 1.x paths existing, so a fresh install does nothing and an upgrade is cleaned exactly once. The cached trees can be large, so the delete runs off the main thread. Kept in a single file so it can be deleted once no installs can come from 1.x.
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
package com.subtracks.data
|
||||
|
||||
import org.junit.Assert.assertFalse
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.junit.rules.TemporaryFolder
|
||||
import java.io.File
|
||||
|
||||
class LegacyDataCleanupTest {
|
||||
@get:Rule
|
||||
val tmp = TemporaryFolder()
|
||||
|
||||
@Test
|
||||
fun removesThe1xLeftoversAndLeavesTheNativeData() {
|
||||
val dataDir = tmp.newFolder("data")
|
||||
val external = tmp.newFolder("external")
|
||||
|
||||
val legacyDatabase = file(dataDir, "databases/RKStorage")
|
||||
val legacyDatabaseWal = file(dataDir, "databases/RKStorage-wal")
|
||||
val legacyServers = file(dataDir, "files/servers/0.json")
|
||||
val legacyCache = file(external, "s/0/coverArt/cover")
|
||||
val nativeDatabase = file(dataDir, "databases/subtracks.db")
|
||||
val nativeDownload = file(external, "Music/downloads/song.mp3")
|
||||
|
||||
LegacyDataCleanup.run(dataDir, external)
|
||||
|
||||
assertFalse(legacyDatabase.exists())
|
||||
assertFalse(legacyDatabaseWal.exists())
|
||||
assertFalse(legacyServers.exists())
|
||||
assertFalse(legacyCache.exists())
|
||||
assertTrue(nativeDatabase.exists())
|
||||
assertTrue(nativeDownload.exists())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun leavesTheNativeDataAloneOnAFreshInstall() {
|
||||
val dataDir = tmp.newFolder("data2")
|
||||
val external = tmp.newFolder("external2")
|
||||
val nativeDatabase = file(dataDir, "databases/subtracks.db")
|
||||
val nativeDownload = file(external, "Music/downloads/song.mp3")
|
||||
|
||||
LegacyDataCleanup.run(dataDir, external)
|
||||
|
||||
assertTrue(nativeDatabase.exists())
|
||||
assertTrue(nativeDownload.exists())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun cleansUpEvenWhenExternalStorageIsUnavailable() {
|
||||
val dataDir = tmp.newFolder("data3")
|
||||
val legacyDatabase = file(dataDir, "databases/RKStorage")
|
||||
|
||||
LegacyDataCleanup.run(dataDir, null)
|
||||
|
||||
assertFalse(legacyDatabase.exists())
|
||||
}
|
||||
|
||||
private fun file(
|
||||
dir: File,
|
||||
path: String,
|
||||
): File =
|
||||
File(dir, path).apply {
|
||||
parentFile?.mkdirs()
|
||||
createNewFile()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user