mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-05-16 00:50:56 +08:00
🎨 Search replace generate file history https://github.com/siyuan-note/siyuan/issues/7864
This commit is contained in:
parent
5df0d4c0ce
commit
240bf6fdfd
@ -219,7 +219,13 @@ func FindReplace(keyword, replacement string, ids []string, method int) (err err
|
|||||||
var renameRoots []*ast.Node
|
var renameRoots []*ast.Node
|
||||||
renameRootTitles := map[string]string{}
|
renameRootTitles := map[string]string{}
|
||||||
cachedTrees := map[string]*parse.Tree{}
|
cachedTrees := map[string]*parse.Tree{}
|
||||||
now := time.Now()
|
|
||||||
|
historyDir, err := getHistoryDir(HistoryOpReplace, time.Now())
|
||||||
|
if nil != err {
|
||||||
|
logging.LogErrorf("get history dir failed: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
for _, id := range ids {
|
for _, id := range ids {
|
||||||
bt := treenode.GetBlockTree(id)
|
bt := treenode.GetBlockTree(id)
|
||||||
if nil == bt {
|
if nil == bt {
|
||||||
@ -236,9 +242,26 @@ func FindReplace(keyword, replacement string, ids []string, method int) (err err
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
generateReplaceHistory(tree, now)
|
historyPath := filepath.Join(historyDir, tree.Box, tree.Path)
|
||||||
|
if err = os.MkdirAll(filepath.Dir(historyPath), 0755); nil != err {
|
||||||
|
logging.LogErrorf("generate history failed: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var data []byte
|
||||||
|
if data, err = filelock.ReadFile(filepath.Join(util.DataDir, tree.Box, tree.Path)); err != nil {
|
||||||
|
logging.LogErrorf("generate history failed: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = gulu.File.WriteFileSafer(historyPath, data, 0644); err != nil {
|
||||||
|
logging.LogErrorf("generate history failed: %s", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
cachedTrees[bt.RootID] = tree
|
cachedTrees[bt.RootID] = tree
|
||||||
}
|
}
|
||||||
|
indexHistoryDir(filepath.Base(historyDir), util.NewLute())
|
||||||
|
|
||||||
for _, id := range ids {
|
for _, id := range ids {
|
||||||
bt := treenode.GetBlockTree(id)
|
bt := treenode.GetBlockTree(id)
|
||||||
@ -367,33 +390,6 @@ func FindReplace(keyword, replacement string, ids []string, method int) (err err
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateReplaceHistory(tree *parse.Tree, t time.Time) {
|
|
||||||
historyDir, err := getHistoryDir(HistoryOpReplace, t)
|
|
||||||
if nil != err {
|
|
||||||
logging.LogErrorf("get history dir failed: %s", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
historyPath := filepath.Join(historyDir, tree.Box, tree.Path)
|
|
||||||
if err = os.MkdirAll(filepath.Dir(historyPath), 0755); nil != err {
|
|
||||||
logging.LogErrorf("generate history failed: %s", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
var data []byte
|
|
||||||
if data, err = filelock.ReadFile(filepath.Join(util.DataDir, tree.Box, tree.Path)); err != nil {
|
|
||||||
logging.LogErrorf("generate history failed: %s", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if err = gulu.File.WriteFileSafer(historyPath, data, 0644); err != nil {
|
|
||||||
logging.LogErrorf("generate history failed: %s", err)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
indexHistoryDir(filepath.Base(historyDir), util.NewLute())
|
|
||||||
}
|
|
||||||
|
|
||||||
// FullTextSearchBlock 搜索内容块。
|
// FullTextSearchBlock 搜索内容块。
|
||||||
//
|
//
|
||||||
// method:0:关键字,1:查询语法,2:SQL,3:正则表达式
|
// method:0:关键字,1:查询语法,2:SQL,3:正则表达式
|
||||||
|
Loading…
Reference in New Issue
Block a user