修复一处异步逻辑
parent
80d328eab4
commit
409e5f1dde
|
@ -20,14 +20,15 @@ export function checkPermission() {
|
||||||
|
|
||||||
export async function getHistory() {
|
export async function getHistory() {
|
||||||
if (await native.fs.isfile(LOCK_FILE)) {
|
if (await native.fs.isfile(LOCK_FILE)) {
|
||||||
var cache = await native.fs.read(HOST_FILE)
|
let cache = await native.fs.read(HOST_FILE)
|
||||||
return JSON.parse(cache)
|
return JSON.parse(cache)
|
||||||
}
|
}
|
||||||
|
|
||||||
var cache = native.fs.read('/etc/hosts').toString()
|
let cache = await native.fs.read('/etc/hosts').toString()
|
||||||
var records = cache.split(/[\n\r]+/)
|
let records = cache.split(/[\n\r]+/)
|
||||||
var list = []
|
let list = []
|
||||||
var dict = {}
|
let dict = {}
|
||||||
|
|
||||||
records.forEach(str => {
|
records.forEach(str => {
|
||||||
str = str.trim()
|
str = str.trim()
|
||||||
let matches = str.match(/^(#*?)\s*(\d+\.\d+\.\d+\.\d+)\s+(.*)/)
|
let matches = str.match(/^(#*?)\s*(\d+\.\d+\.\d+\.\d+)\s+(.*)/)
|
||||||
|
@ -68,8 +69,10 @@ export async function getHistory() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
list = null
|
list = null
|
||||||
native.fs.write(HOST_FILE, JSON.stringify(dict))
|
try {
|
||||||
native.fs.write(LOCK_FILE, '')
|
await native.fs.write(HOST_FILE, JSON.stringify(dict))
|
||||||
|
await native.fs.write(LOCK_FILE, '')
|
||||||
|
} catch (err) {}
|
||||||
return dict
|
return dict
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue