@onekeyfe/react-native-range-downloader 3.0.81-alpha.8 → 3.0.81-alpha.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ReactNativeRangeDownloader.podspec +1 -1
- package/android/src/main/java/com/margelo/nitro/reactnativerangedownloader/FirmwareArchiveRules.kt +12 -5
- package/android/src/main/java/com/margelo/nitro/reactnativerangedownloader/FirmwareArtifactOrphanSweep.kt +111 -0
- package/android/src/main/java/com/margelo/nitro/reactnativerangedownloader/FirmwareArtifactStore.kt +132 -68
- package/android/src/main/java/com/margelo/nitro/reactnativerangedownloader/ReactNativeRangeDownloader.kt +1 -1
- package/android/src/test/java/com/margelo/nitro/reactnativerangedownloader/FirmwareArchiveRulesTest.kt +39 -0
- package/android/src/test/java/com/margelo/nitro/reactnativerangedownloader/FirmwareArtifactOrphanSweepTest.kt +107 -0
- package/ios/FirmwareArtifactStore.swift +242 -172
- package/ios/RangeDownloadLogic.swift +194 -36
- package/ios/ReactNativeRangeDownloader.swift +9 -423
- package/lib/typescript/src/ReactNativeRangeDownloader.nitro.d.ts +3 -3
- package/lib/typescript/src/ReactNativeRangeDownloader.nitro.d.ts.map +1 -1
- package/nitrogen/generated/android/c++/JFirmwareArchiveMaterializeParams.hpp +7 -6
- package/nitrogen/generated/android/c++/JFirmwareArtifactDownloadParams.hpp +7 -7
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativerangedownloader/FirmwareArchiveMaterializeParams.kt +2 -2
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativerangedownloader/FirmwareArtifactDownloadParams.kt +3 -3
- package/nitrogen/generated/ios/ReactNativeRangeDownloader-Swift-Cxx-Bridge.hpp +15 -0
- package/nitrogen/generated/ios/swift/FirmwareArchiveMaterializeParams.swift +32 -13
- package/nitrogen/generated/ios/swift/FirmwareArtifactDownloadParams.swift +39 -8
- package/nitrogen/generated/shared/c++/FirmwareArchiveMaterializeParams.hpp +6 -5
- package/nitrogen/generated/shared/c++/FirmwareArtifactDownloadParams.hpp +9 -9
- package/package.json +1 -1
- package/src/ReactNativeRangeDownloader.nitro.ts +3 -3
- package/ios/FirmwareBackgroundSessionEventRouter.swift +0 -17
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
package com.margelo.nitro.reactnativerangedownloader
|
|
2
|
+
|
|
3
|
+
import java.io.File
|
|
4
|
+
import org.junit.Assert.assertEquals
|
|
5
|
+
import org.junit.Assert.assertFalse
|
|
6
|
+
import org.junit.Assert.assertTrue
|
|
7
|
+
import org.junit.Rule
|
|
8
|
+
import org.junit.Test
|
|
9
|
+
import org.junit.rules.TemporaryFolder
|
|
10
|
+
|
|
11
|
+
class FirmwareArtifactOrphanSweepTest {
|
|
12
|
+
@get:Rule
|
|
13
|
+
val temporaryFolder = TemporaryFolder()
|
|
14
|
+
|
|
15
|
+
@Test
|
|
16
|
+
fun removesOnlyStaleRootScratchEntriesWithExactNamesAndTypes() {
|
|
17
|
+
val root = temporaryFolder.newFolder("firmware-artifact-sweep")
|
|
18
|
+
val nowMs = 2_000_000_000_000L
|
|
19
|
+
val staleAt = nowMs - FIRMWARE_ARTIFACT_SCRATCH_GRACE_MS - 1
|
|
20
|
+
val freshAt = nowMs - FIRMWARE_ARTIFACT_SCRATCH_GRACE_MS + 1
|
|
21
|
+
val staleArchive = File(
|
|
22
|
+
root,
|
|
23
|
+
"archive-00000000-0000-4000-8000-000000000001",
|
|
24
|
+
).apply {
|
|
25
|
+
assertTrue(mkdirs())
|
|
26
|
+
File(this, "0.entry").writeText("archive")
|
|
27
|
+
}
|
|
28
|
+
val stalePromote = File(
|
|
29
|
+
root,
|
|
30
|
+
".promote-00000000-0000-4000-8000-000000000002",
|
|
31
|
+
).apply { writeText("promote") }
|
|
32
|
+
val freshArchive = File(
|
|
33
|
+
root,
|
|
34
|
+
"archive-00000000-0000-4000-8000-000000000003",
|
|
35
|
+
).apply { assertTrue(mkdirs()) }
|
|
36
|
+
val freshPromote = File(
|
|
37
|
+
root,
|
|
38
|
+
".promote-00000000-0000-4000-8000-000000000004",
|
|
39
|
+
).apply { writeText("promote") }
|
|
40
|
+
val malformedArchive = File(
|
|
41
|
+
root,
|
|
42
|
+
"archive-00000000-0000-4000-8000-000000000005.extra",
|
|
43
|
+
).apply { assertTrue(mkdirs()) }
|
|
44
|
+
val malformedPromote = File(
|
|
45
|
+
root,
|
|
46
|
+
".promote-00000000-0000-4000-8000-000000000006.tmp",
|
|
47
|
+
).apply { writeText("promote") }
|
|
48
|
+
val archiveNamedFile = File(
|
|
49
|
+
root,
|
|
50
|
+
"archive-00000000-0000-4000-8000-000000000007",
|
|
51
|
+
).apply { writeText("promote") }
|
|
52
|
+
val promoteNamedDirectory = File(
|
|
53
|
+
root,
|
|
54
|
+
".promote-00000000-0000-4000-8000-000000000008",
|
|
55
|
+
).apply { assertTrue(mkdirs()) }
|
|
56
|
+
val nestedArchive = File(
|
|
57
|
+
File(root, "nested"),
|
|
58
|
+
"archive-00000000-0000-4000-8000-000000000009",
|
|
59
|
+
).apply { assertTrue(mkdirs()) }
|
|
60
|
+
|
|
61
|
+
for (
|
|
62
|
+
entry in listOf(
|
|
63
|
+
staleArchive,
|
|
64
|
+
stalePromote,
|
|
65
|
+
malformedArchive,
|
|
66
|
+
malformedPromote,
|
|
67
|
+
archiveNamedFile,
|
|
68
|
+
promoteNamedDirectory,
|
|
69
|
+
nestedArchive,
|
|
70
|
+
)
|
|
71
|
+
) {
|
|
72
|
+
assertTrue(entry.setLastModified(staleAt))
|
|
73
|
+
}
|
|
74
|
+
for (entry in listOf(freshArchive, freshPromote)) {
|
|
75
|
+
assertTrue(entry.setLastModified(freshAt))
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
val result = sweepFirmwareArtifactOrphansAtRoot(
|
|
79
|
+
root = root,
|
|
80
|
+
retainedSha256 = emptySet(),
|
|
81
|
+
activeSha256 = emptySet(),
|
|
82
|
+
openPaths = emptySet(),
|
|
83
|
+
nowMs = nowMs,
|
|
84
|
+
)
|
|
85
|
+
|
|
86
|
+
assertEquals(2, result.first)
|
|
87
|
+
assertEquals(14L, result.second)
|
|
88
|
+
assertFalse(staleArchive.exists())
|
|
89
|
+
assertFalse(stalePromote.exists())
|
|
90
|
+
for (
|
|
91
|
+
retainedEntry in listOf(
|
|
92
|
+
freshArchive,
|
|
93
|
+
freshPromote,
|
|
94
|
+
malformedArchive,
|
|
95
|
+
malformedPromote,
|
|
96
|
+
archiveNamedFile,
|
|
97
|
+
promoteNamedDirectory,
|
|
98
|
+
nestedArchive,
|
|
99
|
+
)
|
|
100
|
+
) {
|
|
101
|
+
assertTrue(
|
|
102
|
+
"Unexpectedly removed ${retainedEntry.name}",
|
|
103
|
+
retainedEntry.exists(),
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|