🐛 插入/更新资源文件导致内核崩溃 https://github.com/siyuan-note/siyuan/issues/5574

This commit is contained in:
Liang Ding 2022-08-04 18:08:15 +08:00
parent c0df1e50d4
commit caf2dc5231
No known key found for this signature in database
GPG key ID: 136F30F901A2231D
6 changed files with 19 additions and 16 deletions

11
kernel/cache/asset.go vendored
View file

@ -33,11 +33,14 @@ type Asset struct {
Updated int64 `json:"updated"`
}
var Assets = sync.Map{}
var Assets = map[string]*Asset{}
var assetsLock = sync.Mutex{}
func LoadAssets() {
start := time.Now()
Assets = sync.Map{}
assetsLock.Lock()
defer assetsLock.Unlock()
assets := filepath.Join(util.DataDir, "assets")
filepath.Walk(assets, func(path string, info fs.FileInfo, err error) error {
if info.IsDir() {
@ -52,11 +55,11 @@ func LoadAssets() {
hName := util.RemoveID(info.Name())
path = filepath.ToSlash(strings.TrimPrefix(path, util.DataDir))[1:]
Assets.Store(path, &Asset{
Assets[path] = &Asset{
HName: hName,
Path: path,
Updated: info.ModTime().UnixMilli(),
})
}
return nil
})
elapsed := time.Since(start)