提交 adf67cd3 编写于 作者: Q qiang

fix: 修复 App 端临时文件未清理的问题 question/103456

上级 cb3bf18e
......@@ -5,7 +5,9 @@ import {
import initOn from 'uni-core/service/bridge/on'
import {
NETWORK_TYPES
NETWORK_TYPES,
TEMP_PATH,
TEMP_PATH_BASE
} from '../api/constants'
import {
......@@ -205,6 +207,33 @@ function initEntryPage () {
}
}
export function clearTempFile () {
// 统一处理路径
function getPath (path) {
path = path.replace(/\/$/, '')
return path.indexOf('_') === 0 ? plus.io.convertLocalFileSystemURL(path) : path
}
var basePath = getPath(TEMP_PATH_BASE)
var tempPath = getPath(TEMP_PATH)
// 获取父目录
var dirPath = tempPath.split('/')
dirPath.pop()
dirPath = dirPath.join('/')
plus.io.resolveLocalFileSystemURL(plus.io.convertAbsoluteFileSystem(dirPath), entry => {
var reader = entry.createReader()
reader.readEntries(function (entries) {
if (entries && entries.length) {
entries.forEach(function (entry) {
if (entry.isDirectory && entry.fullPath.indexOf(basePath) === 0 && entry.fullPath
.indexOf(tempPath) !== 0) {
entry.removeRecursively()
}
})
}
})
})
}
export function registerApp (appVm) {
if (process.env.NODE_ENV !== 'production') {
console.log('[uni-app] registerApp')
......@@ -234,7 +263,10 @@ export function registerApp (appVm) {
initAppLaunch(appVm)
// 10s后清理临时文件
setTimeout(clearTempFile, 10000)
__uniConfig.ready = true
process.env.NODE_ENV !== 'production' && perf('registerApp')
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册