mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-01-03 07:18:49 +01:00
♻️ 日志组件单独抽取项目 https://github.com/siyuan-note/siyuan/issues/5439
This commit is contained in:
parent
c8ea858976
commit
505b973c2d
70 changed files with 671 additions and 942 deletions
|
|
@ -27,19 +27,20 @@ import (
|
|||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/fsnotify/fsnotify"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
func InitAppearance() {
|
||||
util.SetBootDetails("Initializing appearance...")
|
||||
if err := os.Mkdir(util.AppearancePath, 0755); nil != err && !os.IsExist(err) {
|
||||
util.LogFatalf("create appearance folder [%s] failed: %s", util.AppearancePath, err)
|
||||
logging.LogFatalf("create appearance folder [%s] failed: %s", util.AppearancePath, err)
|
||||
}
|
||||
|
||||
unloadThemes()
|
||||
from := filepath.Join(util.WorkingDir, "appearance")
|
||||
if err := gulu.File.Copy(from, util.AppearancePath); nil != err {
|
||||
util.LogFatalf("copy appearance resources from [%s] to [%s] failed: %s", from, util.AppearancePath, err)
|
||||
logging.LogFatalf("copy appearance resources from [%s] to [%s] failed: %s", from, util.AppearancePath, err)
|
||||
}
|
||||
loadThemes()
|
||||
|
||||
|
|
@ -65,7 +66,7 @@ var themeWatchers = sync.Map{} // [string]*fsnotify.Watcher{}
|
|||
func closeThemeWatchers() {
|
||||
themeWatchers.Range(func(key, value interface{}) bool {
|
||||
if err := value.(*fsnotify.Watcher).Close(); nil != err {
|
||||
util.LogErrorf("close file watcher failed: %s", err)
|
||||
logging.LogErrorf("close file watcher failed: %s", err)
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
|
@ -78,12 +79,12 @@ func unloadThemes() {
|
|||
|
||||
dir, err := os.Open(util.ThemesPath)
|
||||
if nil != err {
|
||||
util.LogErrorf("open appearance themes folder [%s] failed: %s", util.ThemesPath, err)
|
||||
logging.LogErrorf("open appearance themes folder [%s] failed: %s", util.ThemesPath, err)
|
||||
return
|
||||
}
|
||||
themeDirs, err := dir.Readdir(-1)
|
||||
if nil != err {
|
||||
util.LogErrorf("read appearance themes folder failed: %s", err)
|
||||
logging.LogErrorf("read appearance themes folder failed: %s", err)
|
||||
return
|
||||
}
|
||||
dir.Close()
|
||||
|
|
@ -99,11 +100,11 @@ func unloadThemes() {
|
|||
func loadThemes() {
|
||||
dir, err := os.Open(util.ThemesPath)
|
||||
if nil != err {
|
||||
util.LogFatalf("open appearance themes folder [%s] failed: %s", util.ThemesPath, err)
|
||||
logging.LogFatalf("open appearance themes folder [%s] failed: %s", util.ThemesPath, err)
|
||||
}
|
||||
themeDirs, err := dir.Readdir(-1)
|
||||
if nil != err {
|
||||
util.LogFatalf("read appearance themes folder failed: %s", err)
|
||||
logging.LogFatalf("read appearance themes folder failed: %s", err)
|
||||
}
|
||||
dir.Close()
|
||||
|
||||
|
|
@ -152,15 +153,15 @@ func themeJSON(themeName string) (ret map[string]interface{}, err error) {
|
|||
}
|
||||
data, err := os.ReadFile(p)
|
||||
if nil != err {
|
||||
util.LogErrorf("read theme.json [%s] failed: %s", p, err)
|
||||
logging.LogErrorf("read theme.json [%s] failed: %s", p, err)
|
||||
return
|
||||
}
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &ret); nil != err {
|
||||
util.LogErrorf("parse theme.json [%s] failed: %s", p, err)
|
||||
logging.LogErrorf("parse theme.json [%s] failed: %s", p, err)
|
||||
return
|
||||
}
|
||||
if 5 > len(ret) {
|
||||
util.LogWarnf("invalid theme.json [%s]", p)
|
||||
logging.LogWarnf("invalid theme.json [%s]", p)
|
||||
return nil, errors.New("invalid theme.json")
|
||||
}
|
||||
return
|
||||
|
|
@ -174,15 +175,15 @@ func iconJSON(iconName string) (ret map[string]interface{}, err error) {
|
|||
}
|
||||
data, err := os.ReadFile(p)
|
||||
if nil != err {
|
||||
util.LogErrorf("read icon.json [%s] failed: %s", p, err)
|
||||
logging.LogErrorf("read icon.json [%s] failed: %s", p, err)
|
||||
return
|
||||
}
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &ret); nil != err {
|
||||
util.LogErrorf("parse icon.json [%s] failed: %s", p, err)
|
||||
logging.LogErrorf("parse icon.json [%s] failed: %s", p, err)
|
||||
return
|
||||
}
|
||||
if 4 > len(ret) {
|
||||
util.LogWarnf("invalid icon.json [%s]", p)
|
||||
logging.LogWarnf("invalid icon.json [%s]", p)
|
||||
return nil, errors.New("invalid icon.json")
|
||||
}
|
||||
return
|
||||
|
|
@ -196,15 +197,15 @@ func templateJSON(templateName string) (ret map[string]interface{}, err error) {
|
|||
}
|
||||
data, err := os.ReadFile(p)
|
||||
if nil != err {
|
||||
util.LogErrorf("read template.json [%s] failed: %s", p, err)
|
||||
logging.LogErrorf("read template.json [%s] failed: %s", p, err)
|
||||
return
|
||||
}
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &ret); nil != err {
|
||||
util.LogErrorf("parse template.json [%s] failed: %s", p, err)
|
||||
logging.LogErrorf("parse template.json [%s] failed: %s", p, err)
|
||||
return
|
||||
}
|
||||
if 4 > len(ret) {
|
||||
util.LogWarnf("invalid template.json [%s]", p)
|
||||
logging.LogWarnf("invalid template.json [%s]", p)
|
||||
return nil, errors.New("invalid template.json")
|
||||
}
|
||||
return
|
||||
|
|
@ -218,15 +219,15 @@ func widgetJSON(widgetName string) (ret map[string]interface{}, err error) {
|
|||
}
|
||||
data, err := os.ReadFile(p)
|
||||
if nil != err {
|
||||
util.LogErrorf("read widget.json [%s] failed: %s", p, err)
|
||||
logging.LogErrorf("read widget.json [%s] failed: %s", p, err)
|
||||
return
|
||||
}
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &ret); nil != err {
|
||||
util.LogErrorf("parse widget.json [%s] failed: %s", p, err)
|
||||
logging.LogErrorf("parse widget.json [%s] failed: %s", p, err)
|
||||
return
|
||||
}
|
||||
if 4 > len(ret) {
|
||||
util.LogWarnf("invalid widget.json [%s]", p)
|
||||
logging.LogWarnf("invalid widget.json [%s]", p)
|
||||
return nil, errors.New("invalid widget.json")
|
||||
}
|
||||
return
|
||||
|
|
@ -235,11 +236,11 @@ func widgetJSON(widgetName string) (ret map[string]interface{}, err error) {
|
|||
func loadIcons() {
|
||||
dir, err := os.Open(util.IconsPath)
|
||||
if nil != err {
|
||||
util.LogFatalf("open appearance icons folder [%s] failed: %s", util.IconsPath, err)
|
||||
logging.LogFatalf("open appearance icons folder [%s] failed: %s", util.IconsPath, err)
|
||||
}
|
||||
iconDirs, err := dir.Readdir(-1)
|
||||
if nil != err {
|
||||
util.LogFatalf("read appearance icons folder failed: %s", err)
|
||||
logging.LogFatalf("read appearance icons folder failed: %s", err)
|
||||
}
|
||||
dir.Close()
|
||||
|
||||
|
|
@ -278,7 +279,7 @@ func watchTheme(folder string) {
|
|||
|
||||
var err error
|
||||
if themeWatcher, err = fsnotify.NewWatcher(); nil != err {
|
||||
util.LogErrorf("add theme file watcher for folder [%s] failed: %s", folder, err)
|
||||
logging.LogErrorf("add theme file watcher for folder [%s] failed: %s", folder, err)
|
||||
return
|
||||
}
|
||||
themeWatchers.Store(folder, themeWatcher)
|
||||
|
|
@ -292,7 +293,7 @@ func watchTheme(folder string) {
|
|||
return
|
||||
}
|
||||
|
||||
//util.LogInfof(event.String())
|
||||
//logging.LogInfof(event.String())
|
||||
if event.Op&fsnotify.Write == fsnotify.Write &&
|
||||
(strings.HasSuffix(event.Name, "theme.css") || strings.HasSuffix(event.Name, "custom.css")) {
|
||||
var themeName string
|
||||
|
|
@ -318,14 +319,14 @@ func watchTheme(folder string) {
|
|||
if !ok {
|
||||
return
|
||||
}
|
||||
util.LogErrorf("watch theme file failed: %s", err)
|
||||
logging.LogErrorf("watch theme file failed: %s", err)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
//util.LogInfof("add file watcher [%s]", folder)
|
||||
//logging.LogInfof("add file watcher [%s]", folder)
|
||||
if err := themeWatcher.Add(folder); err != nil {
|
||||
util.LogErrorf("add theme files watcher for folder [%s] failed: %s", folder, err)
|
||||
logging.LogErrorf("add theme files watcher for folder [%s] failed: %s", folder, err)
|
||||
}
|
||||
<-done
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ import (
|
|||
"github.com/gabriel-vasile/mimetype"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/httpclient"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/cache"
|
||||
"github.com/siyuan-note/siyuan/kernel/search"
|
||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||
|
|
@ -96,16 +97,16 @@ func NetImg2LocalAssets(rootID string) (err error) {
|
|||
request := httpclient.NewBrowserRequest()
|
||||
resp, reqErr := request.Get(u)
|
||||
if nil != reqErr {
|
||||
util.LogErrorf("download net img [%s] failed: %s", u, reqErr)
|
||||
logging.LogErrorf("download net img [%s] failed: %s", u, reqErr)
|
||||
return ast.WalkSkipChildren
|
||||
}
|
||||
if 200 != resp.StatusCode {
|
||||
util.LogErrorf("download net img [%s] failed: %d", u, resp.StatusCode)
|
||||
logging.LogErrorf("download net img [%s] failed: %d", u, resp.StatusCode)
|
||||
return ast.WalkSkipChildren
|
||||
}
|
||||
data, repErr := resp.ToBytes()
|
||||
if nil != repErr {
|
||||
util.LogErrorf("download net img [%s] failed: %s", u, repErr)
|
||||
logging.LogErrorf("download net img [%s] failed: %s", u, repErr)
|
||||
return ast.WalkSkipChildren
|
||||
}
|
||||
var name string
|
||||
|
|
@ -138,7 +139,7 @@ func NetImg2LocalAssets(rootID string) (err error) {
|
|||
name = "net-img-" + name + "-" + ast.NewNodeID() + ext
|
||||
writePath := filepath.Join(util.DataDir, "assets", name)
|
||||
if err = gulu.File.WriteFileSafer(writePath, data, 0644); nil != err {
|
||||
util.LogErrorf("write downloaded net img [%s] to local assets [%s] failed: %s", u, writePath, err)
|
||||
logging.LogErrorf("write downloaded net img [%s] to local assets [%s] failed: %s", u, writePath, err)
|
||||
return ast.WalkSkipChildren
|
||||
}
|
||||
|
||||
|
|
@ -259,11 +260,11 @@ func uploadCloud(sqlAssets []*sql.Asset) (err error) {
|
|||
var absPath string
|
||||
absPath, err = GetAssetAbsPath(asset)
|
||||
if nil != err {
|
||||
util.LogWarnf("get asset [%s] abs path failed: %s", asset, err)
|
||||
logging.LogWarnf("get asset [%s] abs path failed: %s", asset, err)
|
||||
return
|
||||
}
|
||||
if "" == absPath {
|
||||
util.LogErrorf("not found asset [%s]", asset)
|
||||
logging.LogErrorf("not found asset [%s]", asset)
|
||||
err = errors.New(fmt.Sprintf(Conf.Language(12), asset))
|
||||
return
|
||||
}
|
||||
|
|
@ -277,7 +278,7 @@ func uploadCloud(sqlAssets []*sql.Asset) (err error) {
|
|||
|
||||
uploadAbsAssets = gulu.Str.RemoveDuplicatedElem(uploadAbsAssets)
|
||||
|
||||
util.LogInfof("uploading [%d] assets", len(uploadAbsAssets))
|
||||
logging.LogInfof("uploading [%d] assets", len(uploadAbsAssets))
|
||||
if loadErr := LoadUploadToken(); nil != loadErr {
|
||||
util.PushMsg(loadErr.Error(), 5000)
|
||||
return
|
||||
|
|
@ -286,10 +287,10 @@ func uploadCloud(sqlAssets []*sql.Asset) (err error) {
|
|||
var completedUploadAssets []string
|
||||
for _, absAsset := range uploadAbsAssets {
|
||||
if fi, statErr := os.Stat(absAsset); nil != statErr {
|
||||
util.LogErrorf("stat file [%s] failed: %s", absAsset, statErr)
|
||||
logging.LogErrorf("stat file [%s] failed: %s", absAsset, statErr)
|
||||
return statErr
|
||||
} else if util.CloudSingleFileMaxSizeLimit/10 <= fi.Size() {
|
||||
util.LogWarnf("file [%s] larger than 10MB, ignore uploading it", absAsset)
|
||||
logging.LogWarnf("file [%s] larger than 10MB, ignore uploading it", absAsset)
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
@ -301,7 +302,7 @@ func uploadCloud(sqlAssets []*sql.Asset) (err error) {
|
|||
SetCookies(&http.Cookie{Name: "symphony", Value: uploadToken}).
|
||||
Post(util.AliyunServer + "/apis/siyuan/upload?ver=" + util.Ver)
|
||||
if nil != reqErr {
|
||||
util.LogErrorf("upload assets failed: %s", reqErr)
|
||||
logging.LogErrorf("upload assets failed: %s", reqErr)
|
||||
return ErrFailedToConnectCloudServer
|
||||
}
|
||||
|
||||
|
|
@ -311,7 +312,7 @@ func uploadCloud(sqlAssets []*sql.Asset) (err error) {
|
|||
}
|
||||
|
||||
if 0 != requestResult.Code {
|
||||
util.LogErrorf("upload assets failed: %s", requestResult.Msg)
|
||||
logging.LogErrorf("upload assets failed: %s", requestResult.Msg)
|
||||
err = errors.New(fmt.Sprintf(Conf.Language(94), requestResult.Msg))
|
||||
return
|
||||
}
|
||||
|
|
@ -319,12 +320,12 @@ func uploadCloud(sqlAssets []*sql.Asset) (err error) {
|
|||
absAsset = filepath.ToSlash(absAsset)
|
||||
relAsset := absAsset[strings.Index(absAsset, "assets/"):]
|
||||
completedUploadAssets = append(completedUploadAssets, relAsset)
|
||||
util.LogInfof("uploaded asset [%s]", relAsset)
|
||||
logging.LogInfof("uploaded asset [%s]", relAsset)
|
||||
}
|
||||
|
||||
if 0 < len(completedUploadAssets) {
|
||||
syncedAssets = readWorkspaceAssets()
|
||||
util.LogInfof("uploaded [%d] assets", len(completedUploadAssets))
|
||||
logging.LogInfof("uploaded [%d] assets", len(completedUploadAssets))
|
||||
for _, completedSyncAsset := range completedUploadAssets {
|
||||
syncedAssets = append(syncedAssets, completedSyncAsset)
|
||||
}
|
||||
|
|
@ -337,7 +338,7 @@ func readWorkspaceAssets() (ret []string) {
|
|||
ret = []string{}
|
||||
confDir := filepath.Join(util.DataDir, "assets", ".siyuan")
|
||||
if err := os.MkdirAll(confDir, 0755); nil != err {
|
||||
util.LogErrorf("create assets conf dir [%s] failed: %s", confDir, err)
|
||||
logging.LogErrorf("create assets conf dir [%s] failed: %s", confDir, err)
|
||||
return
|
||||
}
|
||||
confPath := filepath.Join(confDir, "assets.json")
|
||||
|
|
@ -347,11 +348,11 @@ func readWorkspaceAssets() (ret []string) {
|
|||
|
||||
data, err := os.ReadFile(confPath)
|
||||
if nil != err {
|
||||
util.LogErrorf("read assets conf failed: %s", err)
|
||||
logging.LogErrorf("read assets conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &ret); nil != err {
|
||||
util.LogErrorf("parse assets conf failed: %s, re-init it", err)
|
||||
logging.LogErrorf("parse assets conf failed: %s, re-init it", err)
|
||||
return
|
||||
}
|
||||
return
|
||||
|
|
@ -360,7 +361,7 @@ func readWorkspaceAssets() (ret []string) {
|
|||
func saveWorkspaceAssets(assets []string) {
|
||||
confDir := filepath.Join(util.DataDir, "assets", ".siyuan")
|
||||
if err := os.MkdirAll(confDir, 0755); nil != err {
|
||||
util.LogErrorf("create assets conf dir [%s] failed: %s", confDir, err)
|
||||
logging.LogErrorf("create assets conf dir [%s] failed: %s", confDir, err)
|
||||
return
|
||||
}
|
||||
confPath := filepath.Join(confDir, "assets.json")
|
||||
|
|
@ -369,11 +370,11 @@ func saveWorkspaceAssets(assets []string) {
|
|||
sort.Strings(assets)
|
||||
data, err := gulu.JSON.MarshalIndentJSON(assets, "", " ")
|
||||
if nil != err {
|
||||
util.LogErrorf("create assets conf failed: %s", err)
|
||||
logging.LogErrorf("create assets conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
if err = gulu.File.WriteFileSafer(confPath, data, 0644); nil != err {
|
||||
util.LogErrorf("write assets conf failed: %s", err)
|
||||
logging.LogErrorf("write assets conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -390,7 +391,7 @@ func RemoveUnusedAssets() (ret []string) {
|
|||
|
||||
historyDir, err := util.GetHistoryDir("delete")
|
||||
if nil != err {
|
||||
util.LogErrorf("get history dir failed: %s", err)
|
||||
logging.LogErrorf("get history dir failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -406,7 +407,7 @@ func RemoveUnusedAssets() (ret []string) {
|
|||
for _, unusedAsset := range unusedAssets {
|
||||
if unusedAsset = filepath.Join(util.DataDir, unusedAsset); gulu.File.IsExist(unusedAsset) {
|
||||
if err := os.RemoveAll(unusedAsset); nil != err {
|
||||
util.LogErrorf("remove unused asset [%s] failed: %s", unusedAsset, err)
|
||||
logging.LogErrorf("remove unused asset [%s] failed: %s", unusedAsset, err)
|
||||
}
|
||||
}
|
||||
ret = append(ret, unusedAsset)
|
||||
|
|
@ -425,7 +426,7 @@ func RemoveUnusedAsset(p string) (ret string) {
|
|||
|
||||
historyDir, err := util.GetHistoryDir("delete")
|
||||
if nil != err {
|
||||
util.LogErrorf("get history dir failed: %s", err)
|
||||
logging.LogErrorf("get history dir failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -436,7 +437,7 @@ func RemoveUnusedAsset(p string) (ret string) {
|
|||
}
|
||||
|
||||
if err = os.RemoveAll(p); nil != err {
|
||||
util.LogErrorf("remove unused asset [%s] failed: %s", p, err)
|
||||
logging.LogErrorf("remove unused asset [%s] failed: %s", p, err)
|
||||
}
|
||||
ret = p
|
||||
IncSync()
|
||||
|
|
@ -464,7 +465,7 @@ func RenameAsset(oldPath, newName string) (err error) {
|
|||
newName = util.AssetName(newName) + filepath.Ext(oldPath)
|
||||
newPath := "assets/" + newName
|
||||
if err = gulu.File.Copy(filepath.Join(util.DataDir, oldPath), filepath.Join(util.DataDir, newPath)); nil != err {
|
||||
util.LogErrorf("copy asset [%s] failed: %s", oldPath, err)
|
||||
logging.LogErrorf("copy asset [%s] failed: %s", oldPath, err)
|
||||
return
|
||||
}
|
||||
oldName := path.Base(oldPath)
|
||||
|
|
@ -479,7 +480,7 @@ func RenameAsset(oldPath, newName string) (err error) {
|
|||
for _, treeAbsPath := range paths {
|
||||
data, readErr := filelock.NoLockFileRead(treeAbsPath)
|
||||
if nil != readErr {
|
||||
util.LogErrorf("get data [path=%s] failed: %s", treeAbsPath, readErr)
|
||||
logging.LogErrorf("get data [path=%s] failed: %s", treeAbsPath, readErr)
|
||||
err = readErr
|
||||
return
|
||||
}
|
||||
|
|
@ -490,7 +491,7 @@ func RenameAsset(oldPath, newName string) (err error) {
|
|||
|
||||
data = bytes.Replace(data, []byte(oldName), []byte(newName), -1)
|
||||
if writeErr := filelock.NoLockFileWrite(treeAbsPath, data); nil != writeErr {
|
||||
util.LogErrorf("write data [path=%s] failed: %s", treeAbsPath, writeErr)
|
||||
logging.LogErrorf("write data [path=%s] failed: %s", treeAbsPath, writeErr)
|
||||
err = writeErr
|
||||
return
|
||||
}
|
||||
|
|
@ -498,7 +499,7 @@ func RenameAsset(oldPath, newName string) (err error) {
|
|||
p := filepath.ToSlash(strings.TrimPrefix(treeAbsPath, filepath.Join(util.DataDir, notebook.ID)))
|
||||
tree, parseErr := LoadTree(notebook.ID, p)
|
||||
if nil != parseErr {
|
||||
util.LogErrorf("parse json to tree [%s] failed: %s", treeAbsPath, parseErr)
|
||||
logging.LogErrorf("parse json to tree [%s] failed: %s", treeAbsPath, parseErr)
|
||||
err = parseErr
|
||||
return
|
||||
}
|
||||
|
|
@ -795,7 +796,7 @@ func copyAssetsToDataAssets(rootPath string) {
|
|||
dataAssetsPath := filepath.Join(util.DataDir, "assets")
|
||||
for _, assetsDirPath := range assetsDirPaths {
|
||||
if err := gulu.File.Copy(assetsDirPath, dataAssetsPath); nil != err {
|
||||
util.LogErrorf("copy tree assets from [%s] to [%s] failed: %s", assetsDirPaths, dataAssetsPath, err)
|
||||
logging.LogErrorf("copy tree assets from [%s] to [%s] failed: %s", assetsDirPaths, dataAssetsPath, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/fsnotify/fsnotify"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/cache"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
|
@ -47,7 +48,7 @@ func watchAssets() {
|
|||
|
||||
var err error
|
||||
if assetsWatcher, err = fsnotify.NewWatcher(); nil != err {
|
||||
util.LogErrorf("add assets watcher for folder [%s] failed: %s", assetsDir, err)
|
||||
logging.LogErrorf("add assets watcher for folder [%s] failed: %s", assetsDir, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -72,9 +73,9 @@ func watchAssets() {
|
|||
if !ok {
|
||||
return
|
||||
}
|
||||
util.LogErrorf("watch assets failed: %s", err)
|
||||
logging.LogErrorf("watch assets failed: %s", err)
|
||||
case <-timer.C:
|
||||
//util.LogInfof("assets changed: %s", lastEvent)
|
||||
//logging.LogInfof("assets changed: %s", lastEvent)
|
||||
if lastEvent.Op&fsnotify.Write == fsnotify.Write {
|
||||
// 外部修改已有资源文件后纳入云端同步 https://github.com/siyuan-note/siyuan/issues/4694
|
||||
IncSync()
|
||||
|
|
@ -87,9 +88,9 @@ func watchAssets() {
|
|||
}()
|
||||
|
||||
if err = assetsWatcher.Add(assetsDir); err != nil {
|
||||
util.LogErrorf("add assets watcher for folder [%s] failed: %s", assetsDir, err)
|
||||
logging.LogErrorf("add assets watcher for folder [%s] failed: %s", assetsDir, err)
|
||||
}
|
||||
//util.LogInfof("added file watcher [%s]", assetsDir)
|
||||
//logging.LogInfof("added file watcher [%s]", assetsDir)
|
||||
}
|
||||
|
||||
func CloseWatchAssets() {
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import (
|
|||
"github.com/88250/lute/ast"
|
||||
"github.com/88250/lute/parse"
|
||||
"github.com/emirpasic/gods/sets/hashset"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/search"
|
||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||
|
|
@ -51,7 +52,7 @@ func RefreshBacklink(id string) {
|
|||
if nil == tree {
|
||||
tree, err = loadTreeByBlockID(ref.RootID)
|
||||
if nil != err {
|
||||
util.LogErrorf("refresh tree refs failed: %s", err)
|
||||
logging.LogErrorf("refresh tree refs failed: %s", err)
|
||||
continue
|
||||
}
|
||||
trees[ref.RootID] = tree
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import (
|
|||
"github.com/88250/lute/ast"
|
||||
"github.com/88250/lute/html"
|
||||
"github.com/88250/lute/parse"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
|
|
@ -48,7 +49,7 @@ func GetDocInfo(rootID string) (ret *BlockInfo) {
|
|||
|
||||
tree, err := loadTreeByBlockID(rootID)
|
||||
if nil != err {
|
||||
util.LogErrorf("load tree by root id [%s] failed: %s", rootID, err)
|
||||
logging.LogErrorf("load tree by root id [%s] failed: %s", rootID, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import (
|
|||
"github.com/88250/lute/parse"
|
||||
"github.com/facette/natsort"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/conf"
|
||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||
|
|
@ -65,7 +66,7 @@ func ListNotebooks() (ret []*Box, err error) {
|
|||
ret = []*Box{}
|
||||
dirs, err := os.ReadDir(util.DataDir)
|
||||
if nil != err {
|
||||
util.LogErrorf("read dir [%s] failed: %s", util.DataDir, err)
|
||||
logging.LogErrorf("read dir [%s] failed: %s", util.DataDir, err)
|
||||
return ret, err
|
||||
}
|
||||
for _, dir := range dirs {
|
||||
|
|
@ -87,18 +88,18 @@ func ListNotebooks() (ret []*Box, err error) {
|
|||
if isUserGuide(dir.Name()) {
|
||||
filelock.ReleaseAllFileLocks()
|
||||
os.RemoveAll(filepath.Join(util.DataDir, dir.Name()))
|
||||
util.LogWarnf("not found user guid box conf [%s], removed it", boxConfPath)
|
||||
logging.LogWarnf("not found user guid box conf [%s], removed it", boxConfPath)
|
||||
continue
|
||||
}
|
||||
util.LogWarnf("not found box conf [%s], recreate it", boxConfPath)
|
||||
logging.LogWarnf("not found box conf [%s], recreate it", boxConfPath)
|
||||
} else {
|
||||
data, readErr := filelock.NoLockFileRead(boxConfPath)
|
||||
if nil != readErr {
|
||||
util.LogErrorf("read box conf [%s] failed: %s", boxConfPath, readErr)
|
||||
logging.LogErrorf("read box conf [%s] failed: %s", boxConfPath, readErr)
|
||||
continue
|
||||
}
|
||||
if readErr = gulu.JSON.UnmarshalJSON(data, boxConf); nil != readErr {
|
||||
util.LogErrorf("parse box conf [%s] failed: %s", boxConfPath, readErr)
|
||||
logging.LogErrorf("parse box conf [%s] failed: %s", boxConfPath, readErr)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
|
@ -154,12 +155,12 @@ func (box *Box) GetConf() (ret *conf.BoxConf) {
|
|||
|
||||
data, err := filelock.LockFileRead(confPath)
|
||||
if nil != err {
|
||||
util.LogErrorf("read box conf [%s] failed: %s", confPath, err)
|
||||
logging.LogErrorf("read box conf [%s] failed: %s", confPath, err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = gulu.JSON.UnmarshalJSON(data, ret); nil != err {
|
||||
util.LogErrorf("parse box conf [%s] failed: %s", confPath, err)
|
||||
logging.LogErrorf("parse box conf [%s] failed: %s", confPath, err)
|
||||
return
|
||||
}
|
||||
return
|
||||
|
|
@ -169,7 +170,7 @@ func (box *Box) SaveConf(conf *conf.BoxConf) {
|
|||
confPath := filepath.Join(util.DataDir, box.ID, ".siyuan/conf.json")
|
||||
newData, err := gulu.JSON.MarshalIndentJSON(conf, "", " ")
|
||||
if nil != err {
|
||||
util.LogErrorf("marshal box conf [%s] failed: %s", confPath, err)
|
||||
logging.LogErrorf("marshal box conf [%s] failed: %s", confPath, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -189,10 +190,10 @@ func (box *Box) SaveConf(conf *conf.BoxConf) {
|
|||
func (box *Box) saveConf0(data []byte) {
|
||||
confPath := filepath.Join(util.DataDir, box.ID, ".siyuan/conf.json")
|
||||
if err := os.MkdirAll(filepath.Join(util.DataDir, box.ID, ".siyuan"), 0755); nil != err {
|
||||
util.LogErrorf("save box conf [%s] failed: %s", confPath, err)
|
||||
logging.LogErrorf("save box conf [%s] failed: %s", confPath, err)
|
||||
}
|
||||
if err := filelock.LockFileWrite(confPath, data); nil != err {
|
||||
util.LogErrorf("save box conf [%s] failed: %s", confPath, err)
|
||||
logging.LogErrorf("save box conf [%s] failed: %s", confPath, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -238,7 +239,7 @@ func (box *Box) Stat(p string) (ret *FileInfo) {
|
|||
info, err := os.Stat(absPath)
|
||||
if nil != err {
|
||||
if !os.IsNotExist(err) {
|
||||
util.LogErrorf("stat [%s] failed: %s", absPath, err)
|
||||
logging.LogErrorf("stat [%s] failed: %s", absPath, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
@ -258,7 +259,7 @@ func (box *Box) Exist(p string) bool {
|
|||
func (box *Box) Mkdir(path string) error {
|
||||
if err := os.Mkdir(filepath.Join(util.DataDir, box.ID, path), 0755); nil != err {
|
||||
msg := fmt.Sprintf(Conf.Language(6), box.Name, path, err)
|
||||
util.LogErrorf("mkdir [path=%s] in box [%s] failed: %s", path, box.ID, err)
|
||||
logging.LogErrorf("mkdir [path=%s] in box [%s] failed: %s", path, box.ID, err)
|
||||
return errors.New(msg)
|
||||
}
|
||||
IncSync()
|
||||
|
|
@ -268,7 +269,7 @@ func (box *Box) Mkdir(path string) error {
|
|||
func (box *Box) MkdirAll(path string) error {
|
||||
if err := os.MkdirAll(filepath.Join(util.DataDir, box.ID, path), 0755); nil != err {
|
||||
msg := fmt.Sprintf(Conf.Language(6), box.Name, path, err)
|
||||
util.LogErrorf("mkdir all [path=%s] in box [%s] failed: %s", path, box.ID, err)
|
||||
logging.LogErrorf("mkdir all [path=%s] in box [%s] failed: %s", path, box.ID, err)
|
||||
return errors.New(msg)
|
||||
}
|
||||
IncSync()
|
||||
|
|
@ -282,7 +283,7 @@ func (box *Box) Move(oldPath, newPath string) error {
|
|||
filelock.ReleaseFileLocks(fromPath)
|
||||
if err := os.Rename(fromPath, toPath); nil != err {
|
||||
msg := fmt.Sprintf(Conf.Language(5), box.Name, fromPath, err)
|
||||
util.LogErrorf("move [path=%s] in box [%s] failed: %s", fromPath, box.Name, err)
|
||||
logging.LogErrorf("move [path=%s] in box [%s] failed: %s", fromPath, box.Name, err)
|
||||
return errors.New(msg)
|
||||
}
|
||||
|
||||
|
|
@ -302,7 +303,7 @@ func (box *Box) Remove(path string) error {
|
|||
filelock.ReleaseFileLocks(filePath)
|
||||
if err := os.RemoveAll(filePath); nil != err {
|
||||
msg := fmt.Sprintf(Conf.Language(7), box.Name, path, err)
|
||||
util.LogErrorf("remove [path=%s] in box [%s] failed: %s", path, box.ID, err)
|
||||
logging.LogErrorf("remove [path=%s] in box [%s] failed: %s", path, box.ID, err)
|
||||
return errors.New(msg)
|
||||
}
|
||||
IncSync()
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ import (
|
|||
humanize "github.com/dustin/go-humanize"
|
||||
"github.com/getsentry/sentry-go"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/conf"
|
||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||
|
|
@ -78,7 +79,7 @@ func InitConf() {
|
|||
windowStateConf := filepath.Join(util.ConfDir, "windowState.json")
|
||||
if !gulu.File.IsExist(windowStateConf) {
|
||||
if err := gulu.File.WriteFileSafer(windowStateConf, []byte("{}"), 0644); nil != err {
|
||||
util.LogErrorf("create [windowState.json] failed: %s", err)
|
||||
logging.LogErrorf("create [windowState.json] failed: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -87,17 +88,17 @@ func InitConf() {
|
|||
if gulu.File.IsExist(confPath) {
|
||||
data, err := os.ReadFile(confPath)
|
||||
if nil != err {
|
||||
util.LogErrorf("load conf [%s] failed: %s", confPath, err)
|
||||
logging.LogErrorf("load conf [%s] failed: %s", confPath, err)
|
||||
}
|
||||
err = gulu.JSON.UnmarshalJSON(data, Conf)
|
||||
if err != nil {
|
||||
util.LogErrorf("parse conf [%s] failed: %s", confPath, err)
|
||||
logging.LogErrorf("parse conf [%s] failed: %s", confPath, err)
|
||||
}
|
||||
}
|
||||
|
||||
if "" != util.Lang {
|
||||
Conf.Lang = util.Lang
|
||||
util.LogInfof("initialized the specified language [%s]", util.Lang)
|
||||
logging.LogInfof("initialized the specified language [%s]", util.Lang)
|
||||
} else {
|
||||
if "" == Conf.Lang {
|
||||
// 未指定外观语言时使用系统语言
|
||||
|
|
@ -108,7 +109,7 @@ func InitConf() {
|
|||
if tag, err := language.Parse(lang); nil == err {
|
||||
supportLangs = append(supportLangs, tag)
|
||||
} else {
|
||||
util.LogErrorf("load language [%s] failed: %s", lang, err)
|
||||
logging.LogErrorf("load language [%s] failed: %s", lang, err)
|
||||
}
|
||||
}
|
||||
matcher := language.NewMatcher(supportLangs)
|
||||
|
|
@ -117,9 +118,9 @@ func InitConf() {
|
|||
region, _ := lang.Region()
|
||||
util.Lang = base.String() + "_" + region.String()
|
||||
Conf.Lang = util.Lang
|
||||
util.LogInfof("initialized language [%s] based on device locale", Conf.Lang)
|
||||
logging.LogInfof("initialized language [%s] based on device locale", Conf.Lang)
|
||||
} else {
|
||||
util.LogDebugf("check device locale failed [%s], using default language [en_US]", err)
|
||||
logging.LogDebugf("check device locale failed [%s], using default language [en_US]", err)
|
||||
util.Lang = "en_US"
|
||||
Conf.Lang = util.Lang
|
||||
}
|
||||
|
|
@ -235,7 +236,7 @@ func InitConf() {
|
|||
}
|
||||
if !gulu.File.IsExist(Conf.Backup.GetSaveDir()) {
|
||||
if err := os.MkdirAll(Conf.Backup.GetSaveDir(), 0755); nil != err {
|
||||
util.LogErrorf("create backup dir [%s] failed: %s", Conf.Backup.GetSaveDir(), err)
|
||||
logging.LogErrorf("create backup dir [%s] failed: %s", Conf.Backup.GetSaveDir(), err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -244,7 +245,7 @@ func InitConf() {
|
|||
}
|
||||
if !gulu.File.IsExist(Conf.Sync.GetSaveDir()) {
|
||||
if err := os.MkdirAll(Conf.Sync.GetSaveDir(), 0755); nil != err {
|
||||
util.LogErrorf("create sync dir [%s] failed: %s", Conf.Sync.GetSaveDir(), err)
|
||||
logging.LogErrorf("create sync dir [%s] failed: %s", Conf.Sync.GetSaveDir(), err)
|
||||
}
|
||||
}
|
||||
if 0 == Conf.Sync.Mode {
|
||||
|
|
@ -282,10 +283,10 @@ func InitConf() {
|
|||
Conf.LocalIPs = util.GetLocalIPs()
|
||||
|
||||
Conf.Save()
|
||||
util.SetLogLevel(Conf.LogLevel)
|
||||
logging.SetLogLevel(Conf.LogLevel)
|
||||
|
||||
if Conf.System.UploadErrLog {
|
||||
util.LogInfof("user has enabled [Automatically upload error messages and diagnostic data]")
|
||||
logging.LogInfof("user has enabled [Automatically upload error messages and diagnostic data]")
|
||||
sentry.Init(sentry.ClientOptions{
|
||||
Dsn: "https://bdff135f14654ae58a054adeceb2c308@o1173696.ingest.sentry.io/6269178",
|
||||
Release: util.Ver,
|
||||
|
|
@ -303,25 +304,25 @@ func initLang() {
|
|||
p := filepath.Join(util.WorkingDir, "appearance", "langs")
|
||||
dir, err := os.Open(p)
|
||||
if nil != err {
|
||||
util.LogFatalf("open language configuration folder [%s] failed: %s", p, err)
|
||||
logging.LogFatalf("open language configuration folder [%s] failed: %s", p, err)
|
||||
}
|
||||
defer dir.Close()
|
||||
|
||||
langNames, err := dir.Readdirnames(-1)
|
||||
if nil != err {
|
||||
util.LogFatalf("list language configuration folder [%s] failed: %s", p, err)
|
||||
logging.LogFatalf("list language configuration folder [%s] failed: %s", p, err)
|
||||
}
|
||||
|
||||
for _, langName := range langNames {
|
||||
jsonPath := filepath.Join(p, langName)
|
||||
data, err := os.ReadFile(jsonPath)
|
||||
if nil != err {
|
||||
util.LogErrorf("read language configuration [%s] failed: %s", jsonPath, err)
|
||||
logging.LogErrorf("read language configuration [%s] failed: %s", jsonPath, err)
|
||||
continue
|
||||
}
|
||||
langMap := map[string]interface{}{}
|
||||
if err := gulu.JSON.UnmarshalJSON(data, &langMap); nil != err {
|
||||
util.LogErrorf("parse language configuration failed [%s] failed: %s", jsonPath, err)
|
||||
logging.LogErrorf("parse language configuration failed [%s] failed: %s", jsonPath, err)
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
@ -331,7 +332,7 @@ func initLang() {
|
|||
for k, v := range kernelLangs {
|
||||
num, err := strconv.Atoi(k)
|
||||
if nil != err {
|
||||
util.LogErrorf("parse language configuration [%s] item [%d] failed [%s] failed: %s", p, num, err)
|
||||
logging.LogErrorf("parse language configuration [%s] item [%d] failed [%s] failed: %s", p, num, err)
|
||||
continue
|
||||
}
|
||||
kernelMap[num] = v.(string)
|
||||
|
|
@ -382,7 +383,7 @@ func Close(force bool) (err error) {
|
|||
sql.CloseDatabase()
|
||||
util.WebSocketServer.Close()
|
||||
clearWorkspaceTemp()
|
||||
util.LogInfof("exited kernel")
|
||||
logging.LogInfof("exited kernel")
|
||||
go func() {
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
os.Exit(util.ExitCodeOk)
|
||||
|
|
@ -431,7 +432,7 @@ func (conf *AppConf) Save() {
|
|||
func (conf *AppConf) save0(data []byte) {
|
||||
confPath := filepath.Join(util.ConfDir, "conf.json")
|
||||
if err := filelock.LockFileWrite(confPath, data); nil != err {
|
||||
util.LogFatalf("write conf [%s] failed: %s", confPath, err)
|
||||
logging.LogFatalf("write conf [%s] failed: %s", confPath, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -539,7 +540,7 @@ func InitBoxes() {
|
|||
if dbFile, err := os.Stat(util.DBPath); nil == err {
|
||||
dbSize = humanize.Bytes(uint64(dbFile.Size()))
|
||||
}
|
||||
util.LogInfof("database size [%s], block count [%d]", dbSize, blockCount)
|
||||
logging.LogInfof("database size [%s], block count [%d]", dbSize, blockCount)
|
||||
}
|
||||
|
||||
func IsSubscriber() bool {
|
||||
|
|
@ -554,25 +555,25 @@ func clearWorkspaceTemp() {
|
|||
|
||||
tmps, err := filepath.Glob(filepath.Join(util.TempDir, "*.tmp"))
|
||||
if nil != err {
|
||||
util.LogErrorf("glob temp files failed: %s", err)
|
||||
logging.LogErrorf("glob temp files failed: %s", err)
|
||||
}
|
||||
for _, tmp := range tmps {
|
||||
if err = os.RemoveAll(tmp); nil != err {
|
||||
util.LogErrorf("remove temp file [%s] failed: %s", tmp, err)
|
||||
logging.LogErrorf("remove temp file [%s] failed: %s", tmp, err)
|
||||
} else {
|
||||
util.LogInfof("removed temp file [%s]", tmp)
|
||||
logging.LogInfof("removed temp file [%s]", tmp)
|
||||
}
|
||||
}
|
||||
|
||||
tmps, err = filepath.Glob(filepath.Join(util.DataDir, ".siyuan", "*.tmp"))
|
||||
if nil != err {
|
||||
util.LogErrorf("glob temp files failed: %s", err)
|
||||
logging.LogErrorf("glob temp files failed: %s", err)
|
||||
}
|
||||
for _, tmp := range tmps {
|
||||
if err = os.RemoveAll(tmp); nil != err {
|
||||
util.LogErrorf("remove temp file [%s] failed: %s", tmp, err)
|
||||
logging.LogErrorf("remove temp file [%s] failed: %s", tmp, err)
|
||||
} else {
|
||||
util.LogInfof("removed temp file [%s]", tmp)
|
||||
logging.LogInfof("removed temp file [%s]", tmp)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import (
|
|||
|
||||
"github.com/88250/css"
|
||||
"github.com/88250/gulu"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
|
|
@ -133,7 +134,7 @@ func currentCSSValue(key string) string {
|
|||
if 1 > len(data) {
|
||||
data, err = os.ReadFile(theme)
|
||||
if nil != err {
|
||||
util.LogErrorf("read theme css [%s] failed: %s", theme, err)
|
||||
logging.LogErrorf("read theme css [%s] failed: %s", theme, err)
|
||||
return "#ffffff"
|
||||
}
|
||||
}
|
||||
|
|
@ -161,14 +162,14 @@ func ReadCustomCSS(themeName string) (ret map[string]map[string]string, err erro
|
|||
|
||||
if !gulu.File.IsExist(custom) {
|
||||
if err = gulu.File.CopyFile(theme, custom); nil != err {
|
||||
util.LogErrorf("copy theme [%s] to [%s] failed: %s", theme, custom, err)
|
||||
logging.LogErrorf("copy theme [%s] to [%s] failed: %s", theme, custom, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
data, err := os.ReadFile(custom)
|
||||
if nil != err {
|
||||
util.LogErrorf("read custom css [%s] failed: %s", custom, err)
|
||||
logging.LogErrorf("read custom css [%s] failed: %s", custom, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -186,7 +187,7 @@ func ReadCustomCSS(themeName string) (ret map[string]map[string]string, err erro
|
|||
// 补充现有主题中的样式
|
||||
data, err = os.ReadFile(theme)
|
||||
if nil != err {
|
||||
util.LogErrorf("read theme css [%s] failed: %s", theme, err)
|
||||
logging.LogErrorf("read theme css [%s] failed: %s", theme, err)
|
||||
return
|
||||
}
|
||||
ss = css.Parse(string(data))
|
||||
|
|
@ -232,7 +233,7 @@ func WriteCustomCSS(themeName string, cssMap map[string]interface{}) (err error)
|
|||
custom := filepath.Join(themePath, "custom.css")
|
||||
data, err := os.ReadFile(custom)
|
||||
if nil != err {
|
||||
util.LogErrorf("read custom css [%s] failed: %s", custom, err)
|
||||
logging.LogErrorf("read custom css [%s] failed: %s", custom, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -268,7 +269,7 @@ func WriteCustomCSS(themeName string, cssMap map[string]interface{}) (err error)
|
|||
}
|
||||
|
||||
if err := gulu.File.WriteFileSafer(custom, buf.Bytes(), 0644); nil != err {
|
||||
util.LogErrorf("write custom css [%s] failed: %s", custom, err)
|
||||
logging.LogErrorf("write custom css [%s] failed: %s", custom, err)
|
||||
}
|
||||
|
||||
util.BroadcastByType("main", "refreshtheme", 0, "", map[string]interface{}{
|
||||
|
|
|
|||
|
|
@ -41,6 +41,7 @@ import (
|
|||
"github.com/emirpasic/gods/sets/hashset"
|
||||
"github.com/emirpasic/gods/stacks/linkedliststack"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
|
|
@ -49,7 +50,7 @@ import (
|
|||
func ExportSY(id string) (name, zipPath string) {
|
||||
block := treenode.GetBlockTree(id)
|
||||
if nil == block {
|
||||
util.LogErrorf("not found block [%s]", id)
|
||||
logging.LogErrorf("not found block [%s]", id)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -108,7 +109,7 @@ func ExportData() (zipPath string) {
|
|||
func exportData(exportFolder string) (err error) {
|
||||
baseFolderName := "data-" + util.CurrentTimeSecondsStr()
|
||||
if err = os.MkdirAll(exportFolder, 0755); nil != err {
|
||||
util.LogErrorf("create export temp folder failed: %s", err)
|
||||
logging.LogErrorf("create export temp folder failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -119,7 +120,7 @@ func exportData(exportFolder string) (err error) {
|
|||
|
||||
data := filepath.Join(util.WorkspaceDir, "data")
|
||||
if err = stableCopy(data, exportFolder); nil != err {
|
||||
util.LogErrorf("copy data dir from [%s] to [%s] failed: %s", data, baseFolderName, err)
|
||||
logging.LogErrorf("copy data dir from [%s] to [%s] failed: %s", data, baseFolderName, err)
|
||||
err = errors.New(fmt.Sprintf(Conf.Language(14), formatErrorMsg(err)))
|
||||
return
|
||||
}
|
||||
|
|
@ -127,17 +128,17 @@ func exportData(exportFolder string) (err error) {
|
|||
zipPath := exportFolder + ".zip"
|
||||
zip, err := gulu.Zip.Create(zipPath)
|
||||
if nil != err {
|
||||
util.LogErrorf("create export data zip [%s] failed: %s", exportFolder, err)
|
||||
logging.LogErrorf("create export data zip [%s] failed: %s", exportFolder, err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = zip.AddDirectory(baseFolderName, exportFolder); nil != err {
|
||||
util.LogErrorf("create export data zip [%s] failed: %s", exportFolder, err)
|
||||
logging.LogErrorf("create export data zip [%s] failed: %s", exportFolder, err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = zip.Close(); nil != err {
|
||||
util.LogErrorf("close export data zip failed: %s", err)
|
||||
logging.LogErrorf("close export data zip failed: %s", err)
|
||||
}
|
||||
|
||||
os.RemoveAll(exportFolder)
|
||||
|
|
@ -174,19 +175,19 @@ func ExportDocx(id, savePath string) (err error) {
|
|||
pandoc.Stdin = bytes.NewBufferString(dom)
|
||||
output, err := pandoc.CombinedOutput()
|
||||
if nil != err {
|
||||
util.LogErrorf("export docx failed: %s", gulu.Str.FromBytes(output))
|
||||
logging.LogErrorf("export docx failed: %s", gulu.Str.FromBytes(output))
|
||||
msg := fmt.Sprintf(Conf.Language(14), gulu.Str.FromBytes(output))
|
||||
return errors.New(msg)
|
||||
}
|
||||
|
||||
if err = gulu.File.Copy(tmpDocxPath, filepath.Join(savePath, name+".docx")); nil != err {
|
||||
util.LogErrorf("export docx failed: %s", err)
|
||||
logging.LogErrorf("export docx failed: %s", err)
|
||||
return errors.New(fmt.Sprintf(Conf.Language(14), err))
|
||||
}
|
||||
tmpAssets := filepath.Join(tmpDir, "assets")
|
||||
if gulu.File.IsDir(tmpAssets) {
|
||||
if err = gulu.File.Copy(tmpAssets, filepath.Join(savePath, "assets")); nil != err {
|
||||
util.LogErrorf("export docx failed: %s", err)
|
||||
logging.LogErrorf("export docx failed: %s", err)
|
||||
return errors.New(fmt.Sprintf(Conf.Language(14), err))
|
||||
}
|
||||
}
|
||||
|
|
@ -200,7 +201,7 @@ func ExportMarkdownHTML(id, savePath string, docx bool) (name, dom string) {
|
|||
name = path.Base(tree.HPath)
|
||||
|
||||
if err := os.MkdirAll(savePath, 0755); nil != err {
|
||||
util.LogErrorf("mkdir [%s] failed: %s", savePath, err)
|
||||
logging.LogErrorf("mkdir [%s] failed: %s", savePath, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -209,12 +210,12 @@ func ExportMarkdownHTML(id, savePath string, docx bool) (name, dom string) {
|
|||
if strings.HasPrefix(asset, "assets/") {
|
||||
srcAbsPath, err := GetAssetAbsPath(asset)
|
||||
if nil != err {
|
||||
util.LogWarnf("resolve path of asset [%s] failed: %s", asset, err)
|
||||
logging.LogWarnf("resolve path of asset [%s] failed: %s", asset, err)
|
||||
continue
|
||||
}
|
||||
targetAbsPath := filepath.Join(savePath, asset)
|
||||
if err = gulu.File.Copy(srcAbsPath, targetAbsPath); nil != err {
|
||||
util.LogWarnf("copy asset from [%s] to [%s] failed: %s", srcAbsPath, targetAbsPath, err)
|
||||
logging.LogWarnf("copy asset from [%s] to [%s] failed: %s", srcAbsPath, targetAbsPath, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -224,7 +225,7 @@ func ExportMarkdownHTML(id, savePath string, docx bool) (name, dom string) {
|
|||
from := filepath.Join(util.WorkingDir, src)
|
||||
to := filepath.Join(savePath, src)
|
||||
if err := gulu.File.Copy(from, to); nil != err {
|
||||
util.LogWarnf("copy stage from [%s] to [%s] failed: %s", from, savePath, err)
|
||||
logging.LogWarnf("copy stage from [%s] to [%s] failed: %s", from, savePath, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -238,7 +239,7 @@ func ExportMarkdownHTML(id, savePath string, docx bool) (name, dom string) {
|
|||
from := filepath.Join(util.AppearancePath, src)
|
||||
to := filepath.Join(savePath, "appearance", src)
|
||||
if err := gulu.File.Copy(from, to); nil != err {
|
||||
util.LogErrorf("copy appearance from [%s] to [%s] failed: %s", from, savePath, err)
|
||||
logging.LogErrorf("copy appearance from [%s] to [%s] failed: %s", from, savePath, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -283,7 +284,7 @@ func ExportHTML(id, savePath string, pdf bool) (name, dom string) {
|
|||
name = path.Base(tree.Path)
|
||||
|
||||
if err := os.MkdirAll(savePath, 0755); nil != err {
|
||||
util.LogErrorf("mkdir [%s] failed: %s", savePath, err)
|
||||
logging.LogErrorf("mkdir [%s] failed: %s", savePath, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -291,12 +292,12 @@ func ExportHTML(id, savePath string, pdf bool) (name, dom string) {
|
|||
for _, asset := range assets {
|
||||
srcAbsPath, err := GetAssetAbsPath(asset)
|
||||
if nil != err {
|
||||
util.LogWarnf("resolve path of asset [%s] failed: %s", asset, err)
|
||||
logging.LogWarnf("resolve path of asset [%s] failed: %s", asset, err)
|
||||
continue
|
||||
}
|
||||
targetAbsPath := filepath.Join(savePath, asset)
|
||||
if err = gulu.File.Copy(srcAbsPath, targetAbsPath); nil != err {
|
||||
util.LogWarnf("copy asset from [%s] to [%s] failed: %s", srcAbsPath, targetAbsPath, err)
|
||||
logging.LogWarnf("copy asset from [%s] to [%s] failed: %s", srcAbsPath, targetAbsPath, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -307,7 +308,7 @@ func ExportHTML(id, savePath string, pdf bool) (name, dom string) {
|
|||
from := filepath.Join(util.WorkingDir, src)
|
||||
to := filepath.Join(savePath, src)
|
||||
if err := gulu.File.Copy(from, to); nil != err {
|
||||
util.LogErrorf("copy stage from [%s] to [%s] failed: %s", from, savePath, err)
|
||||
logging.LogErrorf("copy stage from [%s] to [%s] failed: %s", from, savePath, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -321,7 +322,7 @@ func ExportHTML(id, savePath string, pdf bool) (name, dom string) {
|
|||
from := filepath.Join(util.AppearancePath, src)
|
||||
to := filepath.Join(savePath, "appearance", src)
|
||||
if err := gulu.File.Copy(from, to); nil != err {
|
||||
util.LogErrorf("copy appearance from [%s] to [%s] failed: %s", from, savePath, err)
|
||||
logging.LogErrorf("copy appearance from [%s] to [%s] failed: %s", from, savePath, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -444,7 +445,7 @@ func AddPDFOutline(id, p string) (err error) {
|
|||
outFile := inFile + ".tmp"
|
||||
err = api.AddBookmarksFile(inFile, outFile, topBms, nil)
|
||||
if nil != err {
|
||||
util.LogErrorf("add bookmark failed: %s", err)
|
||||
logging.LogErrorf("add bookmark failed: %s", err)
|
||||
return
|
||||
}
|
||||
err = os.Rename(outFile, inFile)
|
||||
|
|
@ -467,7 +468,7 @@ func CopyStdMarkdown(id string) string {
|
|||
func ExportMarkdown(id string) (name, zipPath string) {
|
||||
block := treenode.GetBlockTree(id)
|
||||
if nil == block {
|
||||
util.LogErrorf("not found block [%s]", id)
|
||||
logging.LogErrorf("not found block [%s]", id)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -496,7 +497,7 @@ func BatchExportMarkdown(boxID, folderPath string) (zipPath string) {
|
|||
} else {
|
||||
block := treenode.GetBlockTreeRootByHPath(box.ID, folderPath)
|
||||
if nil == block {
|
||||
util.LogErrorf("not found block")
|
||||
logging.LogErrorf("not found block")
|
||||
return
|
||||
}
|
||||
baseFolderName = path.Base(block.HPath)
|
||||
|
|
@ -527,7 +528,7 @@ func exportMarkdownZip(boxID, baseFolderName string, docPaths []string) (zipPath
|
|||
|
||||
exportFolder := filepath.Join(util.TempDir, "export", baseFolderName)
|
||||
if err := os.MkdirAll(exportFolder, 0755); nil != err {
|
||||
util.LogErrorf("create export temp folder failed: %s", err)
|
||||
logging.LogErrorf("create export temp folder failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -553,11 +554,11 @@ func exportMarkdownZip(boxID, baseFolderName string, docPaths []string) (zipPath
|
|||
}
|
||||
writeFolder := filepath.Dir(writePath)
|
||||
if err := os.MkdirAll(writeFolder, 0755); nil != err {
|
||||
util.LogErrorf("create export temp folder [%s] failed: %s", writeFolder, err)
|
||||
logging.LogErrorf("create export temp folder [%s] failed: %s", writeFolder, err)
|
||||
continue
|
||||
}
|
||||
if err := gulu.File.WriteFileSafer(writePath, gulu.Str.ToBytes(md), 0644); nil != err {
|
||||
util.LogErrorf("write export markdown file [%s] failed: %s", writePath, err)
|
||||
logging.LogErrorf("write export markdown file [%s] failed: %s", writePath, err)
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
@ -573,7 +574,7 @@ func exportMarkdownZip(boxID, baseFolderName string, docPaths []string) (zipPath
|
|||
|
||||
srcPath, err := GetAssetAbsPath(asset)
|
||||
if nil != err {
|
||||
util.LogWarnf("get asset [%s] abs path failed: %s", asset, err)
|
||||
logging.LogWarnf("get asset [%s] abs path failed: %s", asset, err)
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
@ -584,7 +585,7 @@ func exportMarkdownZip(boxID, baseFolderName string, docPaths []string) (zipPath
|
|||
err = gulu.File.CopyFile(srcPath, destPath)
|
||||
}
|
||||
if nil != err {
|
||||
util.LogErrorf("copy asset from [%s] to [%s] failed: %s", srcPath, destPath, err)
|
||||
logging.LogErrorf("copy asset from [%s] to [%s] failed: %s", srcPath, destPath, err)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
|
@ -593,17 +594,17 @@ func exportMarkdownZip(boxID, baseFolderName string, docPaths []string) (zipPath
|
|||
zipPath = exportFolder + ".zip"
|
||||
zip, err := gulu.Zip.Create(zipPath)
|
||||
if nil != err {
|
||||
util.LogErrorf("create export markdown zip [%s] failed: %s", exportFolder, err)
|
||||
logging.LogErrorf("create export markdown zip [%s] failed: %s", exportFolder, err)
|
||||
return ""
|
||||
}
|
||||
|
||||
if err = zip.AddDirectory(baseFolderName, exportFolder); nil != err {
|
||||
util.LogErrorf("create export markdown zip [%s] failed: %s", exportFolder, err)
|
||||
logging.LogErrorf("create export markdown zip [%s] failed: %s", exportFolder, err)
|
||||
return ""
|
||||
}
|
||||
|
||||
if err = zip.Close(); nil != err {
|
||||
util.LogErrorf("close export markdown zip failed: %s", err)
|
||||
logging.LogErrorf("close export markdown zip failed: %s", err)
|
||||
}
|
||||
|
||||
os.RemoveAll(exportFolder)
|
||||
|
|
@ -624,7 +625,7 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
|
|||
|
||||
exportFolder := filepath.Join(util.TempDir, "export", baseFolderName)
|
||||
if err := os.MkdirAll(exportFolder, 0755); nil != err {
|
||||
util.LogErrorf("create export temp folder failed: %s", err)
|
||||
logging.LogErrorf("create export temp folder failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -657,7 +658,7 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
|
|||
readPath := filepath.Join(util.DataDir, tree.Box, tree.Path)
|
||||
data, readErr := filelock.NoLockFileRead(readPath)
|
||||
if nil != readErr {
|
||||
util.LogErrorf("read file [%s] failed: %s", readPath, readErr)
|
||||
logging.LogErrorf("read file [%s] failed: %s", readPath, readErr)
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
@ -665,11 +666,11 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
|
|||
writePath = filepath.Join(exportFolder, writePath)
|
||||
writeFolder := filepath.Dir(writePath)
|
||||
if mkdirErr := os.MkdirAll(writeFolder, 0755); nil != mkdirErr {
|
||||
util.LogErrorf("create export temp folder [%s] failed: %s", writeFolder, mkdirErr)
|
||||
logging.LogErrorf("create export temp folder [%s] failed: %s", writeFolder, mkdirErr)
|
||||
continue
|
||||
}
|
||||
if writeErr := os.WriteFile(writePath, data, 0644); nil != writeErr {
|
||||
util.LogErrorf("write export file [%s] failed: %s", writePath, writeErr)
|
||||
logging.LogErrorf("write export file [%s] failed: %s", writePath, writeErr)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
|
@ -679,14 +680,14 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
|
|||
readPath := filepath.Join(util.DataDir, tree.Box, tree.Path)
|
||||
data, readErr := filelock.NoLockFileRead(readPath)
|
||||
if nil != readErr {
|
||||
util.LogErrorf("read file [%s] failed: %s", readPath, readErr)
|
||||
logging.LogErrorf("read file [%s] failed: %s", readPath, readErr)
|
||||
continue
|
||||
}
|
||||
|
||||
writePath := strings.TrimPrefix(tree.Path, rootDirPath)
|
||||
writePath = filepath.Join(exportFolder, treeID+".sy")
|
||||
if writeErr := os.WriteFile(writePath, data, 0644); nil != writeErr {
|
||||
util.LogErrorf("write export file [%s] failed: %s", writePath, writeErr)
|
||||
logging.LogErrorf("write export file [%s] failed: %s", writePath, writeErr)
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
|
@ -713,7 +714,7 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
|
|||
|
||||
srcPath, assetErr := GetAssetAbsPath(asset)
|
||||
if nil != assetErr {
|
||||
util.LogWarnf("get asset [%s] abs path failed: %s", asset, assetErr)
|
||||
logging.LogWarnf("get asset [%s] abs path failed: %s", asset, assetErr)
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
@ -724,7 +725,7 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
|
|||
assetErr = gulu.File.CopyFile(srcPath, destPath)
|
||||
}
|
||||
if nil != assetErr {
|
||||
util.LogErrorf("copy asset from [%s] to [%s] failed: %s", srcPath, destPath, assetErr)
|
||||
logging.LogErrorf("copy asset from [%s] to [%s] failed: %s", srcPath, destPath, assetErr)
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
@ -735,17 +736,17 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
|
|||
zipPath = exportFolder + ".sy.zip"
|
||||
zip, err := gulu.Zip.Create(zipPath)
|
||||
if nil != err {
|
||||
util.LogErrorf("create export markdown zip [%s] failed: %s", exportFolder, err)
|
||||
logging.LogErrorf("create export markdown zip [%s] failed: %s", exportFolder, err)
|
||||
return ""
|
||||
}
|
||||
|
||||
if err = zip.AddDirectory(baseFolderName, exportFolder); nil != err {
|
||||
util.LogErrorf("create export markdown zip [%s] failed: %s", exportFolder, err)
|
||||
logging.LogErrorf("create export markdown zip [%s] failed: %s", exportFolder, err)
|
||||
return ""
|
||||
}
|
||||
|
||||
if err = zip.Close(); nil != err {
|
||||
util.LogErrorf("close export markdown zip failed: %s", err)
|
||||
logging.LogErrorf("close export markdown zip failed: %s", err)
|
||||
}
|
||||
|
||||
os.RemoveAll(exportFolder)
|
||||
|
|
@ -987,24 +988,24 @@ func exportTree(tree *parse.Tree, wysiwyg bool) (ret *parse.Tree) {
|
|||
p := refID[:strings.LastIndex(refID, "/")]
|
||||
absPath, err := GetAssetAbsPath(p)
|
||||
if nil != err {
|
||||
util.LogWarnf("get assets abs path by rel path [%s] failed: %s", p, err)
|
||||
logging.LogWarnf("get assets abs path by rel path [%s] failed: %s", p, err)
|
||||
return ast.WalkSkipChildren
|
||||
}
|
||||
sya := absPath + ".sya"
|
||||
syaData, err := os.ReadFile(sya)
|
||||
if nil != err {
|
||||
util.LogErrorf("read file [%s] failed: %s", sya, err)
|
||||
logging.LogErrorf("read file [%s] failed: %s", sya, err)
|
||||
return ast.WalkSkipChildren
|
||||
}
|
||||
syaJSON := map[string]interface{}{}
|
||||
if err = gulu.JSON.UnmarshalJSON(syaData, &syaJSON); nil != err {
|
||||
util.LogErrorf("unmarshal file [%s] failed: %s", sya, err)
|
||||
logging.LogErrorf("unmarshal file [%s] failed: %s", sya, err)
|
||||
return ast.WalkSkipChildren
|
||||
}
|
||||
annotationID := refID[strings.LastIndex(refID, "/")+1:]
|
||||
annotationData := syaJSON[annotationID]
|
||||
if nil == annotationData {
|
||||
util.LogErrorf("not found annotation [%s] in .sya", annotationID)
|
||||
logging.LogErrorf("not found annotation [%s] in .sya", annotationID)
|
||||
return ast.WalkSkipChildren
|
||||
}
|
||||
pages := annotationData.(map[string]interface{})["pages"].([]interface{})
|
||||
|
|
@ -1293,7 +1294,7 @@ func collectFootnotesDefs(id string, refFootnotes *[]*refAsFootnotes, treeCache
|
|||
}
|
||||
node := treenode.GetNodeInTree(t, b.ID)
|
||||
if nil == node {
|
||||
util.LogErrorf("not found node [%s] in tree [%s]", b.ID, t.Root.ID)
|
||||
logging.LogErrorf("not found node [%s] in tree [%s]", b.ID, t.Root.ID)
|
||||
return
|
||||
}
|
||||
collectFootnotesDefs0(node, refFootnotes, treeCache, depth)
|
||||
|
|
|
|||
|
|
@ -40,6 +40,7 @@ import (
|
|||
"github.com/facette/natsort"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/cache"
|
||||
"github.com/siyuan-note/siyuan/kernel/filesys"
|
||||
"github.com/siyuan-note/siyuan/kernel/search"
|
||||
|
|
@ -138,19 +139,19 @@ func (box *Box) docIAL(p string) (ret map[string]string) {
|
|||
if util.IsCorruptedSYData(data) {
|
||||
filelock.UnlockFile(filePath)
|
||||
if removeErr := os.RemoveAll(filePath); nil == removeErr {
|
||||
util.LogInfof("removed corrupted data file [path=%s, length=%d]", filePath, len(data))
|
||||
logging.LogInfof("removed corrupted data file [path=%s, length=%d]", filePath, len(data))
|
||||
} else {
|
||||
util.LogWarnf("remove corrupted data file [path=%s, length=%d] failed: %s", filePath, len(data), removeErr)
|
||||
logging.LogWarnf("remove corrupted data file [path=%s, length=%d] failed: %s", filePath, len(data), removeErr)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
if nil != err {
|
||||
util.LogErrorf("read file [%s] failed: %s", p, err)
|
||||
logging.LogErrorf("read file [%s] failed: %s", p, err)
|
||||
return nil
|
||||
}
|
||||
ret = readDocIAL(data)
|
||||
if nil == ret {
|
||||
util.LogWarnf("tree [%s] is corrupted", filePath)
|
||||
logging.LogWarnf("tree [%s] is corrupted", filePath)
|
||||
return nil
|
||||
}
|
||||
cache.PutDocIAL(p, ret)
|
||||
|
|
@ -160,7 +161,7 @@ func (box *Box) docIAL(p string) (ret map[string]string) {
|
|||
func readDocIAL(data []byte) (ret map[string]string) {
|
||||
doc := map[string]interface{}{}
|
||||
if err := gulu.JSON.UnmarshalJSON(data, &doc); nil != err {
|
||||
util.LogErrorf("unmarshal data failed: %s", err)
|
||||
logging.LogErrorf("unmarshal data failed: %s", err)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
@ -241,7 +242,7 @@ func ListDocTree(boxID, path string, sortMode int) (ret []*File, totals int, err
|
|||
}
|
||||
elapsed := time.Now().Sub(start).Milliseconds()
|
||||
if 100 < elapsed {
|
||||
util.LogWarnf("ls elapsed [%dms]", elapsed)
|
||||
logging.LogWarnf("ls elapsed [%dms]", elapsed)
|
||||
}
|
||||
|
||||
start = time.Now()
|
||||
|
|
@ -286,7 +287,7 @@ func ListDocTree(boxID, path string, sortMode int) (ret []*File, totals int, err
|
|||
}
|
||||
elapsed = time.Now().Sub(start).Milliseconds()
|
||||
if 500 < elapsed {
|
||||
util.LogWarnf("build docs elapsed [%dms]", elapsed)
|
||||
logging.LogWarnf("build docs elapsed [%dms]", elapsed)
|
||||
}
|
||||
|
||||
start = time.Now()
|
||||
|
|
@ -298,7 +299,7 @@ func ListDocTree(boxID, path string, sortMode int) (ret []*File, totals int, err
|
|||
}
|
||||
elapsed = time.Now().Sub(start).Milliseconds()
|
||||
if 500 < elapsed {
|
||||
util.LogWarnf("query root block ref count elapsed [%dms]", elapsed)
|
||||
logging.LogWarnf("query root block ref count elapsed [%dms]", elapsed)
|
||||
}
|
||||
|
||||
start = time.Now()
|
||||
|
|
@ -359,7 +360,7 @@ func ListDocTree(boxID, path string, sortMode int) (ret []*File, totals int, err
|
|||
|
||||
elapsed = time.Now().Sub(start).Milliseconds()
|
||||
if 200 < elapsed {
|
||||
util.LogInfof("sort docs elapsed [%dms]", elapsed)
|
||||
logging.LogInfof("sort docs elapsed [%dms]", elapsed)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
@ -376,7 +377,7 @@ func BlocksWordCount(ids []string) (runeCount, wordCount int) {
|
|||
for _, id := range ids {
|
||||
bt := treenode.GetBlockTree(id)
|
||||
if nil == bt {
|
||||
util.LogWarnf("block tree not found [%s]", id)
|
||||
logging.LogWarnf("block tree not found [%s]", id)
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
@ -908,12 +909,12 @@ func DuplicateDoc(rootID string) (err error) {
|
|||
if nil != err {
|
||||
tx, txErr := sql.BeginTx()
|
||||
if nil != txErr {
|
||||
util.LogFatalf("transaction failed: %s", txErr)
|
||||
logging.LogFatalf("transaction failed: %s", txErr)
|
||||
return
|
||||
}
|
||||
sql.ClearBoxHash(tx)
|
||||
sql.CommitTx(tx)
|
||||
util.LogFatalf("transaction failed: %s", err)
|
||||
logging.LogFatalf("transaction failed: %s", err)
|
||||
return
|
||||
}
|
||||
sql.WaitForWritingDatabase()
|
||||
|
|
@ -1090,7 +1091,7 @@ func MoveDoc(fromBoxID, fromPath, toBoxID, toPath string) (newPath string, err e
|
|||
}
|
||||
if err = os.Rename(absFromPath, absToPath); nil != err {
|
||||
msg := fmt.Sprintf(Conf.Language(5), fromBox.Name, fromPath, err)
|
||||
util.LogErrorf("move [path=%s] in box [%s] failed: %s", fromPath, fromBoxID, err)
|
||||
logging.LogErrorf("move [path=%s] in box [%s] failed: %s", fromPath, fromBoxID, err)
|
||||
err = errors.New(msg)
|
||||
return
|
||||
}
|
||||
|
|
@ -1116,7 +1117,7 @@ func MoveDoc(fromBoxID, fromPath, toBoxID, toPath string) (newPath string, err e
|
|||
filelock.ReleaseFileLocks(absFromPath)
|
||||
if err = os.Rename(absFromPath, absToPath); nil != err {
|
||||
msg := fmt.Sprintf(Conf.Language(5), fromBox.Name, fromPath, err)
|
||||
util.LogErrorf("move [path=%s] in box [%s] failed: %s", fromPath, fromBoxID, err)
|
||||
logging.LogErrorf("move [path=%s] in box [%s] failed: %s", fromPath, fromBoxID, err)
|
||||
err = errors.New(msg)
|
||||
return
|
||||
}
|
||||
|
|
@ -1152,7 +1153,7 @@ func RemoveDoc(boxID, p string) (err error) {
|
|||
|
||||
historyDir, err := util.GetHistoryDir("delete")
|
||||
if nil != err {
|
||||
util.LogErrorf("get history dir failed: %s", err)
|
||||
logging.LogErrorf("get history dir failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -1290,11 +1291,11 @@ func CreateDailyNote(boxID string) (p string, err error) {
|
|||
if "" != boxConf.DailyNoteTemplatePath {
|
||||
tplPath := filepath.Join(util.DataDir, "templates", boxConf.DailyNoteTemplatePath)
|
||||
if !gulu.File.IsExist(tplPath) {
|
||||
util.LogWarnf("not found daily note template [%s]", tplPath)
|
||||
logging.LogWarnf("not found daily note template [%s]", tplPath)
|
||||
} else {
|
||||
dom, err = renderTemplate(tplPath, id)
|
||||
if nil != err {
|
||||
util.LogWarnf("render daily note template [%s] failed: %s", boxConf.DailyNoteTemplatePath, err)
|
||||
logging.LogWarnf("render daily note template [%s] failed: %s", boxConf.DailyNoteTemplatePath, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1350,7 +1351,7 @@ func createDoc(boxID, p, title, dom string) (err error) {
|
|||
parentID := path.Base(folder)
|
||||
parentTree, err := loadTreeByBlockID(parentID)
|
||||
if nil != err {
|
||||
util.LogErrorf("get parent tree [id=%s] failed", parentID)
|
||||
logging.LogErrorf("get parent tree [id=%s] failed", parentID)
|
||||
return ErrBlockNotFound
|
||||
}
|
||||
hPath = path.Join(parentTree.HPath, title)
|
||||
|
|
@ -1392,12 +1393,12 @@ func createDoc(boxID, p, title, dom string) (err error) {
|
|||
if nil != err {
|
||||
tx, txErr := sql.BeginTx()
|
||||
if nil != txErr {
|
||||
util.LogFatalf("transaction failed: %s", txErr)
|
||||
logging.LogFatalf("transaction failed: %s", txErr)
|
||||
return
|
||||
}
|
||||
sql.ClearBoxHash(tx)
|
||||
sql.CommitTx(tx)
|
||||
util.LogFatalf("transaction failed: %s", err)
|
||||
logging.LogFatalf("transaction failed: %s", err)
|
||||
return
|
||||
}
|
||||
WaitForWritingFiles()
|
||||
|
|
@ -1417,12 +1418,12 @@ func moveSorts(rootID, fromBox, toBox string) {
|
|||
if gulu.File.IsExist(fromConfPath) {
|
||||
data, err := filelock.LockFileRead(fromConfPath)
|
||||
if nil != err {
|
||||
util.LogErrorf("read sort conf failed: %s", err)
|
||||
logging.LogErrorf("read sort conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &fromFullSortIDs); nil != err {
|
||||
util.LogErrorf("unmarshal sort conf failed: %s", err)
|
||||
logging.LogErrorf("unmarshal sort conf failed: %s", err)
|
||||
}
|
||||
}
|
||||
for _, id := range ids {
|
||||
|
|
@ -1434,12 +1435,12 @@ func moveSorts(rootID, fromBox, toBox string) {
|
|||
if gulu.File.IsExist(toConfPath) {
|
||||
data, err := filelock.LockFileRead(toConfPath)
|
||||
if nil != err {
|
||||
util.LogErrorf("read sort conf failed: %s", err)
|
||||
logging.LogErrorf("read sort conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &toFullSortIDs); nil != err {
|
||||
util.LogErrorf("unmarshal sort conf failed: %s", err)
|
||||
logging.LogErrorf("unmarshal sort conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -1450,11 +1451,11 @@ func moveSorts(rootID, fromBox, toBox string) {
|
|||
|
||||
data, err := gulu.JSON.MarshalIndentJSON(toFullSortIDs, "", " ")
|
||||
if nil != err {
|
||||
util.LogErrorf("marshal sort conf failed: %s", err)
|
||||
logging.LogErrorf("marshal sort conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
if err = filelock.LockFileWrite(toConfPath, data); nil != err {
|
||||
util.LogErrorf("write sort conf failed: %s", err)
|
||||
logging.LogErrorf("write sort conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -1507,7 +1508,7 @@ func ChangeFileTreeSort(boxID string, paths []string) {
|
|||
absParentPath := filepath.Join(util.DataDir, boxID, parentPath)
|
||||
files, err := os.ReadDir(absParentPath)
|
||||
if nil != err {
|
||||
util.LogErrorf("read dir [%s] failed: %s", err)
|
||||
logging.LogErrorf("read dir [%s] failed: %s", err)
|
||||
}
|
||||
|
||||
sortFolderIDs := map[string]int{}
|
||||
|
|
@ -1527,7 +1528,7 @@ func ChangeFileTreeSort(boxID string, paths []string) {
|
|||
|
||||
confDir := filepath.Join(util.DataDir, box.ID, ".siyuan")
|
||||
if err = os.MkdirAll(confDir, 0755); nil != err {
|
||||
util.LogErrorf("create conf dir failed: %s", err)
|
||||
logging.LogErrorf("create conf dir failed: %s", err)
|
||||
return
|
||||
}
|
||||
confPath := filepath.Join(confDir, "sort.json")
|
||||
|
|
@ -1536,12 +1537,12 @@ func ChangeFileTreeSort(boxID string, paths []string) {
|
|||
if gulu.File.IsExist(confPath) {
|
||||
data, err = filelock.LockFileRead(confPath)
|
||||
if nil != err {
|
||||
util.LogErrorf("read sort conf failed: %s", err)
|
||||
logging.LogErrorf("read sort conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &fullSortIDs); nil != err {
|
||||
util.LogErrorf("unmarshal sort conf failed: %s", err)
|
||||
logging.LogErrorf("unmarshal sort conf failed: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1551,11 +1552,11 @@ func ChangeFileTreeSort(boxID string, paths []string) {
|
|||
|
||||
data, err = gulu.JSON.MarshalIndentJSON(fullSortIDs, "", " ")
|
||||
if nil != err {
|
||||
util.LogErrorf("marshal sort conf failed: %s", err)
|
||||
logging.LogErrorf("marshal sort conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
if err = filelock.LockFileWrite(confPath, data); nil != err {
|
||||
util.LogErrorf("write sort conf failed: %s", err)
|
||||
logging.LogErrorf("write sort conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -1570,13 +1571,13 @@ func (box *Box) fillSort(files *[]*File) {
|
|||
|
||||
data, err := filelock.LockFileRead(confPath)
|
||||
if nil != err {
|
||||
util.LogErrorf("read sort conf failed: %s", err)
|
||||
logging.LogErrorf("read sort conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
fullSortIDs := map[string]int{}
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &fullSortIDs); nil != err {
|
||||
util.LogErrorf("unmarshal sort conf failed: %s", err)
|
||||
logging.LogErrorf("unmarshal sort conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -1617,13 +1618,13 @@ func (box *Box) removeSort(rootID, path string) {
|
|||
|
||||
data, err := filelock.LockFileRead(confPath)
|
||||
if nil != err {
|
||||
util.LogErrorf("read sort conf failed: %s", err)
|
||||
logging.LogErrorf("read sort conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
fullSortIDs := map[string]int{}
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &fullSortIDs); nil != err {
|
||||
util.LogErrorf("unmarshal sort conf failed: %s", err)
|
||||
logging.LogErrorf("unmarshal sort conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -1633,11 +1634,11 @@ func (box *Box) removeSort(rootID, path string) {
|
|||
|
||||
data, err = gulu.JSON.MarshalIndentJSON(fullSortIDs, "", " ")
|
||||
if nil != err {
|
||||
util.LogErrorf("marshal sort conf failed: %s", err)
|
||||
logging.LogErrorf("marshal sort conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
if err = filelock.LockFileWrite(confPath, data); nil != err {
|
||||
util.LogErrorf("write sort conf failed: %s", err)
|
||||
logging.LogErrorf("write sort conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -1647,10 +1648,10 @@ func ServeFile(c *gin.Context, filePath string) (err error) {
|
|||
|
||||
if filelock.IsLocked(filePath) {
|
||||
if err = filelock.UnlockFile(filePath); nil == err {
|
||||
util.LogInfof("unlocked file [%s]", filePath)
|
||||
logging.LogInfof("unlocked file [%s]", filePath)
|
||||
} else {
|
||||
msg := fmt.Sprintf("unlock file [%s] failed: %s", filePath, err)
|
||||
util.LogErrorf(msg)
|
||||
logging.LogErrorf(msg)
|
||||
return errors.New(msg)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ import (
|
|||
"github.com/88250/lute/parse"
|
||||
"github.com/88250/lute/render"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
|
@ -94,24 +95,24 @@ func AutoSpace(rootID string) (err error) {
|
|||
func generateFormatHistory(tree *parse.Tree) {
|
||||
historyDir, err := util.GetHistoryDir("format")
|
||||
if nil != err {
|
||||
util.LogErrorf("get history dir failed: %s", 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 {
|
||||
util.LogErrorf("generate history failed: %s", err)
|
||||
logging.LogErrorf("generate history failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
var data []byte
|
||||
if data, err = filelock.NoLockFileRead(filepath.Join(util.DataDir, tree.Box, tree.Path)); err != nil {
|
||||
util.LogErrorf("generate history failed: %s", err)
|
||||
logging.LogErrorf("generate history failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = gulu.File.WriteFileSafer(historyPath, data, 0644); err != nil {
|
||||
util.LogErrorf("generate history failed: %s", err)
|
||||
logging.LogErrorf("generate history failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -25,9 +25,9 @@ import (
|
|||
"github.com/88250/gulu"
|
||||
"github.com/88250/lute/ast"
|
||||
"github.com/88250/lute/html"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
type GraphNode struct {
|
||||
|
|
@ -462,7 +462,7 @@ func pruneUnref(nodes *[]*GraphNode, links *[]*GraphLink) {
|
|||
}
|
||||
|
||||
if maxBlocks < len(tmpNodes) {
|
||||
util.LogWarnf("exceeded the maximum number of render nodes [%d]", maxBlocks)
|
||||
logging.LogWarnf("exceeded the maximum number of render nodes [%d]", maxBlocks)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import (
|
|||
"github.com/88250/gulu"
|
||||
"github.com/88250/protyle"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/conf"
|
||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
|
|
@ -82,10 +83,10 @@ func ClearWorkspaceHistory() (err error) {
|
|||
historyDir := util.HistoryDir
|
||||
if gulu.File.IsDir(historyDir) {
|
||||
if err = os.RemoveAll(historyDir); nil != err {
|
||||
util.LogErrorf("remove workspace history dir [%s] failed: %s", historyDir, err)
|
||||
logging.LogErrorf("remove workspace history dir [%s] failed: %s", historyDir, err)
|
||||
return
|
||||
}
|
||||
util.LogInfof("removed workspace history dir [%s]", historyDir)
|
||||
logging.LogInfof("removed workspace history dir [%s]", historyDir)
|
||||
}
|
||||
|
||||
// 以下部分是老版本的清理逻辑,暂时保留
|
||||
|
|
@ -103,27 +104,27 @@ func ClearWorkspaceHistory() (err error) {
|
|||
}
|
||||
|
||||
if err = os.RemoveAll(historyDir); nil != err {
|
||||
util.LogErrorf("remove notebook history dir [%s] failed: %s", historyDir, err)
|
||||
logging.LogErrorf("remove notebook history dir [%s] failed: %s", historyDir, err)
|
||||
return
|
||||
}
|
||||
util.LogInfof("removed notebook history dir [%s]", historyDir)
|
||||
logging.LogInfof("removed notebook history dir [%s]", historyDir)
|
||||
}
|
||||
|
||||
historyDir = filepath.Join(util.DataDir, ".siyuan", "history")
|
||||
if gulu.File.IsDir(historyDir) {
|
||||
if err = os.RemoveAll(historyDir); nil != err {
|
||||
util.LogErrorf("remove data history dir [%s] failed: %s", historyDir, err)
|
||||
logging.LogErrorf("remove data history dir [%s] failed: %s", historyDir, err)
|
||||
return
|
||||
}
|
||||
util.LogInfof("removed data history dir [%s]", historyDir)
|
||||
logging.LogInfof("removed data history dir [%s]", historyDir)
|
||||
}
|
||||
historyDir = filepath.Join(util.DataDir, "assets", ".siyuan", "history")
|
||||
if gulu.File.IsDir(historyDir) {
|
||||
if err = os.RemoveAll(historyDir); nil != err {
|
||||
util.LogErrorf("remove assets history dir [%s] failed: %s", historyDir, err)
|
||||
logging.LogErrorf("remove assets history dir [%s] failed: %s", historyDir, err)
|
||||
return
|
||||
}
|
||||
util.LogInfof("removed assets history dir [%s]", historyDir)
|
||||
logging.LogInfof("removed assets history dir [%s]", historyDir)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
@ -135,13 +136,13 @@ func GetDocHistoryContent(historyPath string) (content string, err error) {
|
|||
|
||||
data, err := filelock.NoLockFileRead(historyPath)
|
||||
if nil != err {
|
||||
util.LogErrorf("read file [%s] failed: %s", historyPath, err)
|
||||
logging.LogErrorf("read file [%s] failed: %s", historyPath, err)
|
||||
return
|
||||
}
|
||||
luteEngine := NewLute()
|
||||
historyTree, err := protyle.ParseJSONWithoutFix(luteEngine, data)
|
||||
if nil != err {
|
||||
util.LogErrorf("parse tree from file [%s] failed, remove it", historyPath)
|
||||
logging.LogErrorf("parse tree from file [%s] failed, remove it", historyPath)
|
||||
os.RemoveAll(historyPath)
|
||||
return
|
||||
}
|
||||
|
|
@ -217,7 +218,7 @@ func RollbackAssetsHistory(historyPath string) (err error) {
|
|||
to := filepath.Join(util.DataDir, "assets", filepath.Base(historyPath))
|
||||
|
||||
if err = gulu.File.Copy(from, to); nil != err {
|
||||
util.LogErrorf("copy file [%s] to [%s] failed: %s", from, to, err)
|
||||
logging.LogErrorf("copy file [%s] to [%s] failed: %s", from, to, err)
|
||||
return
|
||||
}
|
||||
IncSync()
|
||||
|
|
@ -233,7 +234,7 @@ func RollbackNotebookHistory(historyPath string) (err error) {
|
|||
to := filepath.Join(util.DataDir, filepath.Base(historyPath))
|
||||
|
||||
if err = gulu.File.Copy(from, to); nil != err {
|
||||
util.LogErrorf("copy file [%s] to [%s] failed: %s", from, to, err)
|
||||
logging.LogErrorf("copy file [%s] to [%s] failed: %s", from, to, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -264,7 +265,7 @@ func GetDocHistory(boxID string) (ret []*History, err error) {
|
|||
|
||||
historyBoxDirs, err := filepath.Glob(historyDir + "/*/" + boxID)
|
||||
if nil != err {
|
||||
util.LogErrorf("read dir [%s] failed: %s", historyDir, err)
|
||||
logging.LogErrorf("read dir [%s] failed: %s", historyDir, err)
|
||||
return
|
||||
}
|
||||
sort.Slice(historyBoxDirs, func(i, j int) bool {
|
||||
|
|
@ -287,12 +288,12 @@ func GetDocHistory(boxID string) (ret []*History, err error) {
|
|||
|
||||
data, err := filelock.NoLockFileRead(path)
|
||||
if nil != err {
|
||||
util.LogErrorf("read file [%s] failed: %s", path, err)
|
||||
logging.LogErrorf("read file [%s] failed: %s", path, err)
|
||||
return nil
|
||||
}
|
||||
historyTree, err := protyle.ParseJSONWithoutFix(luteEngine, data)
|
||||
if nil != err {
|
||||
util.LogErrorf("parse tree from file [%s] failed, remove it", path)
|
||||
logging.LogErrorf("parse tree from file [%s] failed, remove it", path)
|
||||
os.RemoveAll(path)
|
||||
return nil
|
||||
}
|
||||
|
|
@ -349,7 +350,7 @@ func GetNotebookHistory() (ret []*History, err error) {
|
|||
|
||||
historyNotebookConfs, err := filepath.Glob(historyDir + "/*-delete/*/.siyuan/conf.json")
|
||||
if nil != err {
|
||||
util.LogErrorf("read dir [%s] failed: %s", historyDir, err)
|
||||
logging.LogErrorf("read dir [%s] failed: %s", historyDir, err)
|
||||
return
|
||||
}
|
||||
sort.Slice(historyNotebookConfs, func(i, j int) bool {
|
||||
|
|
@ -369,11 +370,11 @@ func GetNotebookHistory() (ret []*History, err error) {
|
|||
var c conf.BoxConf
|
||||
data, readErr := os.ReadFile(historyNotebookConf)
|
||||
if nil != readErr {
|
||||
util.LogErrorf("read notebook conf [%s] failed: %s", historyNotebookConf, readErr)
|
||||
logging.LogErrorf("read notebook conf [%s] failed: %s", historyNotebookConf, readErr)
|
||||
continue
|
||||
}
|
||||
if err = json.Unmarshal(data, &c); nil != err {
|
||||
util.LogErrorf("parse notebook conf [%s] failed: %s", historyNotebookConf, err)
|
||||
logging.LogErrorf("parse notebook conf [%s] failed: %s", historyNotebookConf, err)
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
@ -409,7 +410,7 @@ func GetAssetsHistory() (ret []*History, err error) {
|
|||
|
||||
historyAssetsDirs, err := filepath.Glob(historyDir + "/*/assets")
|
||||
if nil != err {
|
||||
util.LogErrorf("read dir [%s] failed: %s", historyDir, err)
|
||||
logging.LogErrorf("read dir [%s] failed: %s", historyDir, err)
|
||||
return
|
||||
}
|
||||
sort.Slice(historyAssetsDirs, func(i, j int) bool {
|
||||
|
|
@ -477,25 +478,25 @@ func (box *Box) generateDocHistory0() {
|
|||
|
||||
historyDir, err := util.GetHistoryDir("update")
|
||||
if nil != err {
|
||||
util.LogErrorf("get history dir failed: %s", err)
|
||||
logging.LogErrorf("get history dir failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
historyPath := filepath.Join(historyDir, box.ID, strings.TrimPrefix(file, filepath.Join(util.DataDir, box.ID)))
|
||||
if err = os.MkdirAll(filepath.Dir(historyPath), 0755); nil != err {
|
||||
util.LogErrorf("generate history failed: %s", err)
|
||||
logging.LogErrorf("generate history failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
var data []byte
|
||||
if data, err = filelock.NoLockFileRead(file); err != nil {
|
||||
util.LogErrorf("generate history failed: %s", err)
|
||||
logging.LogErrorf("generate history failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = gulu.File.WriteFileSafer(historyPath, data, 0644); err != nil {
|
||||
util.LogErrorf("generate history failed: %s", err)
|
||||
logging.LogErrorf("generate history failed: %s", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -509,7 +510,7 @@ func clearOutdatedHistoryDir(historyDir string) {
|
|||
|
||||
dirs, err := os.ReadDir(historyDir)
|
||||
if nil != err {
|
||||
util.LogErrorf("clear history [%s] failed: %s", historyDir, err)
|
||||
logging.LogErrorf("clear history [%s] failed: %s", historyDir, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -518,7 +519,7 @@ func clearOutdatedHistoryDir(historyDir string) {
|
|||
for _, dir := range dirs {
|
||||
dirInfo, err := dir.Info()
|
||||
if nil != err {
|
||||
util.LogErrorf("read history dir [%s] failed: %s", dir.Name(), err)
|
||||
logging.LogErrorf("read history dir [%s] failed: %s", dir.Name(), err)
|
||||
continue
|
||||
}
|
||||
if Conf.Editor.HistoryRetentionDays < int(now.Sub(dirInfo.ModTime()).Hours()/24) {
|
||||
|
|
@ -527,10 +528,10 @@ func clearOutdatedHistoryDir(historyDir string) {
|
|||
}
|
||||
for _, dir := range removes {
|
||||
if err = os.RemoveAll(dir); nil != err {
|
||||
util.LogErrorf("remove history dir [%s] failed: %s", dir, err)
|
||||
logging.LogErrorf("remove history dir [%s] failed: %s", dir, err)
|
||||
continue
|
||||
}
|
||||
//util.LogInfof("auto removed history dir [%s]", dir)
|
||||
//logging.LogInfof("auto removed history dir [%s]", dir)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ import (
|
|||
"github.com/88250/lute/parse"
|
||||
"github.com/88250/protyle"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/filesys"
|
||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||
|
|
@ -76,7 +77,7 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
|
|||
return
|
||||
}
|
||||
if 1 != len(unzipRootPaths) {
|
||||
util.LogErrorf("invalid .sy.zip")
|
||||
logging.LogErrorf("invalid .sy.zip")
|
||||
return errors.New("invalid .sy.zip")
|
||||
}
|
||||
unzipRootPath := unzipRootPaths[0]
|
||||
|
|
@ -88,13 +89,13 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
|
|||
for _, syPath := range syPaths {
|
||||
data, readErr := os.ReadFile(syPath)
|
||||
if nil != readErr {
|
||||
util.LogErrorf("read .sy [%s] failed: %s", syPath, readErr)
|
||||
logging.LogErrorf("read .sy [%s] failed: %s", syPath, readErr)
|
||||
err = readErr
|
||||
return
|
||||
}
|
||||
tree, _, parseErr := protyle.ParseJSON(luteEngine, data)
|
||||
if nil != parseErr {
|
||||
util.LogErrorf("parse .sy [%s] failed: %s", syPath, parseErr)
|
||||
logging.LogErrorf("parse .sy [%s] failed: %s", syPath, parseErr)
|
||||
err = parseErr
|
||||
return
|
||||
}
|
||||
|
|
@ -127,7 +128,7 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
|
|||
if "" != newDefID {
|
||||
n.Tokens = gulu.Str.ToBytes(newDefID)
|
||||
} else {
|
||||
util.LogWarnf("not found def [" + n.TokensStr() + "]")
|
||||
logging.LogWarnf("not found def [" + n.TokensStr() + "]")
|
||||
}
|
||||
} else if ast.NodeBlockQueryEmbedScript == n.Type {
|
||||
for oldID, newID := range blockIDs {
|
||||
|
|
@ -153,12 +154,12 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
|
|||
data = buf.Bytes()
|
||||
|
||||
if err = os.WriteFile(syPath, data, 0644); nil != err {
|
||||
util.LogErrorf("write .sy [%s] failed: %s", syPath, err)
|
||||
logging.LogErrorf("write .sy [%s] failed: %s", syPath, err)
|
||||
return
|
||||
}
|
||||
newSyPath := filepath.Join(filepath.Dir(syPath), tree.ID+".sy")
|
||||
if err = os.Rename(syPath, newSyPath); nil != err {
|
||||
util.LogErrorf("rename .sy from [%s] to [%s] failed: %s", syPath, newSyPath, err)
|
||||
logging.LogErrorf("rename .sy from [%s] to [%s] failed: %s", syPath, newSyPath, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -210,7 +211,7 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
|
|||
for i, oldPath := range oldPaths {
|
||||
newPath := renamePaths[oldPath]
|
||||
if err = os.Rename(oldPath, newPath); nil != err {
|
||||
util.LogErrorf("rename path from [%s] to [%s] failed: %s", oldPath, renamePaths[oldPath], err)
|
||||
logging.LogErrorf("rename path from [%s] to [%s] failed: %s", oldPath, renamePaths[oldPath], err)
|
||||
return errors.New("rename path failed")
|
||||
}
|
||||
|
||||
|
|
@ -249,7 +250,7 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
|
|||
if gulu.File.IsDir(assets) {
|
||||
dataAssets := filepath.Join(util.DataDir, "assets")
|
||||
if err = gulu.File.Copy(assets, dataAssets); nil != err {
|
||||
util.LogErrorf("copy assets from [%s] to [%s] failed: %s", assets, dataAssets, err)
|
||||
logging.LogErrorf("copy assets from [%s] to [%s] failed: %s", assets, dataAssets, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -267,7 +268,7 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
|
|||
} else {
|
||||
block := treenode.GetBlockTreeRootByPath(boxID, toPath)
|
||||
if nil == block {
|
||||
util.LogErrorf("not found block by path [%s]", toPath)
|
||||
logging.LogErrorf("not found block by path [%s]", toPath)
|
||||
return nil
|
||||
}
|
||||
baseTargetPath = strings.TrimSuffix(block.Path, ".sy")
|
||||
|
|
@ -279,7 +280,7 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
|
|||
}
|
||||
|
||||
if err = stableCopy(unzipRootPath, targetDir); nil != err {
|
||||
util.LogErrorf("copy data dir from [%s] to [%s] failed: %s", unzipRootPath, util.DataDir, err)
|
||||
logging.LogErrorf("copy data dir from [%s] to [%s] failed: %s", unzipRootPath, util.DataDir, err)
|
||||
err = errors.New("copy data failed")
|
||||
return
|
||||
}
|
||||
|
|
@ -305,7 +306,7 @@ func ImportData(zipPath string) (err error) {
|
|||
|
||||
files, err := filepath.Glob(filepath.Join(unzipPath, "*/*.sy"))
|
||||
if nil != err {
|
||||
util.LogErrorf("check data.zip failed: %s", err)
|
||||
logging.LogErrorf("check data.zip failed: %s", err)
|
||||
return errors.New("check data.zip failed")
|
||||
}
|
||||
if 0 < len(files) {
|
||||
|
|
@ -313,7 +314,7 @@ func ImportData(zipPath string) (err error) {
|
|||
}
|
||||
dirs, err := os.ReadDir(unzipPath)
|
||||
if nil != err {
|
||||
util.LogErrorf("check data.zip failed: %s", err)
|
||||
logging.LogErrorf("check data.zip failed: %s", err)
|
||||
return errors.New("check data.zip failed")
|
||||
}
|
||||
if 1 != len(dirs) {
|
||||
|
|
@ -326,7 +327,7 @@ func ImportData(zipPath string) (err error) {
|
|||
filelock.ReleaseAllFileLocks()
|
||||
tmpDataPath := filepath.Join(unzipPath, dirs[0].Name())
|
||||
if err = stableCopy(tmpDataPath, util.DataDir); nil != err {
|
||||
util.LogErrorf("copy data dir from [%s] to [%s] failed: %s", tmpDataPath, util.DataDir, err)
|
||||
logging.LogErrorf("copy data dir from [%s] to [%s] failed: %s", tmpDataPath, util.DataDir, err)
|
||||
err = errors.New("copy data failed")
|
||||
return
|
||||
}
|
||||
|
|
@ -350,7 +351,7 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
|
|||
} else {
|
||||
block := treenode.GetBlockTreeRootByPath(boxID, toPath)
|
||||
if nil == block {
|
||||
util.LogErrorf("not found block by path [%s]", toPath)
|
||||
logging.LogErrorf("not found block by path [%s]", toPath)
|
||||
return nil
|
||||
}
|
||||
baseHPath = block.HPath
|
||||
|
|
@ -436,7 +437,7 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
|
|||
|
||||
tree = parseKTree(data)
|
||||
if nil == tree {
|
||||
util.LogErrorf("parse tree [%s] failed", currentPath)
|
||||
logging.LogErrorf("parse tree [%s] failed", currentPath)
|
||||
return nil
|
||||
}
|
||||
tree.ID = id
|
||||
|
|
@ -476,7 +477,7 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
|
|||
name = util.AssetName(name)
|
||||
assetTargetPath := filepath.Join(assetDirPath, name)
|
||||
if err = gulu.File.Copy(fullPath, assetTargetPath); nil != err {
|
||||
util.LogErrorf("copy asset from [%s] to [%s] failed: %s", fullPath, assetTargetPath, err)
|
||||
logging.LogErrorf("copy asset from [%s] to [%s] failed: %s", fullPath, assetTargetPath, err)
|
||||
return ast.WalkContinue
|
||||
}
|
||||
assetsDone[absDest] = name
|
||||
|
|
@ -524,7 +525,7 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
|
|||
tree := parseKTree(data)
|
||||
if nil == tree {
|
||||
msg := fmt.Sprintf("parse tree [%s] failed", localPath)
|
||||
util.LogErrorf(msg)
|
||||
logging.LogErrorf(msg)
|
||||
return errors.New(msg)
|
||||
}
|
||||
tree.ID = id
|
||||
|
|
@ -563,7 +564,7 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
|
|||
name = util.AssetName(name)
|
||||
assetTargetPath := filepath.Join(assetDirPath, name)
|
||||
if err = gulu.File.CopyFile(absolutePath, assetTargetPath); nil != err {
|
||||
util.LogErrorf("copy asset from [%s] to [%s] failed: %s", absolutePath, assetTargetPath, err)
|
||||
logging.LogErrorf("copy asset from [%s] to [%s] failed: %s", absolutePath, assetTargetPath, err)
|
||||
return ast.WalkContinue
|
||||
}
|
||||
n.Tokens = gulu.Str.ToBytes("assets/" + name)
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ import (
|
|||
"github.com/dustin/go-humanize"
|
||||
"github.com/emirpasic/gods/sets/hashset"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/cache"
|
||||
"github.com/siyuan-note/siyuan/kernel/filesys"
|
||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||
|
|
@ -59,7 +60,7 @@ func (box *Box) BootIndex() {
|
|||
p := file.path
|
||||
tree, err := filesys.LoadTree(box.ID, p, luteEngine)
|
||||
if nil != err {
|
||||
util.LogErrorf("read box [%s] tree [%s] failed: %s", box.ID, p, err)
|
||||
logging.LogErrorf("read box [%s] tree [%s] failed: %s", box.ID, p, err)
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
@ -113,7 +114,7 @@ func (box *Box) Index(fullRebuildIndex bool) (treeCount int, treeSize int64) {
|
|||
|
||||
tree, err := filesys.LoadTree(box.ID, p, luteEngine)
|
||||
if nil != err {
|
||||
util.LogErrorf("read box [%s] tree [%s] failed: %s", box.ID, p, err)
|
||||
logging.LogErrorf("read box [%s] tree [%s] failed: %s", box.ID, p, err)
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
@ -155,7 +156,7 @@ func (box *Box) Index(fullRebuildIndex bool) (treeCount int, treeSize int64) {
|
|||
|
||||
dbBoxHash := sql.GetBoxHash(box.ID)
|
||||
if boxHash == dbBoxHash {
|
||||
//util.LogInfof("use existing database for box [%s]", box.ID)
|
||||
//logging.LogInfof("use existing database for box [%s]", box.ID)
|
||||
util.SetBootDetails("Use existing database for notebook " + box.ID)
|
||||
return
|
||||
}
|
||||
|
|
@ -194,7 +195,7 @@ func (box *Box) Index(fullRebuildIndex bool) (treeCount int, treeSize int64) {
|
|||
|
||||
tree, err := filesys.LoadTree(box.ID, file.path, luteEngine)
|
||||
if nil != err {
|
||||
util.LogErrorf("read box [%s] tree [%s] failed: %s", box.ID, file.path, err)
|
||||
logging.LogErrorf("read box [%s] tree [%s] failed: %s", box.ID, file.path, err)
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
@ -218,7 +219,7 @@ func (box *Box) Index(fullRebuildIndex bool) (treeCount int, treeSize int64) {
|
|||
|
||||
end := time.Now()
|
||||
elapsed := end.Sub(start).Seconds()
|
||||
util.LogInfof("rebuilt database for notebook [%s] in [%.2fs], tree [count=%d, size=%s]", box.ID, elapsed, treeCount, humanize.Bytes(uint64(treeSize)))
|
||||
logging.LogInfof("rebuilt database for notebook [%s] in [%.2fs], tree [count=%d, size=%s]", box.ID, elapsed, treeCount, humanize.Bytes(uint64(treeSize)))
|
||||
|
||||
util.PushEndlessProgress(fmt.Sprintf(Conf.Language(56), treeCount))
|
||||
return
|
||||
|
|
@ -286,12 +287,12 @@ func IndexRefs() {
|
|||
util.IncBootProgress(bootProgressPart, "Persisting block ref text "+util.ShortPathForBootingDisplay(dynamicRefTreeID))
|
||||
tree, err := loadTreeByBlockID(dynamicRefTreeID)
|
||||
if nil != err {
|
||||
util.LogErrorf("tree [%s] dynamic ref text to static failed: %s", dynamicRefTreeID, err)
|
||||
logging.LogErrorf("tree [%s] dynamic ref text to static failed: %s", dynamicRefTreeID, err)
|
||||
continue
|
||||
}
|
||||
legacyDynamicRefTreeToStatic(tree)
|
||||
if err := filesys.WriteTree(tree); nil == err {
|
||||
//util.LogInfof("persisted tree [%s] dynamic ref text", tree.Box+tree.Path)
|
||||
//logging.LogInfof("persisted tree [%s] dynamic ref text", tree.Box+tree.Path)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -335,7 +336,7 @@ func IndexRefs() {
|
|||
|
||||
tree, err := filesys.LoadTree(box.ID, file.path, luteEngine)
|
||||
if nil != err {
|
||||
util.LogErrorf("parse box [%s] tree [%s] failed", box.ID, file.path)
|
||||
logging.LogErrorf("parse box [%s] tree [%s] failed", box.ID, file.path)
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
@ -355,7 +356,7 @@ func IndexRefs() {
|
|||
}
|
||||
}
|
||||
}
|
||||
util.LogInfof("resolved refs [%d] in [%dms]", len(refBlocks), time.Now().Sub(start).Milliseconds())
|
||||
logging.LogInfof("resolved refs [%d] in [%dms]", len(refBlocks), time.Now().Sub(start).Milliseconds())
|
||||
}
|
||||
|
||||
func legacyDynamicRefTreeToStatic(tree *parse.Tree) {
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ import (
|
|||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/siyuan-note/httpclient"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/conf"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
|
@ -47,7 +48,7 @@ func StartFreeTrial() (err error) {
|
|||
SetCookies(&http.Cookie{Name: "symphony", Value: Conf.User.UserToken}).
|
||||
Post(util.AliyunServer + "/apis/siyuan/user/startFreeTrial")
|
||||
if nil != err {
|
||||
util.LogErrorf("start free trial failed: %s", err)
|
||||
logging.LogErrorf("start free trial failed: %s", err)
|
||||
return ErrFailedToConnectCloudServer
|
||||
}
|
||||
if 0 != requestResult.Code {
|
||||
|
|
@ -64,7 +65,7 @@ func DeactivateUser() (err error) {
|
|||
SetCookies(&http.Cookie{Name: "symphony", Value: Conf.User.UserToken}).
|
||||
Post(util.AliyunServer + "/apis/siyuan/user/deactivate")
|
||||
if nil != err {
|
||||
util.LogErrorf("deactivate user failed: %s", err)
|
||||
logging.LogErrorf("deactivate user failed: %s", err)
|
||||
return ErrFailedToConnectCloudServer
|
||||
}
|
||||
|
||||
|
|
@ -74,7 +75,7 @@ func DeactivateUser() (err error) {
|
|||
}
|
||||
|
||||
if 0 != requestResult.Code {
|
||||
util.LogErrorf("deactivate user failed: %s", requestResult.Msg)
|
||||
logging.LogErrorf("deactivate user failed: %s", requestResult.Msg)
|
||||
return errors.New(requestResult.Msg)
|
||||
}
|
||||
return
|
||||
|
|
@ -90,7 +91,7 @@ func SetCloudBlockReminder(id, data string, timed int64) (err error) {
|
|||
SetCookies(&http.Cookie{Name: "symphony", Value: Conf.User.UserToken}).
|
||||
Post(util.AliyunServer + "/apis/siyuan/calendar/setBlockReminder")
|
||||
if nil != err {
|
||||
util.LogErrorf("set block reminder failed: %s", err)
|
||||
logging.LogErrorf("set block reminder failed: %s", err)
|
||||
return ErrFailedToConnectCloudServer
|
||||
}
|
||||
|
||||
|
|
@ -100,7 +101,7 @@ func SetCloudBlockReminder(id, data string, timed int64) (err error) {
|
|||
}
|
||||
|
||||
if 0 != requestResult.Code {
|
||||
util.LogErrorf("set block reminder failed: %s", requestResult.Msg)
|
||||
logging.LogErrorf("set block reminder failed: %s", requestResult.Msg)
|
||||
return errors.New(requestResult.Msg)
|
||||
}
|
||||
return
|
||||
|
|
@ -122,7 +123,7 @@ func LoadUploadToken() (err error) {
|
|||
SetCookies(&http.Cookie{Name: "symphony", Value: Conf.User.UserToken}).
|
||||
Post(util.AliyunServer + "/apis/siyuan/upload/token")
|
||||
if nil != err {
|
||||
util.LogErrorf("get upload token failed: %s", err)
|
||||
logging.LogErrorf("get upload token failed: %s", err)
|
||||
return ErrFailedToConnectCloudServer
|
||||
}
|
||||
|
||||
|
|
@ -132,7 +133,7 @@ func LoadUploadToken() (err error) {
|
|||
}
|
||||
|
||||
if 0 != requestResult.Code {
|
||||
util.LogErrorf("get upload token failed: %s", requestResult.Msg)
|
||||
logging.LogErrorf("get upload token failed: %s", requestResult.Msg)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -152,7 +153,7 @@ func AutoRefreshUser() {
|
|||
if !subscriptionExpirationReminded {
|
||||
subscriptionExpirationReminded = true
|
||||
go func() {
|
||||
defer util.Recover()
|
||||
defer logging.Recover()
|
||||
|
||||
if "ios" == util.Container {
|
||||
return
|
||||
|
|
@ -175,7 +176,7 @@ func AutoRefreshUser() {
|
|||
}
|
||||
|
||||
go func() {
|
||||
defer util.Recover()
|
||||
defer logging.Recover()
|
||||
|
||||
if nil != Conf.User {
|
||||
time.Sleep(2 * time.Minute)
|
||||
|
|
@ -187,7 +188,7 @@ func AutoRefreshUser() {
|
|||
}()
|
||||
|
||||
go func() {
|
||||
defer util.Recover()
|
||||
defer logging.Recover()
|
||||
|
||||
time.Sleep(1 * time.Minute)
|
||||
announcementConf := filepath.Join(util.HomeDir, ".config", "siyuan", "announcement.json")
|
||||
|
|
@ -195,11 +196,11 @@ func AutoRefreshUser() {
|
|||
if gulu.File.IsExist(announcementConf) {
|
||||
data, err := os.ReadFile(announcementConf)
|
||||
if nil != err {
|
||||
util.LogErrorf("read announcement conf failed: %s", err)
|
||||
logging.LogErrorf("read announcement conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &existingAnnouncements); nil != err {
|
||||
util.LogErrorf("unmarshal announcement conf failed: %s", err)
|
||||
logging.LogErrorf("unmarshal announcement conf failed: %s", err)
|
||||
os.Remove(announcementConf)
|
||||
return
|
||||
}
|
||||
|
|
@ -221,11 +222,11 @@ func AutoRefreshUser() {
|
|||
|
||||
data, err := gulu.JSON.MarshalJSON(existingAnnouncements)
|
||||
if nil != err {
|
||||
util.LogErrorf("marshal announcement conf failed: %s", err)
|
||||
logging.LogErrorf("marshal announcement conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
if err = os.WriteFile(announcementConf, data, 0644); nil != err {
|
||||
util.LogErrorf("write announcement conf failed: %s", err)
|
||||
logging.LogErrorf("write announcement conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -251,7 +252,7 @@ func RefreshUser(token string) error {
|
|||
var tokenExpireTime int64
|
||||
tokenExpireTime, err := strconv.ParseInt(Conf.User.UserTokenExpireTime+"000", 10, 64)
|
||||
if nil != err {
|
||||
util.LogErrorf("convert token expire time [%s] failed: %s", Conf.User.UserTokenExpireTime, err)
|
||||
logging.LogErrorf("convert token expire time [%s] failed: %s", Conf.User.UserTokenExpireTime, err)
|
||||
return errors.New(Conf.Language(19))
|
||||
}
|
||||
|
||||
|
|
@ -273,7 +274,7 @@ Net:
|
|||
var tokenExpireTime int64
|
||||
tokenExpireTime, err = strconv.ParseInt(Conf.User.UserTokenExpireTime+"000", 10, 64)
|
||||
if nil != err {
|
||||
util.LogErrorf("convert token expire time [%s] failed: %s", Conf.User.UserTokenExpireTime, err)
|
||||
logging.LogErrorf("convert token expire time [%s] failed: %s", Conf.User.UserTokenExpireTime, err)
|
||||
return errors.New(Conf.Language(19))
|
||||
}
|
||||
|
||||
|
|
@ -289,7 +290,7 @@ Net:
|
|||
Conf.Save()
|
||||
|
||||
if elapsed := time.Now().Sub(start).Milliseconds(); 3000 < elapsed {
|
||||
util.LogInfof("get cloud user elapsed [%dms]", elapsed)
|
||||
logging.LogInfof("get cloud user elapsed [%dms]", elapsed)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
@ -320,7 +321,7 @@ func RemoveCloudShorthands(ids []string) (err error) {
|
|||
SetBody(body).
|
||||
Post(util.AliyunServer + "/apis/siyuan/inbox/removeCloudShorthands")
|
||||
if nil != err {
|
||||
util.LogErrorf("remove cloud shorthands failed: %s", err)
|
||||
logging.LogErrorf("remove cloud shorthands failed: %s", err)
|
||||
err = ErrFailedToConnectCloudServer
|
||||
return
|
||||
}
|
||||
|
|
@ -332,7 +333,7 @@ func RemoveCloudShorthands(ids []string) (err error) {
|
|||
|
||||
code := result["code"].(float64)
|
||||
if 0 != code {
|
||||
util.LogErrorf("remove cloud shorthands failed: %s", result["msg"])
|
||||
logging.LogErrorf("remove cloud shorthands failed: %s", result["msg"])
|
||||
err = errors.New(result["msg"].(string))
|
||||
return
|
||||
}
|
||||
|
|
@ -347,7 +348,7 @@ func GetCloudShorthands(page int) (result map[string]interface{}, err error) {
|
|||
SetCookies(&http.Cookie{Name: "symphony", Value: Conf.User.UserToken}).
|
||||
Post(util.AliyunServer + "/apis/siyuan/inbox/getCloudShorthands?p=" + strconv.Itoa(page))
|
||||
if nil != err {
|
||||
util.LogErrorf("get cloud shorthands failed: %s", err)
|
||||
logging.LogErrorf("get cloud shorthands failed: %s", err)
|
||||
err = ErrFailedToConnectCloudServer
|
||||
return
|
||||
}
|
||||
|
|
@ -359,7 +360,7 @@ func GetCloudShorthands(page int) (result map[string]interface{}, err error) {
|
|||
|
||||
code := result["code"].(float64)
|
||||
if 0 != code {
|
||||
util.LogErrorf("get cloud shorthands failed: %s", result["msg"])
|
||||
logging.LogErrorf("get cloud shorthands failed: %s", result["msg"])
|
||||
err = errors.New(result["msg"].(string))
|
||||
return
|
||||
}
|
||||
|
|
@ -384,7 +385,7 @@ func getUser(token string) (*conf.User, error) {
|
|||
SetBody(map[string]string{"token": token}).
|
||||
Post(util.AliyunServer + "/apis/siyuan/user")
|
||||
if nil != err {
|
||||
util.LogErrorf("get community user failed: %s", err)
|
||||
logging.LogErrorf("get community user failed: %s", err)
|
||||
return nil, errors.New(Conf.Language(18))
|
||||
}
|
||||
|
||||
|
|
@ -393,7 +394,7 @@ func getUser(token string) (*conf.User, error) {
|
|||
if 255 == code {
|
||||
return nil, errInvalidUser
|
||||
}
|
||||
util.LogErrorf("get community user failed: %s", result["msg"])
|
||||
logging.LogErrorf("get community user failed: %s", result["msg"])
|
||||
return nil, errors.New(Conf.Language(18))
|
||||
}
|
||||
|
||||
|
|
@ -401,7 +402,7 @@ func getUser(token string) (*conf.User, error) {
|
|||
data := util.AESDecrypt(dataStr)
|
||||
user := &conf.User{}
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &user); nil != err {
|
||||
util.LogErrorf("get community user failed: %s", err)
|
||||
logging.LogErrorf("get community user failed: %s", err)
|
||||
return nil, errors.New(Conf.Language(18))
|
||||
}
|
||||
return user, nil
|
||||
|
|
@ -418,7 +419,7 @@ func UseActivationcode(code string) (err error) {
|
|||
SetCookies(&http.Cookie{Name: "symphony", Value: Conf.User.UserToken}).
|
||||
Post(util.AliyunServer + "/apis/siyuan/useActivationcode")
|
||||
if nil != err {
|
||||
util.LogErrorf("check activation code failed: %s", err)
|
||||
logging.LogErrorf("check activation code failed: %s", err)
|
||||
return ErrFailedToConnectCloudServer
|
||||
}
|
||||
if 0 != requestResult.Code {
|
||||
|
|
@ -439,7 +440,7 @@ func CheckActivationcode(code string) (retCode int, msg string) {
|
|||
SetCookies(&http.Cookie{Name: "symphony", Value: Conf.User.UserToken}).
|
||||
Post(util.AliyunServer + "/apis/siyuan/checkActivationcode")
|
||||
if nil != err {
|
||||
util.LogErrorf("check activation code failed: %s", err)
|
||||
logging.LogErrorf("check activation code failed: %s", err)
|
||||
msg = ErrFailedToConnectCloudServer.Error()
|
||||
return
|
||||
}
|
||||
|
|
@ -458,7 +459,7 @@ func Login(userName, password, captcha string) (ret *gulu.Result, err error) {
|
|||
SetBody(map[string]string{"userName": userName, "userPassword": password, "captcha": captcha}).
|
||||
Post(util.AliyunServer + "/apis/siyuan/login")
|
||||
if nil != err {
|
||||
util.LogErrorf("login failed: %s", err)
|
||||
logging.LogErrorf("login failed: %s", err)
|
||||
return nil, errors.New(Conf.Language(18))
|
||||
}
|
||||
ret = &gulu.Result{
|
||||
|
|
@ -485,7 +486,7 @@ func Login2fa(token, code string) (map[string]interface{}, error) {
|
|||
SetHeader("token", token).
|
||||
Post(util.AliyunServer + "/apis/siyuan/login/2fa")
|
||||
if nil != err {
|
||||
util.LogErrorf("login 2fa failed: %s", err)
|
||||
logging.LogErrorf("login 2fa failed: %s", err)
|
||||
return nil, errors.New(Conf.Language(18))
|
||||
}
|
||||
return result, nil
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import (
|
|||
"github.com/88250/gulu"
|
||||
"github.com/88250/lute/ast"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
|
@ -92,13 +93,13 @@ func RemoveBox(boxID string) (err error) {
|
|||
var historyDir string
|
||||
historyDir, err = util.GetHistoryDir("delete")
|
||||
if nil != err {
|
||||
util.LogErrorf("get history dir failed: %s", err)
|
||||
logging.LogErrorf("get history dir failed: %s", err)
|
||||
return
|
||||
}
|
||||
p := strings.TrimPrefix(localPath, util.DataDir)
|
||||
historyPath := filepath.Join(historyDir, p)
|
||||
if err = gulu.File.Copy(localPath, historyPath); nil != err {
|
||||
util.LogErrorf("gen sync history failed: %s", err)
|
||||
logging.LogErrorf("gen sync history failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import (
|
|||
|
||||
"github.com/88250/gulu"
|
||||
"github.com/88250/lute/ast"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/search"
|
||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||
|
|
@ -65,7 +66,7 @@ func createDocsByHPath(boxID, hPath, content string) (id string, err error) {
|
|||
if isNotLast {
|
||||
dirPath := filepath.Join(util.DataDir, boxID, pathBuilder.String())
|
||||
if err = os.MkdirAll(dirPath, 0755); nil != err {
|
||||
util.LogErrorf("mkdir [%s] failed: %s", dirPath, err)
|
||||
logging.LogErrorf("mkdir [%s] failed: %s", dirPath, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ import (
|
|||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
|
|
@ -32,7 +33,7 @@ func HookResident() {
|
|||
|
||||
for range time.Tick(time.Second * 30) {
|
||||
if 0 == util.CountSessions() {
|
||||
util.LogInfof("no active session, exit kernel process now")
|
||||
logging.LogInfof("no active session, exit kernel process now")
|
||||
Close(false)
|
||||
}
|
||||
}
|
||||
|
|
@ -42,6 +43,6 @@ func HandleSignal() {
|
|||
c := make(chan os.Signal)
|
||||
signal.Notify(c, syscall.SIGINT, syscall.SIGQUIT, syscall.SIGTERM)
|
||||
s := <-c
|
||||
util.LogInfof("received os signal [%s], exit kernel process now", s)
|
||||
logging.LogInfof("received os signal [%s], exit kernel process now", s)
|
||||
Close(false)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,6 +34,7 @@ import (
|
|||
"github.com/siyuan-note/eventbus"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/httpclient"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/cache"
|
||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
|
|
@ -62,7 +63,7 @@ func GetRepoSnapshots(page int) (logs []*dejavu.Log, pageCount, totalCount int,
|
|||
return
|
||||
}
|
||||
|
||||
util.LogErrorf("get data repo index logs failed: %s", err)
|
||||
logging.LogErrorf("get data repo index logs failed: %s", err)
|
||||
return
|
||||
}
|
||||
return
|
||||
|
|
@ -80,7 +81,7 @@ func ImportRepoKey(base64Key string) (err error) {
|
|||
|
||||
key, err := base64.StdEncoding.DecodeString(base64Key)
|
||||
if nil != err {
|
||||
util.LogErrorf("import data repo key failed: %s", err)
|
||||
logging.LogErrorf("import data repo key failed: %s", err)
|
||||
return errors.New(Conf.Language(157))
|
||||
}
|
||||
if 32 != len(key) {
|
||||
|
|
@ -142,14 +143,14 @@ func InitRepoKey() (err error) {
|
|||
randomBytes = make([]byte, 16)
|
||||
_, err = rand.Read(randomBytes)
|
||||
if nil != err {
|
||||
util.LogErrorf("init data repo key failed: %s", err)
|
||||
logging.LogErrorf("init data repo key failed: %s", err)
|
||||
return
|
||||
}
|
||||
salt := string(randomBytes)
|
||||
|
||||
key, err := encryption.KDF(password, salt)
|
||||
if nil != err {
|
||||
util.LogErrorf("init data repo key failed: %s", err)
|
||||
logging.LogErrorf("init data repo key failed: %s", err)
|
||||
return
|
||||
}
|
||||
Conf.Repo.Key = key
|
||||
|
|
@ -447,7 +448,7 @@ func syncRepo(boot, exit, byHand bool) {
|
|||
planSyncAfter(fixSyncInterval)
|
||||
|
||||
msg := fmt.Sprintf("sync repo failed: %s", err)
|
||||
util.LogErrorf(msg)
|
||||
logging.LogErrorf(msg)
|
||||
util.PushStatusBar(msg)
|
||||
util.PushErrMsg(msg, 0)
|
||||
return
|
||||
|
|
@ -473,7 +474,7 @@ func syncRepo(boot, exit, byHand bool) {
|
|||
syncDownloadErrCount++
|
||||
planSyncAfter(fixSyncInterval)
|
||||
|
||||
util.LogErrorf("sync data repo failed: %s", err)
|
||||
logging.LogErrorf("sync data repo failed: %s", err)
|
||||
msg := fmt.Sprintf(Conf.Language(80), formatErrorMsg(err))
|
||||
if errors.Is(err, dejavu.ErrCloudStorageSizeExceeded) {
|
||||
msg = fmt.Sprintf(Conf.Language(43), humanize.Bytes(uint64(Conf.User.UserSiYuanRepoSize)))
|
||||
|
|
@ -542,7 +543,7 @@ func indexRepoBeforeCloudSync(repo *dejavu.Repo) (err error) {
|
|||
msg := fmt.Sprintf(Conf.Language(140), err)
|
||||
util.PushStatusBar(msg)
|
||||
util.PushErrMsg(msg, 5000)
|
||||
util.LogErrorf("index data repo before cloud sync failed: %s", err)
|
||||
logging.LogErrorf("index data repo before cloud sync failed: %s", err)
|
||||
return
|
||||
}
|
||||
elapsed := time.Since(start)
|
||||
|
|
@ -552,7 +553,7 @@ func indexRepoBeforeCloudSync(repo *dejavu.Repo) (err error) {
|
|||
index.Memo = fmt.Sprintf("[Sync] Cloud sync, completed in %.2fs", elapsed.Seconds())
|
||||
if err = repo.PutIndex(index); nil != err {
|
||||
util.PushStatusBar("Save data snapshot for cloud sync failed")
|
||||
util.LogErrorf("put index into data repo before cloud sync failed: %s", err)
|
||||
logging.LogErrorf("put index into data repo before cloud sync failed: %s", err)
|
||||
return
|
||||
}
|
||||
util.PushStatusBar(fmt.Sprintf(Conf.Language(147), elapsed.Seconds()))
|
||||
|
|
@ -561,7 +562,7 @@ func indexRepoBeforeCloudSync(repo *dejavu.Repo) (err error) {
|
|||
}
|
||||
|
||||
if 7000 < elapsed.Milliseconds() {
|
||||
util.LogWarnf("index data repo before cloud sync elapsed [%dms]", elapsed.Milliseconds())
|
||||
logging.LogWarnf("index data repo before cloud sync elapsed [%dms]", elapsed.Milliseconds())
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
@ -571,7 +572,7 @@ func newRepository() (ret *dejavu.Repo, err error) {
|
|||
ignoreLines = append(ignoreLines, "/.siyuan/conf.json") // 忽略旧版同步配置
|
||||
ret, err = dejavu.NewRepo(util.DataDir, util.RepoDir, util.HistoryDir, util.TempDir, Conf.Repo.Key, ignoreLines)
|
||||
if nil != err {
|
||||
util.LogErrorf("init data repo failed: %s", err)
|
||||
logging.LogErrorf("init data repo failed: %s", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
|
@ -738,7 +739,7 @@ func contextPushMsg(context map[string]interface{}, msg string) {
|
|||
|
||||
func buildCloudInfo() (ret *dejavu.CloudInfo, err error) {
|
||||
if !IsValidCloudDirName(Conf.Sync.CloudName) {
|
||||
util.LogWarnf("invalid cloud repo name, rename it to [main]")
|
||||
logging.LogWarnf("invalid cloud repo name, rename it to [main]")
|
||||
Conf.Sync.CloudName = "main"
|
||||
Conf.Save()
|
||||
}
|
||||
|
|
@ -816,7 +817,7 @@ func getCloudSpaceOSS() (sync, backup map[string]interface{}, assetSize int64, e
|
|||
Post(util.AliyunServer + "/apis/siyuan/dejavu/getRepoStat?uid=" + Conf.User.UserId)
|
||||
|
||||
if nil != err {
|
||||
util.LogErrorf("get cloud space failed: %s", err)
|
||||
logging.LogErrorf("get cloud space failed: %s", err)
|
||||
err = ErrFailedToConnectCloudServer
|
||||
return
|
||||
}
|
||||
|
|
@ -828,7 +829,7 @@ func getCloudSpaceOSS() (sync, backup map[string]interface{}, assetSize int64, e
|
|||
|
||||
code := result["code"].(float64)
|
||||
if 0 != code {
|
||||
util.LogErrorf("get cloud space failed: %s", result["msg"])
|
||||
logging.LogErrorf("get cloud space failed: %s", result["msg"])
|
||||
err = errors.New(result["msg"].(string))
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import (
|
|||
"github.com/88250/lute/ast"
|
||||
"github.com/88250/lute/parse"
|
||||
"github.com/jinzhu/copier"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/conf"
|
||||
"github.com/siyuan-note/siyuan/kernel/search"
|
||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||
|
|
@ -201,7 +202,7 @@ func FullTextSearchBlock(query, box, path string, types map[string]bool, querySy
|
|||
func searchFilter(types map[string]bool) string {
|
||||
s := conf.NewSearch()
|
||||
if err := copier.Copy(s, Conf.Search); nil != err {
|
||||
util.LogErrorf("copy search conf failed: %s", err)
|
||||
logging.LogErrorf("copy search conf failed: %s", err)
|
||||
}
|
||||
if nil != types {
|
||||
s.Document = types["document"]
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ import (
|
|||
"github.com/88250/gulu"
|
||||
ginSessions "github.com/gin-contrib/sessions"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
"github.com/steambap/captcha"
|
||||
)
|
||||
|
|
@ -45,7 +46,7 @@ func LogoutAuth(c *gin.Context) {
|
|||
})
|
||||
session.Clear()
|
||||
if err := session.Save(); nil != err {
|
||||
util.LogErrorf("saves session failed: " + err.Error())
|
||||
logging.LogErrorf("saves session failed: " + err.Error())
|
||||
ret.Code = -1
|
||||
ret.Msg = "save session failed"
|
||||
}
|
||||
|
|
@ -90,7 +91,7 @@ func LoginAuth(c *gin.Context) {
|
|||
}
|
||||
|
||||
if err := session.Save(c); nil != err {
|
||||
util.LogErrorf("save session failed: " + err.Error())
|
||||
logging.LogErrorf("save session failed: " + err.Error())
|
||||
c.Status(500)
|
||||
return
|
||||
}
|
||||
|
|
@ -101,7 +102,7 @@ func LoginAuth(c *gin.Context) {
|
|||
session.WrongAuthCount = 0
|
||||
session.Captcha = gulu.Rand.String(7)
|
||||
if err := session.Save(c); nil != err {
|
||||
util.LogErrorf("save session failed: " + err.Error())
|
||||
logging.LogErrorf("save session failed: " + err.Error())
|
||||
c.Status(500)
|
||||
return
|
||||
}
|
||||
|
|
@ -114,7 +115,7 @@ func GetCaptcha(c *gin.Context) {
|
|||
options.CurveNumber = 0
|
||||
})
|
||||
if nil != err {
|
||||
util.LogErrorf("generates captcha failed: " + err.Error())
|
||||
logging.LogErrorf("generates captcha failed: " + err.Error())
|
||||
c.Status(500)
|
||||
return
|
||||
}
|
||||
|
|
@ -122,13 +123,13 @@ func GetCaptcha(c *gin.Context) {
|
|||
session := util.GetSession(c)
|
||||
session.Captcha = img.Text
|
||||
if err = session.Save(c); nil != err {
|
||||
util.LogErrorf("save session failed: " + err.Error())
|
||||
logging.LogErrorf("save session failed: " + err.Error())
|
||||
c.Status(500)
|
||||
return
|
||||
}
|
||||
|
||||
if err = img.WriteImage(c.Writer); nil != err {
|
||||
util.LogErrorf("writes captcha image failed: " + err.Error())
|
||||
logging.LogErrorf("writes captcha image failed: " + err.Error())
|
||||
c.Status(500)
|
||||
return
|
||||
}
|
||||
|
|
@ -148,7 +149,7 @@ func CheckReadonly(c *gin.Context) {
|
|||
}
|
||||
|
||||
func CheckAuth(c *gin.Context) {
|
||||
//util.LogInfof("check auth for [%s]", c.Request.RequestURI)
|
||||
//logging.LogInfof("check auth for [%s]", c.Request.RequestURI)
|
||||
|
||||
// 放过 /appearance/
|
||||
if strings.HasPrefix(c.Request.RequestURI, "/appearance/") ||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import (
|
|||
"github.com/88250/gulu"
|
||||
"github.com/dustin/go-humanize"
|
||||
"github.com/siyuan-note/dejavu"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
|
|
@ -55,14 +56,14 @@ func AutoSync() {
|
|||
}
|
||||
|
||||
func SyncData(boot, exit, byHand bool) {
|
||||
defer util.Recover()
|
||||
defer logging.Recover()
|
||||
|
||||
if !boot && !exit && 2 == Conf.Sync.Mode && !byHand {
|
||||
return
|
||||
}
|
||||
|
||||
if util.IsMutexLocked(&syncLock) {
|
||||
util.LogWarnf("sync is in progress")
|
||||
logging.LogWarnf("sync is in progress")
|
||||
planSyncAfter(30 * time.Second)
|
||||
return
|
||||
}
|
||||
|
|
@ -90,15 +91,15 @@ func SyncData(boot, exit, byHand bool) {
|
|||
}
|
||||
|
||||
if boot {
|
||||
util.LogInfof("sync before boot")
|
||||
logging.LogInfof("sync before boot")
|
||||
}
|
||||
if exit {
|
||||
util.LogInfof("sync before exit")
|
||||
logging.LogInfof("sync before exit")
|
||||
util.PushMsg(Conf.Language(81), 1000*60*15)
|
||||
}
|
||||
|
||||
if 7 < syncDownloadErrCount && !byHand {
|
||||
util.LogErrorf("sync download error too many times, cancel auto sync, try to sync by hand")
|
||||
logging.LogErrorf("sync download error too many times, cancel auto sync, try to sync by hand")
|
||||
util.PushErrMsg(Conf.Language(125), 1000*60*60)
|
||||
planSyncAfter(64 * time.Minute)
|
||||
return
|
||||
|
|
@ -329,13 +330,13 @@ func getIgnoreLines() (ret []string) {
|
|||
}
|
||||
if !gulu.File.IsExist(ignore) {
|
||||
if err = gulu.File.WriteFileSafer(ignore, nil, 0644); nil != err {
|
||||
util.LogErrorf("create syncignore [%s] failed: %s", ignore, err)
|
||||
logging.LogErrorf("create syncignore [%s] failed: %s", ignore, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
data, err := os.ReadFile(ignore)
|
||||
if nil != err {
|
||||
util.LogErrorf("read syncignore [%s] failed: %s", ignore, err)
|
||||
logging.LogErrorf("read syncignore [%s] failed: %s", ignore, err)
|
||||
return
|
||||
}
|
||||
dataStr := string(data)
|
||||
|
|
@ -383,7 +384,7 @@ func stableCopy(src, dest string) (err error) {
|
|||
strings.Contains(err.Error(), "exit status 7") {
|
||||
return nil
|
||||
}
|
||||
util.LogErrorf("robocopy data from [%s] to [%s] failed: %s %s", src, dest, string(output), err)
|
||||
logging.LogErrorf("robocopy data from [%s] to [%s] failed: %s %s", src, dest, string(output), err)
|
||||
}
|
||||
return gulu.File.Copy(src, dest)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import (
|
|||
"github.com/88250/lute/render"
|
||||
"github.com/88250/protyle"
|
||||
"github.com/araddon/dateparse"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
|
||||
|
|
@ -167,7 +168,7 @@ func renderTemplate(p, id string) (string, error) {
|
|||
now := time.Now()
|
||||
ret, err := dateparse.ParseIn(dateStr, now.Location())
|
||||
if nil != err {
|
||||
util.LogWarnf("parse date [%s] failed [%s], return current time instead", dateStr, err)
|
||||
logging.LogWarnf("parse date [%s] failed [%s], return current time instead", dateStr, err)
|
||||
return now
|
||||
}
|
||||
return ret
|
||||
|
|
@ -188,7 +189,7 @@ func renderTemplate(p, id string) (string, error) {
|
|||
tree = parseKTree(md)
|
||||
if nil == tree {
|
||||
msg := fmt.Sprintf("parse tree [%s] failed", p)
|
||||
util.LogErrorf(msg)
|
||||
logging.LogErrorf(msg)
|
||||
return "", errors.New(msg)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@ import (
|
|||
util2 "github.com/88250/lute/util"
|
||||
"github.com/emirpasic/gods/sets/hashset"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/cache"
|
||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||
|
|
@ -88,11 +89,11 @@ func WaitForWritingFiles() {
|
|||
for i := 0; isWritingFiles(); i++ {
|
||||
time.Sleep(5 * time.Millisecond)
|
||||
if 2000 < i && !printLog { // 10s 后打日志
|
||||
util.LogWarnf("file is writing: \n%s", util.ShortStack())
|
||||
logging.LogWarnf("file is writing: \n%s", logging.ShortStack())
|
||||
printLog = true
|
||||
}
|
||||
if 12000 < i && !lastPrintLog { // 60s 后打日志
|
||||
util.LogWarnf("file is still writing")
|
||||
logging.LogWarnf("file is still writing")
|
||||
lastPrintLog = true
|
||||
}
|
||||
}
|
||||
|
|
@ -116,7 +117,7 @@ func AutoFlushTx() {
|
|||
func flushTx() {
|
||||
writingDataLock.Lock()
|
||||
defer writingDataLock.Unlock()
|
||||
defer util.Recover()
|
||||
defer logging.Recover()
|
||||
|
||||
currentTx = mergeTx()
|
||||
start := time.Now()
|
||||
|
|
@ -129,13 +130,13 @@ func flushTx() {
|
|||
util.PushTxErr(Conf.Language(76), txErr.code, txErr.id)
|
||||
return
|
||||
default:
|
||||
util.LogFatalf("transaction failed: %s", txErr.msg)
|
||||
logging.LogFatalf("transaction failed: %s", txErr.msg)
|
||||
}
|
||||
}
|
||||
elapsed := time.Now().Sub(start).Milliseconds()
|
||||
if 0 < len(currentTx.DoOperations) {
|
||||
if 2000 < elapsed {
|
||||
util.LogWarnf("tx [%dms]", elapsed)
|
||||
logging.LogWarnf("tx [%dms]", elapsed)
|
||||
}
|
||||
}
|
||||
currentTx = nil
|
||||
|
|
@ -214,7 +215,7 @@ func performTx(tx *Transaction) (ret *TxErr) {
|
|||
if strings.Contains(err.Error(), "database is closed") {
|
||||
return
|
||||
}
|
||||
util.LogErrorf("begin tx failed: %s", err)
|
||||
logging.LogErrorf("begin tx failed: %s", err)
|
||||
ret = &TxErr{msg: err.Error()}
|
||||
return
|
||||
}
|
||||
|
|
@ -225,7 +226,7 @@ func performTx(tx *Transaction) (ret *TxErr) {
|
|||
return
|
||||
}
|
||||
if cr := tx.commit(); nil != cr {
|
||||
util.LogErrorf("commit tx failed: %s", cr)
|
||||
logging.LogErrorf("commit tx failed: %s", cr)
|
||||
return &TxErr{msg: cr.Error()}
|
||||
}
|
||||
return
|
||||
|
|
@ -263,7 +264,7 @@ func performTx(tx *Transaction) (ret *TxErr) {
|
|||
}
|
||||
|
||||
if cr := tx.commit(); nil != cr {
|
||||
util.LogErrorf("commit tx failed: %s", cr)
|
||||
logging.LogErrorf("commit tx failed: %s", cr)
|
||||
return &TxErr{msg: cr.Error()}
|
||||
}
|
||||
elapsed := int(time.Now().Sub(start).Milliseconds())
|
||||
|
|
@ -279,13 +280,13 @@ func (tx *Transaction) doMove(operation *Operation) (ret *TxErr) {
|
|||
id := operation.ID
|
||||
srcTree, err := tx.loadTree(id)
|
||||
if nil != err {
|
||||
util.LogErrorf("load tree [id=%s] failed: %s", id, err)
|
||||
logging.LogErrorf("load tree [id=%s] failed: %s", id, err)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: id}
|
||||
}
|
||||
|
||||
srcNode := treenode.GetNodeInTree(srcTree, id)
|
||||
if nil == srcNode {
|
||||
util.LogErrorf("get node [%s] in tree [%s] failed", id, srcTree.Root.ID)
|
||||
logging.LogErrorf("get node [%s] in tree [%s] failed", id, srcTree.Root.ID)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: id}
|
||||
}
|
||||
|
||||
|
|
@ -309,7 +310,7 @@ func (tx *Transaction) doMove(operation *Operation) (ret *TxErr) {
|
|||
var targetTree *parse.Tree
|
||||
targetTree, err = tx.loadTree(targetPreviousID)
|
||||
if nil != err {
|
||||
util.LogErrorf("load tree [id=%s] failed: %s", targetPreviousID, err)
|
||||
logging.LogErrorf("load tree [id=%s] failed: %s", targetPreviousID, err)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: targetPreviousID}
|
||||
}
|
||||
isSameTree := srcTree.ID == targetTree.ID
|
||||
|
|
@ -319,7 +320,7 @@ func (tx *Transaction) doMove(operation *Operation) (ret *TxErr) {
|
|||
|
||||
targetNode := treenode.GetNodeInTree(targetTree, targetPreviousID)
|
||||
if nil == targetNode {
|
||||
util.LogErrorf("get node [%s] in tree [%s] failed", targetPreviousID, targetTree.Root.ID)
|
||||
logging.LogErrorf("get node [%s] in tree [%s] failed", targetPreviousID, targetTree.Root.ID)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: targetPreviousID}
|
||||
}
|
||||
|
||||
|
|
@ -357,7 +358,7 @@ func (tx *Transaction) doMove(operation *Operation) (ret *TxErr) {
|
|||
|
||||
targetTree, err := tx.loadTree(targetParentID)
|
||||
if nil != err {
|
||||
util.LogErrorf("load tree [id=%s] failed: %s", targetParentID, err)
|
||||
logging.LogErrorf("load tree [id=%s] failed: %s", targetParentID, err)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: targetParentID}
|
||||
}
|
||||
isSameTree := srcTree.ID == targetTree.ID
|
||||
|
|
@ -367,7 +368,7 @@ func (tx *Transaction) doMove(operation *Operation) (ret *TxErr) {
|
|||
|
||||
targetNode := treenode.GetNodeInTree(targetTree, targetParentID)
|
||||
if nil == targetNode {
|
||||
util.LogErrorf("get node [%s] in tree [%s] failed", targetParentID, targetTree.Root.ID)
|
||||
logging.LogErrorf("get node [%s] in tree [%s] failed", targetParentID, targetTree.Root.ID)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: targetParentID}
|
||||
}
|
||||
|
||||
|
|
@ -430,7 +431,7 @@ func (tx *Transaction) doPrependInsert(operation *Operation) (ret *TxErr) {
|
|||
block := treenode.GetBlockTree(operation.ParentID)
|
||||
if nil == block {
|
||||
msg := fmt.Sprintf("not found parent block [id=%s]", operation.ParentID)
|
||||
util.LogErrorf(msg)
|
||||
logging.LogErrorf(msg)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: operation.ParentID}
|
||||
}
|
||||
tree, err := tx.loadTree(block.ID)
|
||||
|
|
@ -439,7 +440,7 @@ func (tx *Transaction) doPrependInsert(operation *Operation) (ret *TxErr) {
|
|||
}
|
||||
if nil != err {
|
||||
msg := fmt.Sprintf("load tree [id=%s] failed: %s", block.ID, err)
|
||||
util.LogErrorf(msg)
|
||||
logging.LogErrorf(msg)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: block.ID}
|
||||
}
|
||||
|
||||
|
|
@ -467,7 +468,7 @@ func (tx *Transaction) doPrependInsert(operation *Operation) (ret *TxErr) {
|
|||
|
||||
node := treenode.GetNodeInTree(tree, operation.ParentID)
|
||||
if nil == node {
|
||||
util.LogErrorf("get node [%s] in tree [%s] failed", operation.ParentID, tree.Root.ID)
|
||||
logging.LogErrorf("get node [%s] in tree [%s] failed", operation.ParentID, tree.Root.ID)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: operation.ParentID}
|
||||
}
|
||||
isContainer := node.IsContainerBlock()
|
||||
|
|
@ -518,7 +519,7 @@ func (tx *Transaction) doAppendInsert(operation *Operation) (ret *TxErr) {
|
|||
block := treenode.GetBlockTree(operation.ParentID)
|
||||
if nil == block {
|
||||
msg := fmt.Sprintf("not found parent block [id=%s]", operation.ParentID)
|
||||
util.LogErrorf(msg)
|
||||
logging.LogErrorf(msg)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: operation.ParentID}
|
||||
}
|
||||
tree, err := tx.loadTree(block.ID)
|
||||
|
|
@ -527,7 +528,7 @@ func (tx *Transaction) doAppendInsert(operation *Operation) (ret *TxErr) {
|
|||
}
|
||||
if nil != err {
|
||||
msg := fmt.Sprintf("load tree [id=%s] failed: %s", block.ID, err)
|
||||
util.LogErrorf(msg)
|
||||
logging.LogErrorf(msg)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: block.ID}
|
||||
}
|
||||
|
||||
|
|
@ -555,7 +556,7 @@ func (tx *Transaction) doAppendInsert(operation *Operation) (ret *TxErr) {
|
|||
|
||||
node := treenode.GetNodeInTree(tree, operation.ParentID)
|
||||
if nil == node {
|
||||
util.LogErrorf("get node [%s] in tree [%s] failed", operation.ParentID, tree.Root.ID)
|
||||
logging.LogErrorf("get node [%s] in tree [%s] failed", operation.ParentID, tree.Root.ID)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: operation.ParentID}
|
||||
}
|
||||
isContainer := node.IsContainerBlock()
|
||||
|
|
@ -594,18 +595,18 @@ func (tx *Transaction) doAppend(operation *Operation) (ret *TxErr) {
|
|||
id := operation.ID
|
||||
srcTree, err := tx.loadTree(id)
|
||||
if nil != err {
|
||||
util.LogErrorf("load tree [id=%s] failed: %s", id, err)
|
||||
logging.LogErrorf("load tree [id=%s] failed: %s", id, err)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: id}
|
||||
}
|
||||
|
||||
srcNode := treenode.GetNodeInTree(srcTree, id)
|
||||
if nil == srcNode {
|
||||
util.LogErrorf("get node [%s] in tree [%s] failed", id, srcTree.Root.ID)
|
||||
logging.LogErrorf("get node [%s] in tree [%s] failed", id, srcTree.Root.ID)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: id}
|
||||
}
|
||||
|
||||
if ast.NodeDocument == srcNode.Type {
|
||||
util.LogWarnf("can't append a root to another root")
|
||||
logging.LogWarnf("can't append a root to another root")
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -626,13 +627,13 @@ func (tx *Transaction) doAppend(operation *Operation) (ret *TxErr) {
|
|||
|
||||
targetRootID := operation.ParentID
|
||||
if id == targetRootID {
|
||||
util.LogWarnf("target root id is nil")
|
||||
logging.LogWarnf("target root id is nil")
|
||||
return
|
||||
}
|
||||
|
||||
targetTree, err := tx.loadTree(targetRootID)
|
||||
if nil != err {
|
||||
util.LogErrorf("load tree [id=%s] failed: %s", targetRootID, err)
|
||||
logging.LogErrorf("load tree [id=%s] failed: %s", targetRootID, err)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: targetRootID}
|
||||
}
|
||||
isSameTree := srcTree.ID == targetTree.ID
|
||||
|
|
@ -717,7 +718,7 @@ func (tx *Transaction) doLargeInsert() (ret *TxErr) {
|
|||
parentID := operations[0].ParentID
|
||||
parentBlock = treenode.GetBlockTree(parentID)
|
||||
if nil == parentBlock {
|
||||
util.LogErrorf("not found previous block [id=%s]", parentID)
|
||||
logging.LogErrorf("not found previous block [id=%s]", parentID)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: parentID}
|
||||
}
|
||||
}
|
||||
|
|
@ -727,7 +728,7 @@ func (tx *Transaction) doLargeInsert() (ret *TxErr) {
|
|||
return &TxErr{code: TxErrCodeUnableLockFile, msg: err.Error(), id: id}
|
||||
}
|
||||
if nil != err {
|
||||
util.LogErrorf("load tree [id=%s] failed: %s", id, err)
|
||||
logging.LogErrorf("load tree [id=%s] failed: %s", id, err)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: id}
|
||||
}
|
||||
|
||||
|
|
@ -751,7 +752,7 @@ func (tx *Transaction) doLargeInsert() (ret *TxErr) {
|
|||
|
||||
node := treenode.GetNodeInTree(tree, previousID)
|
||||
if nil == node {
|
||||
util.LogErrorf("get node [%s] in tree [%s] failed", previousID, tree.Root.ID)
|
||||
logging.LogErrorf("get node [%s] in tree [%s] failed", previousID, tree.Root.ID)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: previousID}
|
||||
}
|
||||
if ast.NodeList == insertedNode.Type && nil != node.Parent && ast.NodeList == node.Parent.Type {
|
||||
|
|
@ -765,7 +766,7 @@ func (tx *Transaction) doLargeInsert() (ret *TxErr) {
|
|||
if "delete" == operations[length-1].Action {
|
||||
node := treenode.GetNodeInTree(tree, previousID)
|
||||
if nil == node {
|
||||
util.LogErrorf("get node [%s] in tree [%s] failed", previousID, tree.Root.ID)
|
||||
logging.LogErrorf("get node [%s] in tree [%s] failed", previousID, tree.Root.ID)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: previousID}
|
||||
}
|
||||
node.Unlink()
|
||||
|
|
@ -779,7 +780,7 @@ func (tx *Transaction) doLargeInsert() (ret *TxErr) {
|
|||
}
|
||||
|
||||
func (tx *Transaction) doDelete(operation *Operation) (ret *TxErr) {
|
||||
// util.LogInfof("commit delete [%+v]", operation)
|
||||
// logging.LogInfof("commit delete [%+v]", operation)
|
||||
|
||||
var err error
|
||||
id := operation.ID
|
||||
|
|
@ -793,7 +794,7 @@ func (tx *Transaction) doDelete(operation *Operation) (ret *TxErr) {
|
|||
|
||||
if nil != err {
|
||||
msg := fmt.Sprintf("load tree [id=%s] failed: %s", id, err)
|
||||
util.LogErrorf(msg)
|
||||
logging.LogErrorf(msg)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: id}
|
||||
}
|
||||
|
||||
|
|
@ -830,7 +831,7 @@ func (tx *Transaction) doInsert(operation *Operation) (ret *TxErr) {
|
|||
block = treenode.GetBlockTree(operation.PreviousID)
|
||||
if nil == block {
|
||||
msg := fmt.Sprintf("not found previous block [id=%s]", operation.PreviousID)
|
||||
util.LogErrorf(msg)
|
||||
logging.LogErrorf(msg)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: operation.PreviousID}
|
||||
}
|
||||
}
|
||||
|
|
@ -840,7 +841,7 @@ func (tx *Transaction) doInsert(operation *Operation) (ret *TxErr) {
|
|||
}
|
||||
if nil != err {
|
||||
msg := fmt.Sprintf("load tree [id=%s] failed: %s", block.ID, err)
|
||||
util.LogErrorf(msg)
|
||||
logging.LogErrorf(msg)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: block.ID}
|
||||
}
|
||||
|
||||
|
|
@ -862,7 +863,7 @@ func (tx *Transaction) doInsert(operation *Operation) (ret *TxErr) {
|
|||
assetP := gulu.Str.FromBytes(n.Tokens)
|
||||
assetPath, e := GetAssetAbsPath(assetP)
|
||||
if nil != e {
|
||||
util.LogErrorf("get path of asset [%s] failed: %s", assetP, err)
|
||||
logging.LogErrorf("get path of asset [%s] failed: %s", assetP, err)
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
|
|
@ -874,7 +875,7 @@ func (tx *Transaction) doInsert(operation *Operation) (ret *TxErr) {
|
|||
// 只有全局 assets 才移动到相对 assets
|
||||
targetP := filepath.Join(assets, filepath.Base(assetPath))
|
||||
if e = os.Rename(assetPath, targetP); nil != err {
|
||||
util.LogErrorf("copy path of asset from [%s] to [%s] failed: %s", assetPath, targetP, err)
|
||||
logging.LogErrorf("copy path of asset from [%s] to [%s] failed: %s", assetPath, targetP, err)
|
||||
return ast.WalkContinue
|
||||
}
|
||||
}
|
||||
|
|
@ -905,7 +906,7 @@ func (tx *Transaction) doInsert(operation *Operation) (ret *TxErr) {
|
|||
if "" != previousID {
|
||||
node = treenode.GetNodeInTree(tree, previousID)
|
||||
if nil == node {
|
||||
util.LogErrorf("get node [%s] in tree [%s] failed", previousID, tree.Root.ID)
|
||||
logging.LogErrorf("get node [%s] in tree [%s] failed", previousID, tree.Root.ID)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: previousID}
|
||||
}
|
||||
|
||||
|
|
@ -926,7 +927,7 @@ func (tx *Transaction) doInsert(operation *Operation) (ret *TxErr) {
|
|||
} else {
|
||||
node = treenode.GetNodeInTree(tree, operation.ParentID)
|
||||
if nil == node {
|
||||
util.LogErrorf("get node [%s] in tree [%s] failed", operation.ParentID, tree.Root.ID)
|
||||
logging.LogErrorf("get node [%s] in tree [%s] failed", operation.ParentID, tree.Root.ID)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: operation.ParentID}
|
||||
}
|
||||
if ast.NodeSuperBlock == node.Type {
|
||||
|
|
@ -973,13 +974,13 @@ func (tx *Transaction) doUpdate(operation *Operation) (ret *TxErr) {
|
|||
return &TxErr{code: TxErrCodeUnableLockFile, msg: err.Error(), id: id}
|
||||
}
|
||||
if nil != err {
|
||||
util.LogErrorf("load tree [id=%s] failed: %s", id, err)
|
||||
logging.LogErrorf("load tree [id=%s] failed: %s", id, err)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: id}
|
||||
}
|
||||
|
||||
data := strings.ReplaceAll(operation.Data.(string), util2.FrontEndCaret, "")
|
||||
if "" == data {
|
||||
util.LogErrorf("update data is nil")
|
||||
logging.LogErrorf("update data is nil")
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: id}
|
||||
}
|
||||
|
||||
|
|
@ -988,7 +989,7 @@ func (tx *Transaction) doUpdate(operation *Operation) (ret *TxErr) {
|
|||
subTree.ID, subTree.Box, subTree.Path = tree.ID, tree.Box, tree.Path
|
||||
oldNode := treenode.GetNodeInTree(tree, id)
|
||||
if nil == oldNode {
|
||||
util.LogErrorf("get node [%s] in tree [%s] failed", id, tree.Root.ID)
|
||||
logging.LogErrorf("get node [%s] in tree [%s] failed", id, tree.Root.ID)
|
||||
return &TxErr{msg: ErrBlockNotFound.Error(), id: id}
|
||||
}
|
||||
|
||||
|
|
@ -1016,7 +1017,7 @@ func (tx *Transaction) doUpdate(operation *Operation) (ret *TxErr) {
|
|||
|
||||
updatedNode := subTree.Root.FirstChild
|
||||
if nil == updatedNode {
|
||||
util.LogErrorf("get fist node in sub tree [%s] failed", subTree.Root.ID)
|
||||
logging.LogErrorf("get fist node in sub tree [%s] failed", subTree.Root.ID)
|
||||
return &TxErr{msg: ErrBlockNotFound.Error(), id: id}
|
||||
}
|
||||
if ast.NodeList == updatedNode.Type && ast.NodeList == oldNode.Parent.Type {
|
||||
|
|
|
|||
|
|
@ -26,9 +26,9 @@ import (
|
|||
"github.com/88250/lute/parse"
|
||||
"github.com/88250/protyle"
|
||||
"github.com/siyuan-note/filelock"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/filesys"
|
||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
func pagedPaths(localPath string, pageSize int) (ret map[int][]string) {
|
||||
|
|
@ -55,13 +55,13 @@ func pagedPaths(localPath string, pageSize int) (ret map[int][]string) {
|
|||
func loadTree(localPath string, luteEngine *lute.Lute) (ret *parse.Tree, err error) {
|
||||
data, err := filelock.NoLockFileRead(localPath)
|
||||
if nil != err {
|
||||
util.LogErrorf("get data [path=%s] failed: %s", localPath, err)
|
||||
logging.LogErrorf("get data [path=%s] failed: %s", localPath, err)
|
||||
return
|
||||
}
|
||||
|
||||
ret, err = protyle.ParseJSONWithoutFix(luteEngine, data)
|
||||
if nil != err {
|
||||
util.LogErrorf("parse json to tree [%s] failed: %s", localPath, err)
|
||||
logging.LogErrorf("parse json to tree [%s] failed: %s", localPath, err)
|
||||
return
|
||||
}
|
||||
return
|
||||
|
|
@ -91,7 +91,7 @@ func LoadTree(boxID, p string) (*parse.Tree, error) {
|
|||
luteEngine := NewLute()
|
||||
tree, err := filesys.LoadTree(boxID, p, luteEngine)
|
||||
if nil != err {
|
||||
util.LogErrorf("load tree [%s] failed: %s", boxID+p, err)
|
||||
logging.LogErrorf("load tree [%s] failed: %s", boxID+p, err)
|
||||
return nil, err
|
||||
}
|
||||
return tree, nil
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import (
|
|||
"fmt"
|
||||
"sync"
|
||||
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
)
|
||||
|
||||
|
|
@ -36,7 +37,7 @@ type Announcement struct {
|
|||
func GetAnnouncements() (ret []*Announcement) {
|
||||
result, err := util.GetRhyResult(false)
|
||||
if nil != err {
|
||||
util.LogErrorf("get ")
|
||||
logging.LogErrorf("get announcement failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@ import (
|
|||
"github.com/88250/gulu"
|
||||
"github.com/88250/lute/ast"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/sql"
|
||||
"github.com/siyuan-note/siyuan/kernel/treenode"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
|
|
@ -102,7 +103,7 @@ func Upload(c *gin.Context) {
|
|||
|
||||
form, err := c.MultipartForm()
|
||||
if nil != err {
|
||||
util.LogErrorf("insert asset failed: %s", err)
|
||||
logging.LogErrorf("insert asset failed: %s", err)
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ import (
|
|||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/siyuan-note/logging"
|
||||
"github.com/siyuan-note/siyuan/kernel/util"
|
||||
|
||||
"github.com/siyuan-note/siyuan/kernel/search"
|
||||
|
|
@ -31,7 +32,7 @@ func SearchWidget(keyword string) (ret []*Block) {
|
|||
widgets := filepath.Join(util.DataDir, "widgets")
|
||||
dirs, err := os.ReadDir(widgets)
|
||||
if nil != err {
|
||||
util.LogErrorf("read dir [%s] failed: %s", widgets, err)
|
||||
logging.LogErrorf("read dir [%s] failed: %s", widgets, err)
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue