🐛 插入/更新资源文件导致内核崩溃 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

File diff suppressed because one or more lines are too long

11
kernel/cache/asset.go vendored
View file

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

View file

@ -7,7 +7,7 @@ require (
github.com/88250/css v0.1.2 github.com/88250/css v0.1.2
github.com/88250/flock v0.8.2 github.com/88250/flock v0.8.2
github.com/88250/gulu v1.2.3-0.20220720144315-065ef35ec583 github.com/88250/gulu v1.2.3-0.20220720144315-065ef35ec583
github.com/88250/lute v1.7.5-0.20220804014636-564e20b36928 github.com/88250/lute v1.7.5-0.20220804075456-e8092b62836e
github.com/88250/melody v0.0.0-20201115062536-c0b3394adcd1 github.com/88250/melody v0.0.0-20201115062536-c0b3394adcd1
github.com/88250/pdfcpu v0.3.13 github.com/88250/pdfcpu v0.3.13
github.com/88250/protyle v0.0.0-20220519012506-0a2c8dc24397 github.com/88250/protyle v0.0.0-20220519012506-0a2c8dc24397

View file

@ -58,8 +58,8 @@ github.com/88250/gulu v1.2.0/go.mod h1:ZhEJ98UjR2y7j2toGj4/b+1rRELcZFQAPq/Yjyin2
github.com/88250/gulu v1.2.3-0.20220720144315-065ef35ec583 h1:FhA/zJemLrbOYJpdMIMBezO5rGigQSdPR1kv+aztHfA= github.com/88250/gulu v1.2.3-0.20220720144315-065ef35ec583 h1:FhA/zJemLrbOYJpdMIMBezO5rGigQSdPR1kv+aztHfA=
github.com/88250/gulu v1.2.3-0.20220720144315-065ef35ec583/go.mod h1:I1qBzsksFL2ciGSuqDE7R3XW4BUMrfDgOvSXEk7FsAI= github.com/88250/gulu v1.2.3-0.20220720144315-065ef35ec583/go.mod h1:I1qBzsksFL2ciGSuqDE7R3XW4BUMrfDgOvSXEk7FsAI=
github.com/88250/lute v1.7.4-0.20220426011157-34c9bfa2e148/go.mod h1:Bdu9LRNjQhtL3TftbtpjIWTwDVAXoS7AD8QsZQPk7zo= github.com/88250/lute v1.7.4-0.20220426011157-34c9bfa2e148/go.mod h1:Bdu9LRNjQhtL3TftbtpjIWTwDVAXoS7AD8QsZQPk7zo=
github.com/88250/lute v1.7.5-0.20220804014636-564e20b36928 h1:YLPXVaHTG865LNL64XKMM+XTGOwTQfuYGULQ+9keDK4= github.com/88250/lute v1.7.5-0.20220804075456-e8092b62836e h1:+P2HXo0zba5VaydqM8mSQins1yofqfsy/r/6qfhRxE8=
github.com/88250/lute v1.7.5-0.20220804014636-564e20b36928/go.mod h1:Bdu9LRNjQhtL3TftbtpjIWTwDVAXoS7AD8QsZQPk7zo= github.com/88250/lute v1.7.5-0.20220804075456-e8092b62836e/go.mod h1:Bdu9LRNjQhtL3TftbtpjIWTwDVAXoS7AD8QsZQPk7zo=
github.com/88250/melody v0.0.0-20201115062536-c0b3394adcd1 h1:9Cb+iN639vUI2OcIBc+4oGwml9/0J6bL6dWNb8Al+1s= github.com/88250/melody v0.0.0-20201115062536-c0b3394adcd1 h1:9Cb+iN639vUI2OcIBc+4oGwml9/0J6bL6dWNb8Al+1s=
github.com/88250/melody v0.0.0-20201115062536-c0b3394adcd1/go.mod h1:jH6MMPr8G7AMzaVmWHXZQiB1DKO3giWbcWZ7UoJ1teI= github.com/88250/melody v0.0.0-20201115062536-c0b3394adcd1/go.mod h1:jH6MMPr8G7AMzaVmWHXZQiB1DKO3giWbcWZ7UoJ1teI=
github.com/88250/pdfcpu v0.3.13 h1:touMWMZkCGalMIbEg9bxYp7rETM+zwb9hXjwhqi4I7Q= github.com/88250/pdfcpu v0.3.13 h1:touMWMZkCGalMIbEg9bxYp7rETM+zwb9hXjwhqi4I7Q=

View file

@ -167,10 +167,9 @@ func SearchAssetsByName(keyword string) (ret []*cache.Asset) {
ret = []*cache.Asset{} ret = []*cache.Asset{}
count := 0 count := 0
cache.Assets.Range(func(k, v interface{}) bool { for _, asset := range cache.Assets {
asset := v.(*cache.Asset)
if !strings.Contains(strings.ToLower(asset.HName), strings.ToLower(keyword)) { if !strings.Contains(strings.ToLower(asset.HName), strings.ToLower(keyword)) {
return true continue
} }
_, hName := search.MarkText(asset.HName, keyword, 64, Conf.Search.CaseSensitive) _, hName := search.MarkText(asset.HName, keyword, 64, Conf.Search.CaseSensitive)
@ -181,10 +180,9 @@ func SearchAssetsByName(keyword string) (ret []*cache.Asset) {
}) })
count++ count++
if Conf.Search.Limit <= count { if Conf.Search.Limit <= count {
return false return
}
} }
return true
})
sort.Slice(ret, func(i, j int) bool { sort.Slice(ret, func(i, j int) bool {
return ret[i].Updated > ret[j].Updated return ret[i].Updated > ret[j].Updated

View file

@ -53,6 +53,8 @@ func watchAssets() {
} }
go func() { go func() {
logging.Recover()
var ( var (
timer *time.Timer timer *time.Timer
lastEvent fsnotify.Event lastEvent fsnotify.Event