Skip to content
This repository was archived by the owner on Feb 6, 2023. It is now read-only.

Commit e0dd50b

Browse files
author
caiyuwei
committed
fix: Creating a cache file may cause a crash
1 parent f25b11a commit e0dd50b

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

library/src/main/java/com/opensource/svgaplayer/SVGACache.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ object SVGACache {
2323
if (isInitialized()) return
2424
context ?: return
2525
cacheDir = "${context.cacheDir.absolutePath}/svga/"
26-
File(cacheDir).takeIf { !it.exists() }?.mkdir()
26+
File(cacheDir).takeIf { !it.exists() }?.mkdirs()
2727
this.type = type
2828
}
2929

library/src/main/java/com/opensource/svgaplayer/SVGAParser.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.content.Context
44
import android.net.http.HttpResponseCache
55
import android.os.Handler
66
import android.os.Looper
7+
import android.util.Log
78
import com.opensource.svgaplayer.proto.MovieEntity
89
import com.opensource.svgaplayer.utils.log.LogUtils
910
import org.json.JSONObject
@@ -237,8 +238,13 @@ class SVGAParser(context: Context?) {
237238
readAsBytes(inputStream)?.let { bytes ->
238239
threadPoolExecutor.execute {
239240
SVGACache.buildSvgaFile(cacheKey).let { cacheFile ->
240-
cacheFile.takeIf { !it.exists() }?.createNewFile()
241-
FileOutputStream(cacheFile).write(bytes)
241+
try {
242+
cacheFile.takeIf { !it.exists() }?.createNewFile()
243+
FileOutputStream(cacheFile).write(bytes)
244+
} catch (e: Exception) {
245+
LogUtils.error(TAG, "create cache file fail.", e)
246+
cacheFile.delete()
247+
}
242248
}
243249
}
244250
LogUtils.info(TAG, "Input.inflate start")

0 commit comments

Comments
 (0)