mirror of
https://github.com/siyuan-note/siyuan.git
synced 2026-02-28 01:44:07 +01:00
♻️ Refactor Go to err != nil, err == nil (#12385)
This commit is contained in:
parent
473a159ef2
commit
b100721fee
147 changed files with 1661 additions and 1659 deletions
|
|
@ -61,7 +61,7 @@ func chatGPT(msg string, cloud bool) (ret string) {
|
|||
}
|
||||
|
||||
ret, retCtxMsgs, err := chatGPTContinueWrite(msg, cachedContextMsg, cloud)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
cachedContextMsg = append(cachedContextMsg, retCtxMsgs...)
|
||||
|
|
@ -74,7 +74,7 @@ func chatGPTWithAction(msg string, action string, cloud bool) (ret string) {
|
|||
msg = action + ":\n\n" + msg
|
||||
}
|
||||
ret, _, err := chatGPTContinueWrite(msg, nil, cloud)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ import (
|
|||
|
||||
func InitAppearance() {
|
||||
util.SetBootDetails("Initializing appearance...")
|
||||
if err := os.Mkdir(util.AppearancePath, 0755); nil != err && !os.IsExist(err) {
|
||||
if err := os.Mkdir(util.AppearancePath, 0755); err != nil && !os.IsExist(err) {
|
||||
logging.LogErrorf("create appearance folder [%s] failed: %s", util.AppearancePath, err)
|
||||
util.ReportFileSysFatalError(err)
|
||||
return
|
||||
|
|
@ -42,7 +42,7 @@ func InitAppearance() {
|
|||
|
||||
unloadThemes()
|
||||
from := filepath.Join(util.WorkingDir, "appearance")
|
||||
if err := filelock.Copy(from, util.AppearancePath); nil != err {
|
||||
if err := filelock.Copy(from, util.AppearancePath); err != nil {
|
||||
logging.LogErrorf("copy appearance resources from [%s] to [%s] failed: %s", from, util.AppearancePath, err)
|
||||
util.ReportFileSysFatalError(err)
|
||||
return
|
||||
|
|
@ -70,7 +70,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 {
|
||||
if err := value.(*fsnotify.Watcher).Close(); err != nil {
|
||||
logging.LogErrorf("close file watcher failed: %s", err)
|
||||
}
|
||||
return true
|
||||
|
|
@ -83,7 +83,7 @@ func unloadThemes() {
|
|||
}
|
||||
|
||||
themeDirs, err := os.ReadDir(util.ThemesPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read appearance themes folder failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -98,7 +98,7 @@ func unloadThemes() {
|
|||
|
||||
func loadThemes() {
|
||||
themeDirs, err := os.ReadDir(util.ThemesPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read appearance themes folder failed: %s", err)
|
||||
util.ReportFileSysFatalError(err)
|
||||
return
|
||||
|
|
@ -143,7 +143,7 @@ func loadThemes() {
|
|||
|
||||
func loadIcons() {
|
||||
iconDirs, err := os.ReadDir(util.IconsPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read appearance icons folder failed: %s", err)
|
||||
util.ReportFileSysFatalError(err)
|
||||
return
|
||||
|
|
@ -156,7 +156,7 @@ func loadIcons() {
|
|||
}
|
||||
name := iconDir.Name()
|
||||
iconConf, err := bazaar.IconJSON(name)
|
||||
if nil != err || nil == iconConf {
|
||||
if err != nil || nil == iconConf {
|
||||
continue
|
||||
}
|
||||
Conf.Appearance.Icons = append(Conf.Appearance.Icons, name)
|
||||
|
|
@ -183,7 +183,7 @@ func watchTheme(folder string) {
|
|||
}
|
||||
|
||||
var err error
|
||||
if themeWatcher, err = fsnotify.NewWatcher(); nil != err {
|
||||
if themeWatcher, err = fsnotify.NewWatcher(); err != nil {
|
||||
logging.LogErrorf("add theme file watcher for folder [%s] failed: %s", folder, err)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -312,7 +312,7 @@ func IndexAssetContent(absPath string) {
|
|||
}
|
||||
|
||||
info, err := os.Stat(absPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("stat [%s] failed: %s", absPath, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -385,7 +385,7 @@ func (searcher *AssetsSearcher) FullIndex() {
|
|||
|
||||
var results []*AssetParseResult
|
||||
filelock.Walk(assetsDir, func(absPath string, info fs.FileInfo, err error) error {
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("walk dir [%s] failed: %s", absPath, err)
|
||||
return err
|
||||
}
|
||||
|
|
@ -502,7 +502,7 @@ type TxtAssetParser struct {
|
|||
|
||||
func (parser *TxtAssetParser) Parse(absPath string) (ret *AssetParseResult) {
|
||||
info, err := os.Stat(absPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("stat file [%s] failed: %s", absPath, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -519,7 +519,7 @@ func (parser *TxtAssetParser) Parse(absPath string) (ret *AssetParseResult) {
|
|||
defer os.RemoveAll(tmp)
|
||||
|
||||
data, err := os.ReadFile(tmp)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read file [%s] failed: %s", absPath, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -544,7 +544,7 @@ func normalizeNonTxtAssetContent(content string) (ret string) {
|
|||
|
||||
func copyTempAsset(absPath string) (ret string) {
|
||||
dir := filepath.Join(util.TempDir, "convert", "asset_content")
|
||||
if err := os.MkdirAll(dir, 0755); nil != err {
|
||||
if err := os.MkdirAll(dir, 0755); err != nil {
|
||||
logging.LogErrorf("mkdir [%s] failed: [%s]", dir, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -559,7 +559,7 @@ func copyTempAsset(absPath string) (ret string) {
|
|||
|
||||
ext := filepath.Ext(absPath)
|
||||
ret = filepath.Join(dir, gulu.Rand.String(7)+ext)
|
||||
if err := gulu.File.Copy(absPath, ret); nil != err {
|
||||
if err := gulu.File.Copy(absPath, ret); err != nil {
|
||||
logging.LogErrorf("copy [src=%s, dest=%s] failed: %s", absPath, ret, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -585,14 +585,14 @@ func (parser *DocxAssetParser) Parse(absPath string) (ret *AssetParseResult) {
|
|||
defer os.RemoveAll(tmp)
|
||||
|
||||
f, err := os.Open(tmp)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("open [%s] failed: [%s]", tmp, err)
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
data, _, err := docconv.ConvertDocx(f)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("convert [%s] failed: [%s]", tmp, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -623,14 +623,14 @@ func (parser *PptxAssetParser) Parse(absPath string) (ret *AssetParseResult) {
|
|||
defer os.RemoveAll(tmp)
|
||||
|
||||
f, err := os.Open(tmp)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("open [%s] failed: [%s]", tmp, err)
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
data, _, err := docconv.ConvertPptx(f)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("convert [%s] failed: [%s]", tmp, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -661,7 +661,7 @@ func (parser *XlsxAssetParser) Parse(absPath string) (ret *AssetParseResult) {
|
|||
defer os.RemoveAll(tmp)
|
||||
|
||||
x, err := excelize.OpenFile(tmp)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("open [%s] failed: [%s]", tmp, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -713,7 +713,7 @@ func (parser *PdfAssetParser) getTextPageWorker(id int, instance pdfium.Pdfium,
|
|||
doc, err := instance.OpenDocument(&requests.OpenDocument{
|
||||
File: pd.data,
|
||||
})
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
instance.FPDF_CloseDocument(&requests.FPDF_CloseDocument{
|
||||
Document: doc.Document,
|
||||
})
|
||||
|
|
@ -733,7 +733,7 @@ func (parser *PdfAssetParser) getTextPageWorker(id int, instance pdfium.Pdfium,
|
|||
},
|
||||
}
|
||||
res, err := instance.GetPageText(req)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
instance.FPDF_CloseDocument(&requests.FPDF_CloseDocument{
|
||||
Document: doc.Document,
|
||||
})
|
||||
|
|
@ -778,7 +778,7 @@ func (parser *PdfAssetParser) Parse(absPath string) (ret *AssetParseResult) {
|
|||
|
||||
// PDF blob will be processed in-memory making sharing of PDF document data across worker goroutines possible
|
||||
pdfData, err := os.ReadFile(tmp)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("open [%s] failed: [%s]", tmp, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -795,7 +795,7 @@ func (parser *PdfAssetParser) Parse(absPath string) (ret *AssetParseResult) {
|
|||
MaxIdle: cores,
|
||||
MaxTotal: cores,
|
||||
})
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("convert [%s] failed: [%s]", tmp, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -803,20 +803,20 @@ func (parser *PdfAssetParser) Parse(absPath string) (ret *AssetParseResult) {
|
|||
|
||||
// first get the number of PDF pages to convert into text
|
||||
instance, err := pool.GetInstance(time.Second * 30)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("convert [%s] failed: [%s]", tmp, err)
|
||||
return
|
||||
}
|
||||
doc, err := instance.OpenDocument(&requests.OpenDocument{
|
||||
File: &pdfData,
|
||||
})
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
instance.Close()
|
||||
logging.LogErrorf("convert [%s] failed: [%s]", tmp, err)
|
||||
return
|
||||
}
|
||||
pc, err := instance.FPDF_GetPageCount(&requests.FPDF_GetPageCount{Document: doc.Document})
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
instance.FPDF_CloseDocument(&requests.FPDF_CloseDocument{
|
||||
Document: doc.Document,
|
||||
})
|
||||
|
|
@ -854,7 +854,7 @@ func (parser *PdfAssetParser) Parse(absPath string) (ret *AssetParseResult) {
|
|||
results := make(chan *pdfTextResult, pc.PageCount)
|
||||
for i := 0; i < cores; i++ {
|
||||
inst, err := pool.GetInstance(time.Second * 30)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
close(pages)
|
||||
close(results)
|
||||
logging.LogErrorf("convert [%s] failed: [%s]", tmp, err)
|
||||
|
|
@ -919,14 +919,14 @@ func (parser *EpubAssetParser) Parse(absPath string) (ret *AssetParseResult) {
|
|||
defer os.RemoveAll(tmp)
|
||||
|
||||
f, err := os.Open(tmp)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("open [%s] failed: [%s]", tmp, err)
|
||||
return
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
buf := bytes.Buffer{}
|
||||
if err = epub.ToTxt(tmp, &buf); nil != err {
|
||||
if err = epub.ToTxt(tmp, &buf); err != nil {
|
||||
logging.LogErrorf("convert [%s] failed: [%s]", tmp, err)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ import (
|
|||
|
||||
func DocImageAssets(rootID string) (ret []string, err error) {
|
||||
tree, err := LoadTreeByBlockID(rootID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -77,7 +77,7 @@ func DocImageAssets(rootID string) (ret []string, err error) {
|
|||
|
||||
func NetAssets2LocalAssets(rootID string, onlyImg bool, originalURL string) (err error) {
|
||||
tree, err := LoadTreeByBlockID(rootID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -87,7 +87,7 @@ func NetAssets2LocalAssets(rootID string, onlyImg bool, originalURL string) (err
|
|||
docDirLocalPath := filepath.Join(util.DataDir, tree.Box, path.Dir(tree.Path))
|
||||
assetsDirPath := getAssetsDir(filepath.Join(util.DataDir, tree.Box), docDirLocalPath)
|
||||
if !gulu.File.IsExist(assetsDirPath) {
|
||||
if err = os.MkdirAll(assetsDirPath, 0755); nil != err {
|
||||
if err = os.MkdirAll(assetsDirPath, 0755); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -127,7 +127,7 @@ func NetAssets2LocalAssets(rootID string, onlyImg bool, originalURL string) (err
|
|||
name = "network-asset-" + name
|
||||
name = util.AssetName(name)
|
||||
writePath := filepath.Join(assetsDirPath, name)
|
||||
if err = filelock.Copy(u, writePath); nil != err {
|
||||
if err = filelock.Copy(u, writePath); err != nil {
|
||||
logging.LogErrorf("copy [%s] to [%s] failed: %s", u, writePath, err)
|
||||
continue
|
||||
}
|
||||
|
|
@ -223,7 +223,7 @@ func NetAssets2LocalAssets(rootID string, onlyImg bool, originalURL string) (err
|
|||
name = util.TruncateLenFileName(name)
|
||||
name = "network-asset-" + name + "-" + ast.NewNodeID() + ext
|
||||
writePath := filepath.Join(assetsDirPath, name)
|
||||
if err = filelock.WriteFile(writePath, data); nil != err {
|
||||
if err = filelock.WriteFile(writePath, data); err != nil {
|
||||
logging.LogErrorf("write downloaded network asset [%s] to local asset [%s] failed: %s", u, writePath, err)
|
||||
continue
|
||||
}
|
||||
|
|
@ -237,7 +237,7 @@ func NetAssets2LocalAssets(rootID string, onlyImg bool, originalURL string) (err
|
|||
|
||||
if 0 < files {
|
||||
util.PushUpdateMsg(msgId, Conf.Language(113), 7000)
|
||||
if err = writeTreeUpsertQueue(tree); nil != err {
|
||||
if err = writeTreeUpsertQueue(tree); err != nil {
|
||||
return
|
||||
}
|
||||
util.PushUpdateMsg(msgId, fmt.Sprintf(Conf.Language(120), files), 5000)
|
||||
|
|
@ -303,7 +303,7 @@ func GetAssetAbsPath(relativePath string) (ret string, err error) {
|
|||
relativePath = relativePath[:strings.Index(relativePath, "?")]
|
||||
}
|
||||
notebooks, err := ListNotebooks()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
err = errors.New(Conf.Language(0))
|
||||
return
|
||||
}
|
||||
|
|
@ -355,7 +355,7 @@ func UploadAssets2Cloud(rootID string) (count int, err error) {
|
|||
}
|
||||
|
||||
tree, err := LoadTreeByBlockID(rootID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -366,7 +366,7 @@ func UploadAssets2Cloud(rootID string) (count int, err error) {
|
|||
assets = append(assets, avAssets...)
|
||||
assets = gulu.Str.RemoveDuplicatedElem(assets)
|
||||
count, err = uploadAssets2Cloud(assets, bizTypeUploadAssets)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
|
|
@ -383,7 +383,7 @@ func uploadAssets2Cloud(assetPaths []string, bizType string) (count int, err err
|
|||
for _, assetPath := range assetPaths {
|
||||
var absPath string
|
||||
absPath, err = GetAssetAbsPath(assetPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogWarnf("get asset [%s] abs path failed: %s", assetPath, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -496,7 +496,7 @@ func RemoveUnusedAssets() (ret []string) {
|
|||
unusedAssets := UnusedAssets()
|
||||
|
||||
historyDir, err := GetHistoryDir(HistoryOpClean)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("get history dir failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -509,7 +509,7 @@ func RemoveUnusedAssets() (ret []string) {
|
|||
continue
|
||||
}
|
||||
|
||||
if err = filelock.Copy(p, historyPath); nil != err {
|
||||
if err = filelock.Copy(p, historyPath); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -522,7 +522,7 @@ func RemoveUnusedAssets() (ret []string) {
|
|||
|
||||
for _, unusedAsset := range unusedAssets {
|
||||
if unusedAsset = filepath.Join(util.DataDir, unusedAsset); filelock.IsExist(unusedAsset) {
|
||||
if err := filelock.Remove(unusedAsset); nil != err {
|
||||
if err := filelock.Remove(unusedAsset); err != nil {
|
||||
logging.LogErrorf("remove unused asset [%s] failed: %s", unusedAsset, err)
|
||||
}
|
||||
}
|
||||
|
|
@ -544,7 +544,7 @@ func RemoveUnusedAsset(p string) (ret string) {
|
|||
}
|
||||
|
||||
historyDir, err := GetHistoryDir(HistoryOpClean)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("get history dir failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -552,7 +552,7 @@ func RemoveUnusedAsset(p string) (ret string) {
|
|||
newP := strings.TrimPrefix(absPath, util.DataDir)
|
||||
historyPath := filepath.Join(historyDir, newP)
|
||||
if filelock.IsExist(absPath) {
|
||||
if err = filelock.Copy(absPath, historyPath); nil != err {
|
||||
if err = filelock.Copy(absPath, historyPath); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -560,7 +560,7 @@ func RemoveUnusedAsset(p string) (ret string) {
|
|||
sql.BatchRemoveAssetsQueue([]string{hash})
|
||||
}
|
||||
|
||||
if err = filelock.Remove(absPath); nil != err {
|
||||
if err = filelock.Remove(absPath); err != nil {
|
||||
logging.LogErrorf("remove unused asset [%s] failed: %s", absPath, err)
|
||||
}
|
||||
ret = absPath
|
||||
|
|
@ -591,14 +591,14 @@ func RenameAsset(oldPath, newName string) (newPath string, err error) {
|
|||
|
||||
newName = util.AssetName(newName + filepath.Ext(oldPath))
|
||||
newPath = "assets/" + newName
|
||||
if err = filelock.Copy(filepath.Join(util.DataDir, oldPath), filepath.Join(util.DataDir, newPath)); nil != err {
|
||||
if err = filelock.Copy(filepath.Join(util.DataDir, oldPath), filepath.Join(util.DataDir, newPath)); err != nil {
|
||||
logging.LogErrorf("copy asset [%s] failed: %s", oldPath, err)
|
||||
return
|
||||
}
|
||||
|
||||
if filelock.IsExist(filepath.Join(util.DataDir, oldPath+".sya")) {
|
||||
// Rename the .sya annotation file when renaming a PDF asset https://github.com/siyuan-note/siyuan/issues/9390
|
||||
if err = filelock.Copy(filepath.Join(util.DataDir, oldPath+".sya"), filepath.Join(util.DataDir, newPath+".sya")); nil != err {
|
||||
if err = filelock.Copy(filepath.Join(util.DataDir, oldPath+".sya"), filepath.Join(util.DataDir, newPath+".sya")); err != nil {
|
||||
logging.LogErrorf("copy PDF annotation [%s] failed: %s", oldPath+".sya", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -607,7 +607,7 @@ func RenameAsset(oldPath, newName string) (newPath string, err error) {
|
|||
oldName := path.Base(oldPath)
|
||||
|
||||
notebooks, err := ListNotebooks()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -659,12 +659,12 @@ func UnusedAssets() (ret []string) {
|
|||
ret = []string{}
|
||||
|
||||
assetsPathMap, err := allAssetAbsPaths()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
linkDestMap := map[string]bool{}
|
||||
notebooks, err := ListNotebooks()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
luteEngine := util.NewLute()
|
||||
|
|
@ -815,11 +815,11 @@ func MissingAssets() (ret []string) {
|
|||
ret = []string{}
|
||||
|
||||
assetsPathMap, err := allAssetAbsPaths()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
notebooks, err := ListNotebooks()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
luteEngine := util.NewLute()
|
||||
|
|
@ -1188,7 +1188,7 @@ func getRemoteAssetsLinkDestsInTree(tree *parse.Tree, onlyImg bool) (nodes []*as
|
|||
// allAssetAbsPaths 返回 asset 相对路径(assets/xxx)到绝对路径(F:\SiYuan\data\assets\xxx)的映射。
|
||||
func allAssetAbsPaths() (assetsAbsPathMap map[string]string, err error) {
|
||||
notebooks, err := ListNotebooks()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -1305,7 +1305,7 @@ func copyAssetsToDataAssets(rootPath string) {
|
|||
|
||||
dataAssetsPath := filepath.Join(util.DataDir, "assets")
|
||||
for _, assetsDirPath := range assetsDirPaths {
|
||||
if err := filelock.Copy(assetsDirPath, dataAssetsPath); nil != err {
|
||||
if err := filelock.Copy(assetsDirPath, dataAssetsPath); err != nil {
|
||||
logging.LogErrorf("copy tree assets from [%s] to [%s] failed: %s", assetsDirPaths, dataAssetsPath, err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ func watchAssets() {
|
|||
}
|
||||
|
||||
var err error
|
||||
if assetsWatcher, err = fsnotify.NewWatcher(); nil != err {
|
||||
if assetsWatcher, err = fsnotify.NewWatcher(); err != nil {
|
||||
logging.LogErrorf("add assets watcher for folder [%s] failed: %s", assetsDir, err)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,13 +76,13 @@ func watchAssets() {
|
|||
}
|
||||
}()
|
||||
|
||||
if err := assetsWatcher.Add(assetsDir); nil != err {
|
||||
if err := assetsWatcher.Add(assetsDir); err != nil {
|
||||
logging.LogErrorf("add assets watcher for folder [%s] failed: %s", assetsDir, err)
|
||||
return
|
||||
}
|
||||
|
||||
//logging.LogInfof("added file watcher [%s]", assetsDir)
|
||||
if err := assetsWatcher.Start(10 * time.Second); nil != err {
|
||||
if err := assetsWatcher.Start(10 * time.Second); err != nil {
|
||||
logging.LogErrorf("start assets watcher for folder [%s] failed: %s", assetsDir, err)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -134,7 +134,7 @@ func GetBacklinkDoc(defID, refTreeID, keyword string, containChildren bool) (ret
|
|||
|
||||
linkRefs, _, _ := buildLinkRefs(rootID, refs, keyword)
|
||||
refTree, err := LoadTreeByBlockID(refTreeID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogWarnf("load ref tree [%s] failed: %s", refTreeID, err)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ func BatchUpdateBazaarPackages(frontend string) {
|
|||
count := 1
|
||||
for _, plugin := range plugins {
|
||||
err := bazaar.InstallPlugin(plugin.RepoURL, plugin.RepoHash, filepath.Join(util.DataDir, "plugins", plugin.Name), Conf.System.ID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("update plugin [%s] failed: %s", plugin.Name, err)
|
||||
util.PushErrMsg(fmt.Sprintf(Conf.language(238)), 5000)
|
||||
return
|
||||
|
|
@ -57,7 +57,7 @@ func BatchUpdateBazaarPackages(frontend string) {
|
|||
|
||||
for _, widget := range widgets {
|
||||
err := bazaar.InstallWidget(widget.RepoURL, widget.RepoHash, filepath.Join(util.DataDir, "widgets", widget.Name), Conf.System.ID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("update widget [%s] failed: %s", widget.Name, err)
|
||||
util.PushErrMsg(fmt.Sprintf(Conf.language(238)), 5000)
|
||||
return
|
||||
|
|
@ -69,7 +69,7 @@ func BatchUpdateBazaarPackages(frontend string) {
|
|||
|
||||
for _, icon := range icons {
|
||||
err := bazaar.InstallIcon(icon.RepoURL, icon.RepoHash, filepath.Join(util.IconsPath, icon.Name), Conf.System.ID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("update icon [%s] failed: %s", icon.Name, err)
|
||||
util.PushErrMsg(fmt.Sprintf(Conf.language(238)), 5000)
|
||||
return
|
||||
|
|
@ -81,7 +81,7 @@ func BatchUpdateBazaarPackages(frontend string) {
|
|||
|
||||
for _, template := range templates {
|
||||
err := bazaar.InstallTemplate(template.RepoURL, template.RepoHash, filepath.Join(util.DataDir, "templates", template.Name), Conf.System.ID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("update template [%s] failed: %s", template.Name, err)
|
||||
util.PushErrMsg(fmt.Sprintf(Conf.language(238)), 5000)
|
||||
return
|
||||
|
|
@ -93,7 +93,7 @@ func BatchUpdateBazaarPackages(frontend string) {
|
|||
|
||||
for _, theme := range themes {
|
||||
err := bazaar.InstallTheme(theme.RepoURL, theme.RepoHash, filepath.Join(util.ThemesPath, theme.Name), Conf.System.ID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("update theme [%s] failed: %s", theme.Name, err)
|
||||
util.PushErrMsg(fmt.Sprintf(Conf.language(238)), 5000)
|
||||
return
|
||||
|
|
@ -202,7 +202,7 @@ func BazaarPlugins(frontend, keyword string) (plugins []*bazaar.Plugin) {
|
|||
for _, plugin := range plugins {
|
||||
plugin.Installed = util.IsPathRegularDirOrSymlinkDir(filepath.Join(util.DataDir, "plugins", plugin.Name))
|
||||
if plugin.Installed {
|
||||
if pluginConf, err := bazaar.PluginJSON(plugin.Name); nil == err && nil != plugin {
|
||||
if pluginConf, err := bazaar.PluginJSON(plugin.Name); err == nil && nil != plugin {
|
||||
plugin.Outdated = 0 > semver.Compare("v"+pluginConf.Version, "v"+plugin.Version)
|
||||
}
|
||||
}
|
||||
|
|
@ -237,7 +237,7 @@ func InstalledPlugins(frontend, keyword string) (plugins []*bazaar.Plugin) {
|
|||
func InstallBazaarPlugin(repoURL, repoHash, pluginName string) error {
|
||||
installPath := filepath.Join(util.DataDir, "plugins", pluginName)
|
||||
err := bazaar.InstallPlugin(repoURL, repoHash, installPath, Conf.System.ID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf(Conf.Language(46), pluginName, err))
|
||||
}
|
||||
return nil
|
||||
|
|
@ -246,7 +246,7 @@ func InstallBazaarPlugin(repoURL, repoHash, pluginName string) error {
|
|||
func UninstallBazaarPlugin(pluginName, frontend string) error {
|
||||
installPath := filepath.Join(util.DataDir, "plugins", pluginName)
|
||||
err := bazaar.UninstallPlugin(installPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf(Conf.Language(47), err.Error()))
|
||||
}
|
||||
|
||||
|
|
@ -271,7 +271,7 @@ func BazaarWidgets(keyword string) (widgets []*bazaar.Widget) {
|
|||
for _, widget := range widgets {
|
||||
widget.Installed = util.IsPathRegularDirOrSymlinkDir(filepath.Join(util.DataDir, "widgets", widget.Name))
|
||||
if widget.Installed {
|
||||
if widgetConf, err := bazaar.WidgetJSON(widget.Name); nil == err && nil != widget {
|
||||
if widgetConf, err := bazaar.WidgetJSON(widget.Name); err == nil && nil != widget {
|
||||
widget.Outdated = 0 > semver.Compare("v"+widgetConf.Version, "v"+widget.Version)
|
||||
}
|
||||
}
|
||||
|
|
@ -299,7 +299,7 @@ func InstalledWidgets(keyword string) (widgets []*bazaar.Widget) {
|
|||
func InstallBazaarWidget(repoURL, repoHash, widgetName string) error {
|
||||
installPath := filepath.Join(util.DataDir, "widgets", widgetName)
|
||||
err := bazaar.InstallWidget(repoURL, repoHash, installPath, Conf.System.ID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf(Conf.Language(46), widgetName, err))
|
||||
}
|
||||
return nil
|
||||
|
|
@ -308,7 +308,7 @@ func InstallBazaarWidget(repoURL, repoHash, widgetName string) error {
|
|||
func UninstallBazaarWidget(widgetName string) error {
|
||||
installPath := filepath.Join(util.DataDir, "widgets", widgetName)
|
||||
err := bazaar.UninstallWidget(installPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf(Conf.Language(47), err.Error()))
|
||||
}
|
||||
return nil
|
||||
|
|
@ -321,7 +321,7 @@ func BazaarIcons(keyword string) (icons []*bazaar.Icon) {
|
|||
for _, icon := range icons {
|
||||
if installed == icon.Name {
|
||||
icon.Installed = true
|
||||
if iconConf, err := bazaar.IconJSON(icon.Name); nil == err {
|
||||
if iconConf, err := bazaar.IconJSON(icon.Name); err == nil {
|
||||
icon.Outdated = 0 > semver.Compare("v"+iconConf.Version, "v"+icon.Version)
|
||||
}
|
||||
}
|
||||
|
|
@ -354,7 +354,7 @@ func InstalledIcons(keyword string) (icons []*bazaar.Icon) {
|
|||
func InstallBazaarIcon(repoURL, repoHash, iconName string) error {
|
||||
installPath := filepath.Join(util.IconsPath, iconName)
|
||||
err := bazaar.InstallIcon(repoURL, repoHash, installPath, Conf.System.ID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf(Conf.Language(46), iconName, err))
|
||||
}
|
||||
Conf.Appearance.Icon = iconName
|
||||
|
|
@ -366,7 +366,7 @@ func InstallBazaarIcon(repoURL, repoHash, iconName string) error {
|
|||
func UninstallBazaarIcon(iconName string) error {
|
||||
installPath := filepath.Join(util.IconsPath, iconName)
|
||||
err := bazaar.UninstallIcon(installPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf(Conf.Language(47), err.Error()))
|
||||
}
|
||||
|
||||
|
|
@ -383,7 +383,7 @@ func BazaarThemes(keyword string) (ret []*bazaar.Theme) {
|
|||
for _, theme := range ret {
|
||||
if installed == theme.Name {
|
||||
theme.Installed = true
|
||||
if themeConf, err := bazaar.ThemeJSON(theme.Name); nil == err {
|
||||
if themeConf, err := bazaar.ThemeJSON(theme.Name); err == nil {
|
||||
theme.Outdated = 0 > semver.Compare("v"+themeConf.Version, "v"+theme.Version)
|
||||
}
|
||||
theme.Current = theme.Name == Conf.Appearance.ThemeDark || theme.Name == Conf.Appearance.ThemeLight
|
||||
|
|
@ -418,7 +418,7 @@ func InstallBazaarTheme(repoURL, repoHash, themeName string, mode int, update bo
|
|||
|
||||
installPath := filepath.Join(util.ThemesPath, themeName)
|
||||
err := bazaar.InstallTheme(repoURL, repoHash, installPath, Conf.System.ID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf(Conf.Language(46), themeName, err))
|
||||
}
|
||||
|
||||
|
|
@ -443,7 +443,7 @@ func UninstallBazaarTheme(themeName string) error {
|
|||
|
||||
installPath := filepath.Join(util.ThemesPath, themeName)
|
||||
err := bazaar.UninstallTheme(installPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf(Conf.Language(47), err.Error()))
|
||||
}
|
||||
|
||||
|
|
@ -457,7 +457,7 @@ func BazaarTemplates(keyword string) (templates []*bazaar.Template) {
|
|||
for _, template := range templates {
|
||||
template.Installed = util.IsPathRegularDirOrSymlinkDir(filepath.Join(util.DataDir, "templates", template.Name))
|
||||
if template.Installed {
|
||||
if templateConf, err := bazaar.TemplateJSON(template.Name); nil == err && nil != templateConf {
|
||||
if templateConf, err := bazaar.TemplateJSON(template.Name); err == nil && nil != templateConf {
|
||||
template.Outdated = 0 > semver.Compare("v"+templateConf.Version, "v"+template.Version)
|
||||
}
|
||||
}
|
||||
|
|
@ -485,7 +485,7 @@ func InstalledTemplates(keyword string) (templates []*bazaar.Template) {
|
|||
func InstallBazaarTemplate(repoURL, repoHash, templateName string) error {
|
||||
installPath := filepath.Join(util.DataDir, "templates", templateName)
|
||||
err := bazaar.InstallTemplate(repoURL, repoHash, installPath, Conf.System.ID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf(Conf.Language(46), templateName, err))
|
||||
}
|
||||
return nil
|
||||
|
|
@ -494,7 +494,7 @@ func InstallBazaarTemplate(repoURL, repoHash, templateName string) error {
|
|||
func UninstallBazaarTemplate(templateName string) error {
|
||||
installPath := filepath.Join(util.DataDir, "templates", templateName)
|
||||
err := bazaar.UninstallTemplate(installPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return errors.New(fmt.Sprintf(Conf.Language(47), err.Error()))
|
||||
}
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -177,7 +177,7 @@ func GetBlockTreeInfos(ids []string) (ret map[string]*BlockTreeInfo) {
|
|||
|
||||
func GetBlockSiblingID(id string) (parent, previous, next string) {
|
||||
tree, err := LoadTreeByBlockID(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -341,7 +341,7 @@ func TransferBlockRef(fromID, toID string, refIDs []string) (err error) {
|
|||
}
|
||||
}
|
||||
|
||||
if err = indexWriteTreeUpsertQueue(tree); nil != err {
|
||||
if err = indexWriteTreeUpsertQueue(tree); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -352,7 +352,7 @@ func TransferBlockRef(fromID, toID string, refIDs []string) (err error) {
|
|||
|
||||
func SwapBlockRef(refID, defID string, includeChildren bool) (err error) {
|
||||
refTree, err := LoadTreeByBlockID(refID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
refNode := treenode.GetNodeInTree(refTree, refID)
|
||||
|
|
@ -363,7 +363,7 @@ func SwapBlockRef(refID, defID string, includeChildren bool) (err error) {
|
|||
refNode = refNode.Parent
|
||||
}
|
||||
defTree, err := LoadTreeByBlockID(defID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
sameTree := defTree.ID == refTree.ID
|
||||
|
|
@ -453,11 +453,11 @@ func SwapBlockRef(refID, defID string, includeChildren bool) (err error) {
|
|||
}
|
||||
refPivot.Unlink()
|
||||
|
||||
if err = indexWriteTreeUpsertQueue(refTree); nil != err {
|
||||
if err = indexWriteTreeUpsertQueue(refTree); err != nil {
|
||||
return
|
||||
}
|
||||
if !sameTree {
|
||||
if err = indexWriteTreeUpsertQueue(defTree); nil != err {
|
||||
if err = indexWriteTreeUpsertQueue(defTree); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -468,7 +468,7 @@ func SwapBlockRef(refID, defID string, includeChildren bool) (err error) {
|
|||
|
||||
func GetHeadingDeleteTransaction(id string) (transaction *Transaction, err error) {
|
||||
tree, err := LoadTreeByBlockID(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -511,7 +511,7 @@ func GetHeadingDeleteTransaction(id string) (transaction *Transaction, err error
|
|||
|
||||
func GetHeadingChildrenIDs(id string) (ret []string) {
|
||||
tree, err := LoadTreeByBlockID(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
heading := treenode.GetNodeInTree(tree, id)
|
||||
|
|
@ -529,7 +529,7 @@ func GetHeadingChildrenIDs(id string) (ret []string) {
|
|||
|
||||
func GetHeadingChildrenDOM(id string) (ret string) {
|
||||
tree, err := LoadTreeByBlockID(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
heading := treenode.GetNodeInTree(tree, id)
|
||||
|
|
@ -547,7 +547,7 @@ func GetHeadingChildrenDOM(id string) (ret string) {
|
|||
|
||||
func GetHeadingLevelTransaction(id string, level int) (transaction *Transaction, err error) {
|
||||
tree, err := LoadTreeByBlockID(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -606,7 +606,7 @@ func GetBlockDOM(id string) (ret string) {
|
|||
}
|
||||
|
||||
tree, err := LoadTreeByBlockID(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
node := treenode.GetNodeInTree(tree, id)
|
||||
|
|
@ -621,7 +621,7 @@ func GetBlockKramdown(id string) (ret string) {
|
|||
}
|
||||
|
||||
tree, err := LoadTreeByBlockID(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -650,7 +650,7 @@ func GetChildBlocks(id string) (ret []*ChildBlock) {
|
|||
}
|
||||
|
||||
tree, err := LoadTreeByBlockID(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -702,7 +702,7 @@ func GetTailChildBlocks(id string, n int) (ret []*ChildBlock) {
|
|||
}
|
||||
|
||||
tree, err := LoadTreeByBlockID(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -767,10 +767,10 @@ func getBlock(id string, tree *parse.Tree) (ret *Block, err error) {
|
|||
|
||||
if nil == tree {
|
||||
tree, err = LoadTreeByBlockID(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
time.Sleep(1 * time.Second)
|
||||
tree, err = LoadTreeByBlockID(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ func SetBlockReminder(id string, timed string) (err error) {
|
|||
|
||||
attrs := GetBlockAttrs(id) // 获取属性是会等待树写入
|
||||
tree, err := LoadTreeByBlockID(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -70,7 +70,7 @@ func SetBlockReminder(id string, timed string) (err error) {
|
|||
content := sql.NodeStaticContent(node, nil, false, false, false, GetBlockAttrsWithoutWaitWriting)
|
||||
content = gulu.Str.SubStr(content, 128)
|
||||
err = SetCloudBlockReminder(id, content, timedMills)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -88,7 +88,7 @@ func SetBlockReminder(id string, timed string) (err error) {
|
|||
node.SetIALAttr(attrName, timed)
|
||||
util.PushMsg(fmt.Sprintf(Conf.Language(101), time.UnixMilli(timedMills).Format("2006-01-02 15:04")), 5000)
|
||||
}
|
||||
if err = indexWriteTreeUpsertQueue(tree); nil != err {
|
||||
if err = indexWriteTreeUpsertQueue(tree); err != nil {
|
||||
return
|
||||
}
|
||||
IncSync()
|
||||
|
|
@ -144,7 +144,7 @@ func BatchSetBlockAttrs(blockAttrs []map[string]interface{}) (err error) {
|
|||
}
|
||||
|
||||
for _, tree := range trees {
|
||||
if err = indexWriteTreeUpsertQueue(tree); nil != err {
|
||||
if err = indexWriteTreeUpsertQueue(tree); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -162,7 +162,7 @@ func SetBlockAttrs(id string, nameValues map[string]string) (err error) {
|
|||
WaitForWritingFiles()
|
||||
|
||||
tree, err := LoadTreeByBlockID(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -177,11 +177,11 @@ func SetBlockAttrs(id string, nameValues map[string]string) (err error) {
|
|||
|
||||
func setNodeAttrs(node *ast.Node, tree *parse.Tree, nameValues map[string]string) (err error) {
|
||||
oldAttrs, err := setNodeAttrs0(node, nameValues)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err = indexWriteTreeUpsertQueue(tree); nil != err {
|
||||
if err = indexWriteTreeUpsertQueue(tree); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -201,11 +201,11 @@ func setNodeAttrs(node *ast.Node, tree *parse.Tree, nameValues map[string]string
|
|||
|
||||
func setNodeAttrsWithTx(tx *Transaction, node *ast.Node, tree *parse.Tree, nameValues map[string]string) (err error) {
|
||||
oldAttrs, err := setNodeAttrs0(node, nameValues)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err = tx.writeTree(tree); nil != err {
|
||||
if err = tx.writeTree(tree); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -250,7 +250,7 @@ func pushBroadcastAttrTransactions(oldAttrs map[string]string, node *ast.Node) {
|
|||
|
||||
func ResetBlockAttrs(id string, nameValues map[string]string) (err error) {
|
||||
tree, err := LoadTreeByBlockID(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -280,7 +280,7 @@ func ResetBlockAttrs(id string, nameValues map[string]string) (err error) {
|
|||
updateRefTextRenameDoc(tree)
|
||||
}
|
||||
|
||||
if err = indexWriteTreeUpsertQueue(tree); nil != err {
|
||||
if err = indexWriteTreeUpsertQueue(tree); err != nil {
|
||||
return
|
||||
}
|
||||
IncSync()
|
||||
|
|
@ -335,7 +335,7 @@ func getBlockAttrs(id string) (ret map[string]string) {
|
|||
ret = map[string]string{}
|
||||
|
||||
tree, err := LoadTreeByBlockID(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ func GetDocInfo(blockID string) (ret *BlockInfo) {
|
|||
WaitForWritingFiles()
|
||||
|
||||
tree, err := LoadTreeByBlockID(blockID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("load tree by root id [%s] failed: %s", blockID, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -111,7 +111,7 @@ func GetDocInfo(blockID string) (ret *BlockInfo) {
|
|||
var subFileCount int
|
||||
boxLocalPath := filepath.Join(util.DataDir, tree.Box)
|
||||
subFiles, err := os.ReadDir(filepath.Join(boxLocalPath, strings.TrimSuffix(tree.Path, ".sy")))
|
||||
if nil == err {
|
||||
if err == nil {
|
||||
for _, subFile := range subFiles {
|
||||
if strings.HasSuffix(subFile.Name(), ".sy") {
|
||||
subFileCount++
|
||||
|
|
@ -130,7 +130,7 @@ func GetBlockRefText(id string) string {
|
|||
}
|
||||
|
||||
tree, err := LoadTreeByBlockID(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ func RemoveBookmark(bookmark string) (err error) {
|
|||
}
|
||||
|
||||
util.PushEndlessProgress(fmt.Sprintf(Conf.Language(111), util.EscapeHTML(tree.Root.IALAttr("title"))))
|
||||
if err = writeTreeUpsertQueue(tree); nil != err {
|
||||
if err = writeTreeUpsertQueue(tree); err != nil {
|
||||
util.ClearPushProgress(100)
|
||||
return
|
||||
}
|
||||
|
|
@ -124,7 +124,7 @@ func RenameBookmark(oldBookmark, newBookmark string) (err error) {
|
|||
}
|
||||
|
||||
util.PushEndlessProgress(fmt.Sprintf(Conf.Language(111), util.EscapeHTML(tree.Root.IALAttr("title"))))
|
||||
if err = writeTreeUpsertQueue(tree); nil != err {
|
||||
if err = writeTreeUpsertQueue(tree); err != nil {
|
||||
util.ClearPushProgress(100)
|
||||
return
|
||||
}
|
||||
|
|
@ -180,7 +180,7 @@ func BuildBookmark() (ret *Bookmarks) {
|
|||
} else {
|
||||
// Improve bookmark panel rendering https://github.com/siyuan-note/siyuan/issues/9361
|
||||
tree, err := LoadTreeByBlockID(block.ID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("parse block [%s] failed: %s", block.ID, err)
|
||||
} else {
|
||||
n := treenode.GetNodeInTree(tree, block.ID)
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ func StatJob() {
|
|||
func ListNotebooks() (ret []*Box, err error) {
|
||||
ret = []*Box{}
|
||||
dirs, err := os.ReadDir(util.DataDir)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read dir [%s] failed: %s", util.DataDir, err)
|
||||
return ret, err
|
||||
}
|
||||
|
|
@ -185,12 +185,12 @@ func (box *Box) GetConf() (ret *conf.BoxConf) {
|
|||
}
|
||||
|
||||
data, err := filelock.ReadFile(confPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read box conf [%s] failed: %s", confPath, err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = gulu.JSON.UnmarshalJSON(data, ret); nil != err {
|
||||
if err = gulu.JSON.UnmarshalJSON(data, ret); err != nil {
|
||||
logging.LogErrorf("parse box conf [%s] failed: %s", confPath, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -200,13 +200,13 @@ func (box *Box) GetConf() (ret *conf.BoxConf) {
|
|||
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 {
|
||||
if err != nil {
|
||||
logging.LogErrorf("marshal box conf [%s] failed: %s", confPath, err)
|
||||
return
|
||||
}
|
||||
|
||||
oldData, err := filelock.ReadFile(confPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
box.saveConf0(newData)
|
||||
return
|
||||
}
|
||||
|
|
@ -220,10 +220,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 {
|
||||
if err := os.MkdirAll(filepath.Join(util.DataDir, box.ID, ".siyuan"), 0755); err != nil {
|
||||
logging.LogErrorf("save box conf [%s] failed: %s", confPath, err)
|
||||
}
|
||||
if err := filelock.WriteFile(confPath, data); nil != err {
|
||||
if err := filelock.WriteFile(confPath, data); err != nil {
|
||||
logging.LogErrorf("write box conf [%s] failed: %s", confPath, err)
|
||||
util.ReportFileSysFatalError(err)
|
||||
return
|
||||
|
|
@ -243,7 +243,7 @@ func (box *Box) Ls(p string) (ret []*FileInfo, totals int, err error) {
|
|||
}
|
||||
|
||||
entries, err := os.ReadDir(filepath.Join(util.DataDir, box.ID, p))
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -287,7 +287,7 @@ func (box *Box) Ls(p string) (ret []*FileInfo, totals int, err error) {
|
|||
func (box *Box) Stat(p string) (ret *FileInfo) {
|
||||
absPath := filepath.Join(util.DataDir, box.ID, p)
|
||||
info, err := os.Stat(absPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
logging.LogErrorf("stat [%s] failed: %s", absPath, err)
|
||||
}
|
||||
|
|
@ -307,7 +307,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 {
|
||||
if err := os.Mkdir(filepath.Join(util.DataDir, box.ID, path), 0755); err != nil {
|
||||
msg := fmt.Sprintf(Conf.Language(6), box.Name, path, err)
|
||||
logging.LogErrorf("mkdir [path=%s] in box [%s] failed: %s", path, box.ID, err)
|
||||
return errors.New(msg)
|
||||
|
|
@ -317,7 +317,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 {
|
||||
if err := os.MkdirAll(filepath.Join(util.DataDir, box.ID, path), 0755); err != nil {
|
||||
msg := fmt.Sprintf(Conf.Language(6), box.Name, path, err)
|
||||
logging.LogErrorf("mkdir all [path=%s] in box [%s] failed: %s", path, box.ID, err)
|
||||
return errors.New(msg)
|
||||
|
|
@ -331,7 +331,7 @@ func (box *Box) Move(oldPath, newPath string) error {
|
|||
fromPath := filepath.Join(boxLocalPath, oldPath)
|
||||
toPath := filepath.Join(boxLocalPath, newPath)
|
||||
|
||||
if err := filelock.Rename(fromPath, toPath); nil != err {
|
||||
if err := filelock.Rename(fromPath, toPath); err != nil {
|
||||
msg := fmt.Sprintf(Conf.Language(5), box.Name, fromPath, err)
|
||||
logging.LogErrorf("move [path=%s] in box [%s] failed: %s", fromPath, box.Name, err)
|
||||
return errors.New(msg)
|
||||
|
|
@ -350,7 +350,7 @@ func (box *Box) Move(oldPath, newPath string) error {
|
|||
func (box *Box) Remove(path string) error {
|
||||
boxLocalPath := filepath.Join(util.DataDir, box.ID)
|
||||
filePath := filepath.Join(boxLocalPath, path)
|
||||
if err := filelock.Remove(filePath); nil != err {
|
||||
if err := filelock.Remove(filePath); err != nil {
|
||||
msg := fmt.Sprintf(Conf.Language(7), box.Name, path, err)
|
||||
logging.LogErrorf("remove [path=%s] in box [%s] failed: %s", path, box.ID, err)
|
||||
return errors.New(msg)
|
||||
|
|
@ -361,7 +361,7 @@ func (box *Box) Remove(path string) error {
|
|||
|
||||
func (box *Box) ListFiles(path string) (ret []*FileInfo) {
|
||||
fis, _, err := box.Ls(path)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
box.listFiles(&fis, &ret)
|
||||
|
|
@ -372,7 +372,7 @@ func (box *Box) listFiles(files, ret *[]*FileInfo) {
|
|||
for _, file := range *files {
|
||||
if file.isdir {
|
||||
fis, _, err := box.Ls(file.path)
|
||||
if nil == err {
|
||||
if err == nil {
|
||||
box.listFiles(&fis, ret)
|
||||
}
|
||||
*ret = append(*ret, file)
|
||||
|
|
@ -412,7 +412,7 @@ func (box *Box) renameSubTrees(tree *parse.Tree) {
|
|||
}
|
||||
|
||||
subTree, err := filesys.LoadTree(box.ID, subFile.path, luteEngine) // LoadTree 会重新构造 HPath
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
|
|
@ -521,7 +521,7 @@ func fullReindex() {
|
|||
|
||||
WaitForWritingFiles()
|
||||
|
||||
if err := sql.InitDatabase(true); nil != err {
|
||||
if err := sql.InitDatabase(true); err != nil {
|
||||
os.Exit(logging.ExitCodeReadOnlyDatabase)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ func CloudChatGPT(msg string, contextMsgs []string) (ret string, stop bool, err
|
|||
SetCookies(&http.Cookie{Name: "symphony", Value: Conf.GetUser().UserToken}).
|
||||
SetBody(payload).
|
||||
Post(util.GetCloudServer() + "/apis/siyuan/ai/chatGPT")
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("chat gpt failed: %s", err)
|
||||
err = ErrFailedToConnectCloudServer
|
||||
return
|
||||
|
|
@ -109,7 +109,7 @@ func StartFreeTrial() (err error) {
|
|||
SetSuccessResult(requestResult).
|
||||
SetCookies(&http.Cookie{Name: "symphony", Value: Conf.GetUser().UserToken}).
|
||||
Post(util.GetCloudServer() + "/apis/siyuan/user/startFreeTrial")
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("start free trial failed: %s", err)
|
||||
return ErrFailedToConnectCloudServer
|
||||
}
|
||||
|
|
@ -130,7 +130,7 @@ func DeactivateUser() (err error) {
|
|||
SetSuccessResult(requestResult).
|
||||
SetCookies(&http.Cookie{Name: "symphony", Value: Conf.GetUser().UserToken}).
|
||||
Post(util.GetCloudServer() + "/apis/siyuan/user/deactivate")
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("deactivate user failed: %s", err)
|
||||
return ErrFailedToConnectCloudServer
|
||||
}
|
||||
|
|
@ -156,7 +156,7 @@ func SetCloudBlockReminder(id, data string, timed int64) (err error) {
|
|||
SetBody(payload).
|
||||
SetCookies(&http.Cookie{Name: "symphony", Value: Conf.GetUser().UserToken}).
|
||||
Post(util.GetCloudServer() + "/apis/siyuan/calendar/setBlockReminder")
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("set block reminder failed: %s", err)
|
||||
return ErrFailedToConnectCloudServer
|
||||
}
|
||||
|
|
@ -188,7 +188,7 @@ func LoadUploadToken() (err error) {
|
|||
SetSuccessResult(requestResult).
|
||||
SetCookies(&http.Cookie{Name: "symphony", Value: Conf.GetUser().UserToken}).
|
||||
Post(util.GetCloudServer() + "/apis/siyuan/upload/token")
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("get upload token failed: %s", err)
|
||||
return ErrFailedToConnectCloudServer
|
||||
}
|
||||
|
|
@ -288,11 +288,11 @@ func refreshAnnouncement() {
|
|||
var existingAnnouncements, newAnnouncements []*Announcement
|
||||
if gulu.File.IsExist(announcementConf) {
|
||||
data, err := os.ReadFile(announcementConf)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read announcement conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &existingAnnouncements); nil != err {
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &existingAnnouncements); err != nil {
|
||||
logging.LogErrorf("unmarshal announcement conf failed: %s", err)
|
||||
os.Remove(announcementConf)
|
||||
return
|
||||
|
|
@ -316,11 +316,11 @@ func refreshAnnouncement() {
|
|||
}
|
||||
|
||||
data, err := gulu.JSON.MarshalJSON(existingAnnouncements)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("marshal announcement conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
if err = os.WriteFile(announcementConf, data, 0644); nil != err {
|
||||
if err = os.WriteFile(announcementConf, data, 0644); err != nil {
|
||||
logging.LogErrorf("write announcement conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -342,7 +342,7 @@ func RefreshUser(token string) {
|
|||
|
||||
var tokenExpireTime int64
|
||||
tokenExpireTime, err := strconv.ParseInt(Conf.GetUser().UserTokenExpireTime+"000", 10, 64)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("convert token expire time [%s] failed: %s", Conf.GetUser().UserTokenExpireTime, err)
|
||||
util.PushErrMsg(Conf.Language(19), 5000)
|
||||
return
|
||||
|
|
@ -366,7 +366,7 @@ Net:
|
|||
|
||||
var tokenExpireTime int64
|
||||
tokenExpireTime, err = strconv.ParseInt(Conf.GetUser().UserTokenExpireTime+"000", 10, 64)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("convert token expire time [%s] failed: %s", Conf.GetUser().UserTokenExpireTime, err)
|
||||
util.PushErrMsg(Conf.Language(19), 5000)
|
||||
return
|
||||
|
|
@ -398,7 +398,7 @@ func loadUserFromConf() *conf.User {
|
|||
data := util.AESDecrypt(Conf.UserData)
|
||||
data, _ = hex.DecodeString(string(data))
|
||||
user := &conf.User{}
|
||||
if err := gulu.JSON.UnmarshalJSON(data, &user); nil == err {
|
||||
if err := gulu.JSON.UnmarshalJSON(data, &user); err == nil {
|
||||
return user
|
||||
}
|
||||
return nil
|
||||
|
|
@ -415,7 +415,7 @@ func RemoveCloudShorthands(ids []string) (err error) {
|
|||
SetCookies(&http.Cookie{Name: "symphony", Value: Conf.GetUser().UserToken}).
|
||||
SetBody(body).
|
||||
Post(util.GetCloudServer() + "/apis/siyuan/inbox/removeCloudShorthands")
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("remove cloud shorthands failed: %s", err)
|
||||
err = ErrFailedToConnectCloudServer
|
||||
return
|
||||
|
|
@ -442,7 +442,7 @@ func GetCloudShorthand(id string) (ret map[string]interface{}, err error) {
|
|||
SetSuccessResult(&result).
|
||||
SetCookies(&http.Cookie{Name: "symphony", Value: Conf.GetUser().UserToken}).
|
||||
Post(util.GetCloudServer() + "/apis/siyuan/inbox/getCloudShorthand?id=" + id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("get cloud shorthand failed: %s", err)
|
||||
err = ErrFailedToConnectCloudServer
|
||||
return
|
||||
|
|
@ -482,7 +482,7 @@ func GetCloudShorthands(page int) (result map[string]interface{}, err error) {
|
|||
SetSuccessResult(&result).
|
||||
SetCookies(&http.Cookie{Name: "symphony", Value: Conf.GetUser().UserToken}).
|
||||
Post(util.GetCloudServer() + "/apis/siyuan/inbox/getCloudShorthands?p=" + strconv.Itoa(page))
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("get cloud shorthands failed: %s", err)
|
||||
err = ErrFailedToConnectCloudServer
|
||||
return
|
||||
|
|
@ -538,7 +538,7 @@ func getUser(token string) (*conf.User, error) {
|
|||
SetSuccessResult(&result).
|
||||
SetBody(map[string]string{"token": token}).
|
||||
Post(util.GetCloudServer() + "/apis/siyuan/user")
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("get community user failed: %s", err)
|
||||
return nil, errors.New(Conf.Language(18))
|
||||
}
|
||||
|
|
@ -559,7 +559,7 @@ func getUser(token string) (*conf.User, error) {
|
|||
dataStr := result["data"].(string)
|
||||
data := util.AESDecrypt(dataStr)
|
||||
user := &conf.User{}
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &user); nil != err {
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &user); err != nil {
|
||||
logging.LogErrorf("get community user failed: %s", err)
|
||||
return nil, errors.New(Conf.Language(18))
|
||||
}
|
||||
|
|
@ -576,7 +576,7 @@ func UseActivationcode(code string) (err error) {
|
|||
SetBody(map[string]string{"data": code}).
|
||||
SetCookies(&http.Cookie{Name: "symphony", Value: Conf.GetUser().UserToken}).
|
||||
Post(util.GetCloudServer() + "/apis/siyuan/useActivationcode")
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("check activation code failed: %s", err)
|
||||
return ErrFailedToConnectCloudServer
|
||||
}
|
||||
|
|
@ -601,7 +601,7 @@ func CheckActivationcode(code string) (retCode int, msg string) {
|
|||
SetBody(map[string]string{"data": code}).
|
||||
SetCookies(&http.Cookie{Name: "symphony", Value: Conf.GetUser().UserToken}).
|
||||
Post(util.GetCloudServer() + "/apis/siyuan/checkActivationcode")
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("check activation code failed: %s", err)
|
||||
msg = ErrFailedToConnectCloudServer.Error()
|
||||
return
|
||||
|
|
@ -629,7 +629,7 @@ func Login(userName, password, captcha string, cloudRegion int) (ret *gulu.Resul
|
|||
SetSuccessResult(&result).
|
||||
SetBody(map[string]string{"userName": userName, "userPassword": password, "captcha": captcha}).
|
||||
Post(util.GetCloudServer() + "/apis/siyuan/login")
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("login failed: %s", err)
|
||||
ret = gulu.Ret.NewResult()
|
||||
ret.Code = -1
|
||||
|
|
@ -667,7 +667,7 @@ func Login2fa(token, code string) (map[string]interface{}, error) {
|
|||
SetBody(map[string]string{"twofactorAuthCode": code}).
|
||||
SetHeader("token", token).
|
||||
Post(util.GetCloudServer() + "/apis/siyuan/login/2fa")
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("login 2fa failed: %s", err)
|
||||
return nil, errors.New(Conf.Language(18))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ func InitConf() {
|
|||
Conf = &AppConf{LogLevel: "debug", m: &sync.Mutex{}}
|
||||
confPath := filepath.Join(util.ConfDir, "conf.json")
|
||||
if gulu.File.IsExist(confPath) {
|
||||
if data, err := os.ReadFile(confPath); nil != err {
|
||||
if data, err := os.ReadFile(confPath); err != nil {
|
||||
logging.LogErrorf("load conf [%s] failed: %s", confPath, err)
|
||||
} else {
|
||||
if err = gulu.JSON.UnmarshalJSON(data, Conf); err != nil {
|
||||
|
|
@ -146,10 +146,10 @@ func InitConf() {
|
|||
if "" == Conf.Lang {
|
||||
// 未指定外观语言时使用系统语言
|
||||
|
||||
if userLang, err := locale.Detect(); nil == err {
|
||||
if userLang, err := locale.Detect(); err == nil {
|
||||
var supportLangs []language.Tag
|
||||
for lang := range util.Langs {
|
||||
if tag, err := language.Parse(lang); nil == err {
|
||||
if tag, err := language.Parse(lang); err == nil {
|
||||
supportLangs = append(supportLangs, tag)
|
||||
} else {
|
||||
logging.LogErrorf("load language [%s] failed: %s", lang, err)
|
||||
|
|
@ -367,7 +367,7 @@ func InitConf() {
|
|||
}
|
||||
if timingEnv := os.Getenv("SIYUAN_SYNC_INDEX_TIMING"); "" != timingEnv {
|
||||
val, err := strconv.Atoi(timingEnv)
|
||||
if nil == err {
|
||||
if err == nil {
|
||||
Conf.Repo.SyncIndexTiming = int64(val)
|
||||
}
|
||||
}
|
||||
|
|
@ -504,7 +504,7 @@ func InitConf() {
|
|||
func initLang() {
|
||||
p := filepath.Join(util.WorkingDir, "appearance", "langs")
|
||||
dir, err := os.Open(p)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("open language configuration folder [%s] failed: %s", p, err)
|
||||
util.ReportFileSysFatalError(err)
|
||||
return
|
||||
|
|
@ -512,7 +512,7 @@ func initLang() {
|
|||
defer dir.Close()
|
||||
|
||||
langNames, err := dir.Readdirnames(-1)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("list language configuration folder [%s] failed: %s", p, err)
|
||||
util.ReportFileSysFatalError(err)
|
||||
return
|
||||
|
|
@ -521,12 +521,12 @@ func initLang() {
|
|||
for _, langName := range langNames {
|
||||
jsonPath := filepath.Join(p, langName)
|
||||
data, err := os.ReadFile(jsonPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read language configuration [%s] failed: %s", jsonPath, err)
|
||||
continue
|
||||
}
|
||||
langMap := map[string]interface{}{}
|
||||
if err := gulu.JSON.UnmarshalJSON(data, &langMap); nil != err {
|
||||
if err := gulu.JSON.UnmarshalJSON(data, &langMap); err != nil {
|
||||
logging.LogErrorf("parse language configuration failed [%s] failed: %s", jsonPath, err)
|
||||
continue
|
||||
}
|
||||
|
|
@ -639,7 +639,7 @@ func Close(force, setCurrentWorkspace bool, execInstallPkg int) (exitCode int) {
|
|||
// 将当前工作空间放到工作空间列表的最后一个
|
||||
// Open the last workspace by default https://github.com/siyuan-note/siyuan/issues/10570
|
||||
workspacePaths, err := util.ReadWorkspacePaths()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read workspace paths failed: %s", err)
|
||||
} else {
|
||||
workspacePaths = gulu.Str.RemoveElem(workspacePaths, util.WorkspaceDir)
|
||||
|
|
@ -697,7 +697,7 @@ func (conf *AppConf) Save() {
|
|||
newData, _ := gulu.JSON.MarshalIndentJSON(Conf, "", " ")
|
||||
confPath := filepath.Join(util.ConfDir, "conf.json")
|
||||
oldData, err := filelock.ReadFile(confPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
conf.save0(newData)
|
||||
return
|
||||
}
|
||||
|
|
@ -711,7 +711,7 @@ func (conf *AppConf) Save() {
|
|||
|
||||
func (conf *AppConf) save0(data []byte) {
|
||||
confPath := filepath.Join(util.ConfDir, "conf.json")
|
||||
if err := filelock.WriteFile(confPath, data); nil != err {
|
||||
if err := filelock.WriteFile(confPath, data); err != nil {
|
||||
logging.LogErrorf("write conf [%s] failed: %s", confPath, err)
|
||||
util.ReportFileSysFatalError(err)
|
||||
return
|
||||
|
|
@ -758,7 +758,7 @@ func (conf *AppConf) BoxNames(boxIDs []string) (ret map[string]string) {
|
|||
func (conf *AppConf) GetBoxes() (ret []*Box) {
|
||||
ret = []*Box{}
|
||||
notebooks, err := ListNotebooks()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -775,7 +775,7 @@ func (conf *AppConf) GetBoxes() (ret []*Box) {
|
|||
func (conf *AppConf) GetOpenedBoxes() (ret []*Box) {
|
||||
ret = []*Box{}
|
||||
notebooks, err := ListNotebooks()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -790,7 +790,7 @@ func (conf *AppConf) GetOpenedBoxes() (ret []*Box) {
|
|||
func (conf *AppConf) GetClosedBoxes() (ret []*Box) {
|
||||
ret = []*Box{}
|
||||
notebooks, err := ListNotebooks()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -829,7 +829,7 @@ func InitBoxes() {
|
|||
}
|
||||
|
||||
var dbSize string
|
||||
if dbFile, err := os.Stat(util.DBPath); nil == err {
|
||||
if dbFile, err := os.Stat(util.DBPath); err == nil {
|
||||
dbSize = humanize.BytesCustomCeil(uint64(dbFile.Size()), 2)
|
||||
}
|
||||
logging.LogInfof("database size [%s], tree/block count [%d/%d]", dbSize, treenode.CountTrees(), treenode.CountBlocks())
|
||||
|
|
@ -862,12 +862,12 @@ const (
|
|||
func GetMaskedConf() (ret *AppConf, err error) {
|
||||
// 脱敏处理
|
||||
data, err := gulu.JSON.MarshalIndentJSON(Conf, "", " ")
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("marshal conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
ret = &AppConf{}
|
||||
if err = gulu.JSON.UnmarshalJSON(data, ret); nil != err {
|
||||
if err = gulu.JSON.UnmarshalJSON(data, ret); err != nil {
|
||||
logging.LogErrorf("unmarshal conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -906,20 +906,20 @@ func clearPortJSON() {
|
|||
|
||||
if gulu.File.IsExist(portJSON) {
|
||||
data, err = os.ReadFile(portJSON)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogWarnf("read port.json failed: %s", err)
|
||||
} else {
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &pidPorts); nil != err {
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &pidPorts); err != nil {
|
||||
logging.LogWarnf("unmarshal port.json failed: %s", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
delete(pidPorts, pid)
|
||||
if data, err = gulu.JSON.MarshalIndentJSON(pidPorts, "", " "); nil != err {
|
||||
if data, err = gulu.JSON.MarshalIndentJSON(pidPorts, "", " "); err != nil {
|
||||
logging.LogWarnf("marshal port.json failed: %s", err)
|
||||
} else {
|
||||
if err = os.WriteFile(portJSON, data, 0644); nil != err {
|
||||
if err = os.WriteFile(portJSON, data, 0644); err != nil {
|
||||
logging.LogWarnf("write port.json failed: %s", err)
|
||||
}
|
||||
}
|
||||
|
|
@ -929,7 +929,7 @@ func clearCorruptedNotebooks() {
|
|||
// 数据同步时展开文档树操作可能导致数据丢失 https://github.com/siyuan-note/siyuan/issues/7129
|
||||
|
||||
dirs, err := os.ReadDir(util.DataDir)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read dir [%s] failed: %s", util.DataDir, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -970,13 +970,13 @@ func clearWorkspaceTemp() {
|
|||
if gulu.File.IsDir(install) {
|
||||
monthAgo := time.Now().Add(-time.Hour * 24 * 7)
|
||||
entries, err := os.ReadDir(install)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read dir [%s] failed: %s", install, err)
|
||||
} else {
|
||||
for _, entry := range entries {
|
||||
info, _ := entry.Info()
|
||||
if nil != info && !info.IsDir() && info.ModTime().Before(monthAgo) {
|
||||
if err = os.RemoveAll(filepath.Join(install, entry.Name())); nil != err {
|
||||
if err = os.RemoveAll(filepath.Join(install, entry.Name())); err != nil {
|
||||
logging.LogErrorf("remove old install pkg [%s] failed: %s", filepath.Join(install, entry.Name()), err)
|
||||
}
|
||||
}
|
||||
|
|
@ -985,11 +985,11 @@ func clearWorkspaceTemp() {
|
|||
}
|
||||
|
||||
tmps, err := filepath.Glob(filepath.Join(util.TempDir, "*.tmp"))
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("glob temp files failed: %s", err)
|
||||
}
|
||||
for _, tmp := range tmps {
|
||||
if err = os.RemoveAll(tmp); nil != err {
|
||||
if err = os.RemoveAll(tmp); err != nil {
|
||||
logging.LogErrorf("remove temp file [%s] failed: %s", tmp, err)
|
||||
} else {
|
||||
logging.LogInfof("removed temp file [%s]", tmp)
|
||||
|
|
@ -997,11 +997,11 @@ func clearWorkspaceTemp() {
|
|||
}
|
||||
|
||||
tmps, err = filepath.Glob(filepath.Join(util.DataDir, ".siyuan", "*.tmp"))
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("glob temp files failed: %s", err)
|
||||
}
|
||||
for _, tmp := range tmps {
|
||||
if err = os.RemoveAll(tmp); nil != err {
|
||||
if err = os.RemoveAll(tmp); err != nil {
|
||||
logging.LogErrorf("remove temp file [%s] failed: %s", tmp, err)
|
||||
} else {
|
||||
logging.LogInfof("removed temp file [%s]", tmp)
|
||||
|
|
@ -1022,7 +1022,7 @@ func closeUserGuide() {
|
|||
defer logging.Recover()
|
||||
|
||||
dirs, err := os.ReadDir(util.DataDir)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read dir [%s] failed: %s", util.DataDir, err)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ func watchEmojis() {
|
|||
}
|
||||
|
||||
var err error
|
||||
if emojisWatcher, err = fsnotify.NewWatcher(); nil != err {
|
||||
if emojisWatcher, err = fsnotify.NewWatcher(); err != nil {
|
||||
logging.LogErrorf("add emojis watcher for folder [%s] failed: %s", emojisDir, err)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,13 +62,13 @@ func watchEmojis() {
|
|||
}
|
||||
}()
|
||||
|
||||
if err := emojisWatcher.Add(emojisDir); nil != err {
|
||||
if err := emojisWatcher.Add(emojisDir); err != nil {
|
||||
logging.LogErrorf("add emojis watcher for folder [%s] failed: %s", emojisDir, err)
|
||||
return
|
||||
}
|
||||
|
||||
//logging.LogInfof("added file watcher [%s]", emojisDir)
|
||||
if err := emojisWatcher.Start(10 * time.Second); nil != err {
|
||||
if err := emojisWatcher.Start(10 * time.Second); err != nil {
|
||||
logging.LogErrorf("start emojis watcher for folder [%s] failed: %s", emojisDir, err)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,7 +61,7 @@ func ExportAv2CSV(avID, blockID string) (zipPath string, err error) {
|
|||
// Database block supports export as CSV https://github.com/siyuan-note/siyuan/issues/10072
|
||||
|
||||
attrView, err := av.ParseAttributeView(avID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -71,7 +71,7 @@ func ExportAv2CSV(avID, blockID string) (zipPath string, err error) {
|
|||
}
|
||||
viewID := node.IALAttr(av.NodeAttrView)
|
||||
view, err := attrView.GetCurrentView(viewID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -83,19 +83,19 @@ func ExportAv2CSV(avID, blockID string) (zipPath string, err error) {
|
|||
table.SortRows(attrView)
|
||||
|
||||
exportFolder := filepath.Join(util.TempDir, "export", "csv", name)
|
||||
if err = os.MkdirAll(exportFolder, 0755); nil != err {
|
||||
if err = os.MkdirAll(exportFolder, 0755); err != nil {
|
||||
logging.LogErrorf("mkdir [%s] failed: %s", exportFolder, err)
|
||||
return
|
||||
}
|
||||
csvPath := filepath.Join(exportFolder, name+".csv")
|
||||
|
||||
f, err := os.OpenFile(csvPath, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0644)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("open [%s] failed: %s", csvPath, err)
|
||||
return
|
||||
}
|
||||
|
||||
if _, err = f.WriteString("\xEF\xBB\xBF"); nil != err { // 写入 UTF-8 BOM,避免使用 Microsoft Excel 打开乱码
|
||||
if _, err = f.WriteString("\xEF\xBB\xBF"); err != nil { // 写入 UTF-8 BOM,避免使用 Microsoft Excel 打开乱码
|
||||
logging.LogErrorf("write UTF-8 BOM to [%s] failed: %s", csvPath, err)
|
||||
f.Close()
|
||||
return
|
||||
|
|
@ -106,7 +106,7 @@ func ExportAv2CSV(avID, blockID string) (zipPath string, err error) {
|
|||
for _, col := range table.Columns {
|
||||
header = append(header, col.Name)
|
||||
}
|
||||
if err = writer.Write(header); nil != err {
|
||||
if err = writer.Write(header); err != nil {
|
||||
logging.LogErrorf("write csv header [%s] failed: %s", header, err)
|
||||
f.Close()
|
||||
return
|
||||
|
|
@ -164,7 +164,7 @@ func ExportAv2CSV(avID, blockID string) (zipPath string, err error) {
|
|||
|
||||
rowVal = append(rowVal, val)
|
||||
}
|
||||
if err = writer.Write(rowVal); nil != err {
|
||||
if err = writer.Write(rowVal); err != nil {
|
||||
logging.LogErrorf("write csv row [%s] failed: %s", rowVal, err)
|
||||
f.Close()
|
||||
return
|
||||
|
|
@ -175,19 +175,19 @@ func ExportAv2CSV(avID, blockID string) (zipPath string, err error) {
|
|||
|
||||
zipPath = exportFolder + ".db.zip"
|
||||
zip, err := gulu.Zip.Create(zipPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("create export .db.zip [%s] failed: %s", exportFolder, err)
|
||||
f.Close()
|
||||
return
|
||||
}
|
||||
|
||||
if err = zip.AddDirectory("", exportFolder); nil != err {
|
||||
if err = zip.AddDirectory("", exportFolder); err != nil {
|
||||
logging.LogErrorf("create export .db.zip [%s] failed: %s", exportFolder, err)
|
||||
f.Close()
|
||||
return
|
||||
}
|
||||
|
||||
if err = zip.Close(); nil != err {
|
||||
if err = zip.Close(); err != nil {
|
||||
logging.LogErrorf("close export .db.zip failed: %s", err)
|
||||
f.Close()
|
||||
return
|
||||
|
|
@ -204,7 +204,7 @@ func ExportAv2CSV(avID, blockID string) (zipPath string, err error) {
|
|||
|
||||
func Export2Liandi(id string) (err error) {
|
||||
tree, err := LoadTreeByBlockID(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("load tree by block id [%s] failed: %s", id, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -221,7 +221,7 @@ func Export2Liandi(id string) (err error) {
|
|||
assets = append(assets, avAssets...)
|
||||
assets = gulu.Str.RemoveDuplicatedElem(assets)
|
||||
_, err = uploadAssets2Cloud(assets, bizTypeExport2Liandi)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -309,7 +309,7 @@ func Export2Liandi(id string) (err error) {
|
|||
articleId = result.Data.(string)
|
||||
tree, _ = LoadTreeByBlockID(id) // 这里必须重新加载,因为前面导出时已经修改了树结构
|
||||
tree.Root.SetIALAttr(liandiArticleIdAttrName, articleId)
|
||||
if err = writeTreeUpsertQueue(tree); nil != err {
|
||||
if err = writeTreeUpsertQueue(tree); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -322,7 +322,7 @@ func Export2Liandi(id string) (err error) {
|
|||
func ExportSystemLog() (zipPath string) {
|
||||
exportFolder := filepath.Join(util.TempDir, "export", "system-log")
|
||||
os.RemoveAll(exportFolder)
|
||||
if err := os.MkdirAll(exportFolder, 0755); nil != err {
|
||||
if err := os.MkdirAll(exportFolder, 0755); err != nil {
|
||||
logging.LogErrorf("create export temp folder failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -330,7 +330,7 @@ func ExportSystemLog() (zipPath string) {
|
|||
appLog := filepath.Join(util.HomeDir, ".config", "siyuan", "app.log")
|
||||
if gulu.File.IsExist(appLog) {
|
||||
to := filepath.Join(exportFolder, "app.log")
|
||||
if err := filelock.Copy(appLog, to); nil != err {
|
||||
if err := filelock.Copy(appLog, to); err != nil {
|
||||
logging.LogErrorf("copy app log from [%s] to [%s] failed: %s", err, appLog, to)
|
||||
}
|
||||
}
|
||||
|
|
@ -338,7 +338,7 @@ func ExportSystemLog() (zipPath string) {
|
|||
kernelLog := filepath.Join(util.HomeDir, ".config", "siyuan", "kernel.log")
|
||||
if gulu.File.IsExist(kernelLog) {
|
||||
to := filepath.Join(exportFolder, "kernel.log")
|
||||
if err := filelock.Copy(kernelLog, to); nil != err {
|
||||
if err := filelock.Copy(kernelLog, to); err != nil {
|
||||
logging.LogErrorf("copy kernel log from [%s] to [%s] failed: %s", err, kernelLog, to)
|
||||
}
|
||||
}
|
||||
|
|
@ -346,7 +346,7 @@ func ExportSystemLog() (zipPath string) {
|
|||
siyuanLog := filepath.Join(util.TempDir, "siyuan.log")
|
||||
if gulu.File.IsExist(siyuanLog) {
|
||||
to := filepath.Join(exportFolder, "siyuan.log")
|
||||
if err := filelock.Copy(siyuanLog, to); nil != err {
|
||||
if err := filelock.Copy(siyuanLog, to); err != nil {
|
||||
logging.LogErrorf("copy kernel log from [%s] to [%s] failed: %s", err, siyuanLog, to)
|
||||
}
|
||||
}
|
||||
|
|
@ -354,24 +354,24 @@ func ExportSystemLog() (zipPath string) {
|
|||
mobileLog := filepath.Join(util.TempDir, "mobile.log")
|
||||
if gulu.File.IsExist(mobileLog) {
|
||||
to := filepath.Join(exportFolder, "mobile.log")
|
||||
if err := filelock.Copy(mobileLog, to); nil != err {
|
||||
if err := filelock.Copy(mobileLog, to); err != nil {
|
||||
logging.LogErrorf("copy mobile log from [%s] to [%s] failed: %s", err, mobileLog, to)
|
||||
}
|
||||
}
|
||||
|
||||
zipPath = exportFolder + ".zip"
|
||||
zip, err := gulu.Zip.Create(zipPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("create export log zip [%s] failed: %s", exportFolder, err)
|
||||
return ""
|
||||
}
|
||||
|
||||
if err = zip.AddDirectory("log", exportFolder); nil != err {
|
||||
if err = zip.AddDirectory("log", exportFolder); err != nil {
|
||||
logging.LogErrorf("create export log zip [%s] failed: %s", exportFolder, err)
|
||||
return ""
|
||||
}
|
||||
|
||||
if err = zip.Close(); nil != err {
|
||||
if err = zip.Close(); err != nil {
|
||||
logging.LogErrorf("close export log zip failed: %s", err)
|
||||
}
|
||||
|
||||
|
|
@ -414,12 +414,12 @@ func ExportDataInFolder(exportFolder string) (name string, err error) {
|
|||
defer util.ClearPushProgress(100)
|
||||
|
||||
zipPath, err := ExportData()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
name = filepath.Base(zipPath)
|
||||
name, err = url.PathUnescape(name)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("url unescape [%s] failed: %s", name, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -427,7 +427,7 @@ func ExportDataInFolder(exportFolder string) (name string, err error) {
|
|||
targetZipPath := filepath.Join(exportFolder, name)
|
||||
zipAbsPath := filepath.Join(util.TempDir, "export", name)
|
||||
err = filelock.Copy(zipAbsPath, targetZipPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("copy export zip from [%s] to [%s] failed: %s", zipAbsPath, targetZipPath, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -444,7 +444,7 @@ func ExportData() (zipPath string, err error) {
|
|||
name := util.FilterFileName(filepath.Base(util.WorkspaceDir)) + "-" + util.CurrentTimeSecondsStr()
|
||||
exportFolder := filepath.Join(util.TempDir, "export", name)
|
||||
zipPath, err = exportData(exportFolder)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
zipPath = "/export/" + url.PathEscape(filepath.Base(zipPath))
|
||||
|
|
@ -455,13 +455,13 @@ func exportData(exportFolder string) (zipPath string, err error) {
|
|||
WaitForWritingFiles()
|
||||
|
||||
baseFolderName := "data-" + util.CurrentTimeSecondsStr()
|
||||
if err = os.MkdirAll(exportFolder, 0755); nil != err {
|
||||
if err = os.MkdirAll(exportFolder, 0755); err != nil {
|
||||
logging.LogErrorf("create export temp folder failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
data := filepath.Join(util.WorkspaceDir, "data")
|
||||
if err = filelock.Copy(data, exportFolder); nil != err {
|
||||
if err = filelock.Copy(data, exportFolder); err != nil {
|
||||
logging.LogErrorf("copy data dir from [%s] to [%s] failed: %s", data, baseFolderName, err)
|
||||
err = errors.New(fmt.Sprintf(Conf.Language(14), err.Error()))
|
||||
return
|
||||
|
|
@ -469,7 +469,7 @@ func exportData(exportFolder string) (zipPath string, err error) {
|
|||
|
||||
zipPath = exportFolder + ".zip"
|
||||
zip, err := gulu.Zip.Create(zipPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("create export data zip [%s] failed: %s", exportFolder, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -479,12 +479,12 @@ func exportData(exportFolder string) (zipPath string, err error) {
|
|||
util.PushEndlessProgress(msg)
|
||||
}
|
||||
|
||||
if err = zip.AddDirectory(baseFolderName, exportFolder, zipCallback); nil != err {
|
||||
if err = zip.AddDirectory(baseFolderName, exportFolder, zipCallback); err != nil {
|
||||
logging.LogErrorf("create export data zip [%s] failed: %s", exportFolder, err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = zip.Close(); nil != err {
|
||||
if err = zip.Close(); err != nil {
|
||||
logging.LogErrorf("close export data zip failed: %s", err)
|
||||
}
|
||||
|
||||
|
|
@ -497,7 +497,7 @@ func ExportResources(resourcePaths []string, mainName string) (exportFilePath st
|
|||
|
||||
// 用于导出的临时文件夹完整路径
|
||||
exportFolderPath := filepath.Join(util.TempDir, "export", mainName)
|
||||
if err = os.MkdirAll(exportFolderPath, 0755); nil != err {
|
||||
if err = os.MkdirAll(exportFolderPath, 0755); err != nil {
|
||||
logging.LogErrorf("create export temp folder failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -507,7 +507,7 @@ func ExportResources(resourcePaths []string, mainName string) (exportFilePath st
|
|||
resourceFullPath := filepath.Join(util.WorkspaceDir, resourcePath) // 资源完整路径
|
||||
resourceBaseName := filepath.Base(resourceFullPath) // 资源名称
|
||||
resourceCopyPath := filepath.Join(exportFolderPath, resourceBaseName) // 资源副本完整路径
|
||||
if err = filelock.Copy(resourceFullPath, resourceCopyPath); nil != err {
|
||||
if err = filelock.Copy(resourceFullPath, resourceCopyPath); err != nil {
|
||||
logging.LogErrorf("copy resource will be exported from [%s] to [%s] failed: %s", resourcePath, resourceCopyPath, err)
|
||||
err = fmt.Errorf(Conf.Language(14), err.Error())
|
||||
return
|
||||
|
|
@ -516,17 +516,17 @@ func ExportResources(resourcePaths []string, mainName string) (exportFilePath st
|
|||
|
||||
zipFilePath := exportFolderPath + ".zip" // 导出的 *.zip 文件完整路径
|
||||
zip, err := gulu.Zip.Create(zipFilePath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("create export zip [%s] failed: %s", zipFilePath, err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = zip.AddDirectory(mainName, exportFolderPath); nil != err {
|
||||
if err = zip.AddDirectory(mainName, exportFolderPath); err != nil {
|
||||
logging.LogErrorf("create export zip [%s] failed: %s", exportFolderPath, err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = zip.Close(); nil != err {
|
||||
if err = zip.Close(); err != nil {
|
||||
logging.LogErrorf("close export zip failed: %s", err)
|
||||
}
|
||||
|
||||
|
|
@ -570,7 +570,7 @@ func ExportDocx(id, savePath string, removeAssets, merge bool) (fullPath string,
|
|||
}
|
||||
|
||||
tmpDir := filepath.Join(util.TempDir, "export", gulu.Rand.String(7))
|
||||
if err = os.MkdirAll(tmpDir, 0755); nil != err {
|
||||
if err = os.MkdirAll(tmpDir, 0755); err != nil {
|
||||
return
|
||||
}
|
||||
defer os.Remove(tmpDir)
|
||||
|
|
@ -601,7 +601,7 @@ func ExportDocx(id, savePath string, removeAssets, merge bool) (fullPath string,
|
|||
gulu.CmdAttr(pandoc)
|
||||
pandoc.Stdin = bytes.NewBufferString(content)
|
||||
output, err := pandoc.CombinedOutput()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("export docx failed: %s", gulu.Str.FromBytes(output))
|
||||
msg := fmt.Sprintf(Conf.Language(14), gulu.Str.FromBytes(output))
|
||||
err = errors.New(msg)
|
||||
|
|
@ -610,14 +610,14 @@ func ExportDocx(id, savePath string, removeAssets, merge bool) (fullPath string,
|
|||
|
||||
fullPath = filepath.Join(savePath, name+".docx")
|
||||
fullPath = util.GetUniqueFilename(fullPath)
|
||||
if err = filelock.Copy(tmpDocxPath, fullPath); nil != err {
|
||||
if err = filelock.Copy(tmpDocxPath, fullPath); err != nil {
|
||||
logging.LogErrorf("export docx failed: %s", err)
|
||||
err = errors.New(fmt.Sprintf(Conf.Language(14), err))
|
||||
return
|
||||
}
|
||||
|
||||
if tmpAssets := filepath.Join(tmpDir, "assets"); !removeAssets && gulu.File.IsDir(tmpAssets) {
|
||||
if err = filelock.Copy(tmpAssets, filepath.Join(savePath, "assets")); nil != err {
|
||||
if err = filelock.Copy(tmpAssets, filepath.Join(savePath, "assets")); err != nil {
|
||||
logging.LogErrorf("export docx failed: %s", err)
|
||||
err = errors.New(fmt.Sprintf(Conf.Language(14), err))
|
||||
return
|
||||
|
|
@ -652,7 +652,7 @@ func ExportMarkdownHTML(id, savePath string, docx, merge bool) (name, dom string
|
|||
name = util.FilterFileName(name) // 导出 PDF、HTML 和 Word 时未移除不支持的文件名符号 https://github.com/siyuan-note/siyuan/issues/5614
|
||||
savePath = strings.TrimSpace(savePath)
|
||||
|
||||
if err := os.MkdirAll(savePath, 0755); nil != err {
|
||||
if err := os.MkdirAll(savePath, 0755); err != nil {
|
||||
logging.LogErrorf("mkdir [%s] failed: %s", savePath, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -665,12 +665,12 @@ func ExportMarkdownHTML(id, savePath string, docx, merge bool) (name, dom string
|
|||
}
|
||||
|
||||
srcAbsPath, err := GetAssetAbsPath(asset)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogWarnf("resolve path of asset [%s] failed: %s", asset, err)
|
||||
continue
|
||||
}
|
||||
targetAbsPath := filepath.Join(savePath, asset)
|
||||
if err = filelock.Copy(srcAbsPath, targetAbsPath); nil != err {
|
||||
if err = filelock.Copy(srcAbsPath, targetAbsPath); err != nil {
|
||||
logging.LogWarnf("copy asset from [%s] to [%s] failed: %s", srcAbsPath, targetAbsPath, err)
|
||||
}
|
||||
}
|
||||
|
|
@ -680,7 +680,7 @@ func ExportMarkdownHTML(id, savePath string, docx, merge bool) (name, dom string
|
|||
for _, src := range srcs {
|
||||
from := filepath.Join(util.WorkingDir, src)
|
||||
to := filepath.Join(savePath, src)
|
||||
if err := filelock.Copy(from, to); nil != err {
|
||||
if err := filelock.Copy(from, to); err != nil {
|
||||
logging.LogWarnf("copy stage from [%s] to [%s] failed: %s", from, savePath, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -705,7 +705,7 @@ func ExportMarkdownHTML(id, savePath string, docx, merge bool) (name, dom string
|
|||
for _, src := range srcs {
|
||||
from := filepath.Join(appearancePath, src)
|
||||
to := filepath.Join(savePath, "appearance", src)
|
||||
if err := filelock.Copy(from, to); nil != err {
|
||||
if err := filelock.Copy(from, to); err != nil {
|
||||
logging.LogErrorf("copy appearance from [%s] to [%s] failed: %s", from, savePath, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -716,7 +716,7 @@ func ExportMarkdownHTML(id, savePath string, docx, merge bool) (name, dom string
|
|||
for _, emoji := range emojis {
|
||||
from := filepath.Join(util.DataDir, emoji)
|
||||
to := filepath.Join(savePath, emoji)
|
||||
if err := filelock.Copy(from, to); nil != err {
|
||||
if err := filelock.Copy(from, to); err != nil {
|
||||
logging.LogErrorf("copy emojis from [%s] to [%s] failed: %s", from, savePath, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -802,7 +802,7 @@ func ExportHTML(id, savePath string, pdf, image, keepFold, merge bool) (name, do
|
|||
name = util.FilterFileName(name) // 导出 PDF、HTML 和 Word 时未移除不支持的文件名符号 https://github.com/siyuan-note/siyuan/issues/5614
|
||||
|
||||
if "" != savePath {
|
||||
if err := os.MkdirAll(savePath, 0755); nil != err {
|
||||
if err := os.MkdirAll(savePath, 0755); err != nil {
|
||||
logging.LogErrorf("mkdir [%s] failed: %s", savePath, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -814,12 +814,12 @@ func ExportHTML(id, savePath string, pdf, image, keepFold, merge bool) (name, do
|
|||
}
|
||||
|
||||
srcAbsPath, err := GetAssetAbsPath(asset)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogWarnf("resolve path of asset [%s] failed: %s", asset, err)
|
||||
continue
|
||||
}
|
||||
targetAbsPath := filepath.Join(savePath, asset)
|
||||
if err = filelock.Copy(srcAbsPath, targetAbsPath); nil != err {
|
||||
if err = filelock.Copy(srcAbsPath, targetAbsPath); err != nil {
|
||||
logging.LogWarnf("copy asset from [%s] to [%s] failed: %s", srcAbsPath, targetAbsPath, err)
|
||||
}
|
||||
}
|
||||
|
|
@ -831,7 +831,7 @@ func ExportHTML(id, savePath string, pdf, image, keepFold, merge bool) (name, do
|
|||
for _, src := range srcs {
|
||||
from := filepath.Join(util.WorkingDir, src)
|
||||
to := filepath.Join(savePath, src)
|
||||
if err := filelock.Copy(from, to); nil != err {
|
||||
if err := filelock.Copy(from, to); err != nil {
|
||||
logging.LogErrorf("copy stage from [%s] to [%s] failed: %s", from, savePath, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -855,7 +855,7 @@ func ExportHTML(id, savePath string, pdf, image, keepFold, merge bool) (name, do
|
|||
for _, src := range srcs {
|
||||
from := filepath.Join(appearancePath, src)
|
||||
to := filepath.Join(savePath, "appearance", src)
|
||||
if err := filelock.Copy(from, to); nil != err {
|
||||
if err := filelock.Copy(from, to); err != nil {
|
||||
logging.LogErrorf("copy appearance from [%s] to [%s] failed: %s", from, savePath, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -866,7 +866,7 @@ func ExportHTML(id, savePath string, pdf, image, keepFold, merge bool) (name, do
|
|||
for _, emoji := range emojis {
|
||||
from := filepath.Join(util.DataDir, emoji)
|
||||
to := filepath.Join(savePath, emoji)
|
||||
if err := filelock.Copy(from, to); nil != err {
|
||||
if err := filelock.Copy(from, to); err != nil {
|
||||
logging.LogErrorf("copy emojis from [%s] to [%s] failed: %s", from, savePath, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -1055,7 +1055,7 @@ func processPDFWatermark(pdfCtx *pdfcpu.Context, watermark bool) {
|
|||
|
||||
fontPath := filepath.Join(util.AppearancePath, "fonts", "LxgwWenKai-Lite-1.311", "LXGWWenKaiLite-Regular.ttf")
|
||||
err := api.InstallFonts([]string{fontPath})
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("install font [%s] failed: %s", fontPath, err)
|
||||
}
|
||||
}
|
||||
|
|
@ -1073,14 +1073,14 @@ func processPDFWatermark(pdfCtx *pdfcpu.Context, watermark bool) {
|
|||
wm, err = pdfcpu.ParsePDFWatermarkDetails(str, desc, false, pdfcpu.POINTS)
|
||||
}
|
||||
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("parse watermark failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
wm.OnTop = true // Export PDF and add watermarks no longer covered by images https://github.com/siyuan-note/siyuan/issues/10818
|
||||
err = pdfCtx.AddWatermarks(nil, wm)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("add watermark failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -1088,7 +1088,7 @@ func processPDFWatermark(pdfCtx *pdfcpu.Context, watermark bool) {
|
|||
|
||||
func processPDFBookmarks(pdfCtx *pdfcpu.Context, headings []*ast.Node) {
|
||||
links, err := api.ListToCLinks(pdfCtx)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -1148,7 +1148,7 @@ func processPDFBookmarks(pdfCtx *pdfcpu.Context, headings []*ast.Node) {
|
|||
}
|
||||
|
||||
err = pdfCtx.AddBookmarks(topBms)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("add bookmark failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -1342,7 +1342,7 @@ func processPDFLinkEmbedAssets(pdfCtx *pdfcpu.Context, assetDests []string, remo
|
|||
|
||||
func ExportStdMarkdown(id string) string {
|
||||
tree, err := LoadTreeByBlockID(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("load tree by block id [%s] failed: %s", id, err)
|
||||
return ""
|
||||
}
|
||||
|
|
@ -1503,7 +1503,7 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
|
|||
box := Conf.Box(boxID)
|
||||
|
||||
exportFolder := filepath.Join(util.TempDir, "export", baseFolderName)
|
||||
if err := os.MkdirAll(exportFolder, 0755); nil != err {
|
||||
if err := os.MkdirAll(exportFolder, 0755); err != nil {
|
||||
logging.LogErrorf("create export temp folder failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -1518,7 +1518,7 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
|
|||
|
||||
id := docIAL["id"]
|
||||
tree, err := LoadTreeByBlockID(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
trees[tree.ID] = tree
|
||||
|
|
@ -1649,7 +1649,7 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
|
|||
}
|
||||
|
||||
attrView, err := av.ParseAttributeView(avID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("parse attribute view [%s] failed: %s", avID, err)
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
|
@ -1749,7 +1749,7 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
|
|||
|
||||
zipPath = exportFolder + ".sy.zip"
|
||||
zip, err := gulu.Zip.Create(zipPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("create export .sy.zip [%s] failed: %s", exportFolder, err)
|
||||
return ""
|
||||
}
|
||||
|
|
@ -1759,12 +1759,12 @@ func exportSYZip(boxID, rootDirPath, baseFolderName string, docPaths []string) (
|
|||
util.PushEndlessProgress(msg)
|
||||
}
|
||||
|
||||
if err = zip.AddDirectory(baseFolderName, exportFolder, zipCallback); nil != err {
|
||||
if err = zip.AddDirectory(baseFolderName, exportFolder, zipCallback); err != nil {
|
||||
logging.LogErrorf("create export .sy.zip [%s] failed: %s", exportFolder, err)
|
||||
return ""
|
||||
}
|
||||
|
||||
if err = zip.Close(); nil != err {
|
||||
if err = zip.Close(); err != nil {
|
||||
logging.LogErrorf("close export .sy.zip failed: %s", err)
|
||||
}
|
||||
|
||||
|
|
@ -1819,7 +1819,7 @@ func ExportMarkdownContent(id string) (hPath, exportedMd string) {
|
|||
|
||||
func exportMarkdownContent(id string, exportRefMode int, defBlockIDs []string) (hPath, exportedMd string) {
|
||||
tree, err := LoadTreeByBlockID(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("load tree by block id [%s] failed: %s", id, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -2196,14 +2196,14 @@ func exportTree(tree *parse.Tree, wysiwyg, keepFold, avHiddenCol bool,
|
|||
}
|
||||
|
||||
attrView, err := av.ParseAttributeView(avID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("parse attribute view [%s] failed: %s", avID, err)
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
viewID := n.IALAttr(av.NodeAttrView)
|
||||
view, err := attrView.GetCurrentView(viewID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("get attribute view [%s] failed: %s", avID, err)
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
|
@ -2389,7 +2389,7 @@ func resolveFootnotesDefs(refFootnotes *[]*refAsFootnotes, rootID string, blockR
|
|||
var rendered []string
|
||||
for _, foot := range *refFootnotes {
|
||||
t, err := LoadTreeByBlockID(foot.defID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
defNode := treenode.GetNodeInTree(t, foot.defID)
|
||||
|
|
@ -2515,7 +2515,7 @@ func collectFootnotesDefs(id string, refFootnotes *[]*refAsFootnotes, treeCache
|
|||
t := (*treeCache)[b.RootID]
|
||||
if nil == t {
|
||||
var err error
|
||||
if t, err = LoadTreeByBlockID(b.ID); nil != err {
|
||||
if t, err = LoadTreeByBlockID(b.ID); err != nil {
|
||||
return
|
||||
}
|
||||
(*treeCache)[t.ID] = t
|
||||
|
|
@ -2602,7 +2602,7 @@ func exportRefTrees0(tree *parse.Tree, retTrees *map[string]*parse.Tree) {
|
|||
return ast.WalkSkipChildren
|
||||
}
|
||||
defTree, err := LoadTreeByBlockID(defBlock.RootID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return ast.WalkSkipChildren
|
||||
}
|
||||
|
||||
|
|
@ -2647,18 +2647,18 @@ func exportRefTrees0(tree *parse.Tree, retTrees *map[string]*parse.Tree) {
|
|||
func processFileAnnotationRef(refID string, n *ast.Node, fileAnnotationRefMode int) ast.WalkStatus {
|
||||
p := refID[:strings.LastIndex(refID, "/")]
|
||||
absPath, err := GetAssetAbsPath(p)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
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 {
|
||||
if err != nil {
|
||||
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 {
|
||||
if err = gulu.JSON.UnmarshalJSON(syaData, &syaJSON); err != nil {
|
||||
logging.LogErrorf("unmarshal file [%s] failed: %s", sya, err)
|
||||
return ast.WalkSkipChildren
|
||||
}
|
||||
|
|
@ -2705,7 +2705,7 @@ func exportPandocConvertZip(exportNotebook bool, boxID, baseFolderName string, d
|
|||
|
||||
exportFolder := filepath.Join(util.TempDir, "export", baseFolderName+ext)
|
||||
os.RemoveAll(exportFolder)
|
||||
if err := os.MkdirAll(exportFolder, 0755); nil != err {
|
||||
if err := os.MkdirAll(exportFolder, 0755); err != nil {
|
||||
logging.LogErrorf("create export temp folder failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -2726,7 +2726,7 @@ func exportPandocConvertZip(exportNotebook bool, boxID, baseFolderName string, d
|
|||
}
|
||||
id := docIAL["id"]
|
||||
tree, err := LoadTreeByBlockID(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
ast.Walk(tree.Root, func(n *ast.Node, entering bool) ast.WalkStatus {
|
||||
|
|
@ -2772,7 +2772,7 @@ func exportPandocConvertZip(exportNotebook bool, boxID, baseFolderName string, d
|
|||
writePath = filepath.Join(exportFolder, p)
|
||||
}
|
||||
writeFolder := filepath.Dir(writePath)
|
||||
if err := os.MkdirAll(writeFolder, 0755); nil != err {
|
||||
if err := os.MkdirAll(writeFolder, 0755); err != nil {
|
||||
logging.LogErrorf("create export temp folder [%s] failed: %s", writeFolder, err)
|
||||
continue
|
||||
}
|
||||
|
|
@ -2792,14 +2792,14 @@ func exportPandocConvertZip(exportNotebook bool, boxID, baseFolderName string, d
|
|||
}
|
||||
|
||||
srcPath, err := GetAssetAbsPath(asset)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogWarnf("get asset [%s] abs path failed: %s", asset, err)
|
||||
continue
|
||||
}
|
||||
|
||||
destPath := filepath.Join(writeFolder, asset)
|
||||
err = filelock.Copy(srcPath, destPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("copy asset from [%s] to [%s] failed: %s", srcPath, destPath, err)
|
||||
continue
|
||||
}
|
||||
|
|
@ -2807,7 +2807,7 @@ func exportPandocConvertZip(exportNotebook bool, boxID, baseFolderName string, d
|
|||
|
||||
// 调用 Pandoc 进行格式转换
|
||||
err := util.Pandoc(pandocFrom, pandocTo, writePath, md)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("pandoc failed: %s", err)
|
||||
continue
|
||||
}
|
||||
|
|
@ -2815,14 +2815,14 @@ func exportPandocConvertZip(exportNotebook bool, boxID, baseFolderName string, d
|
|||
|
||||
zipPath = exportFolder + ".zip"
|
||||
zip, err := gulu.Zip.Create(zipPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("create export markdown zip [%s] failed: %s", exportFolder, err)
|
||||
return ""
|
||||
}
|
||||
|
||||
// 导出 Markdown zip 包内不带文件夹 https://github.com/siyuan-note/siyuan/issues/6869
|
||||
entries, err := os.ReadDir(exportFolder)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read export markdown folder [%s] failed: %s", exportFolder, err)
|
||||
return ""
|
||||
}
|
||||
|
|
@ -2833,13 +2833,13 @@ func exportPandocConvertZip(exportNotebook bool, boxID, baseFolderName string, d
|
|||
} else {
|
||||
err = zip.AddEntry(entry.Name(), entryPath)
|
||||
}
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("add entry [%s] to zip failed: %s", entry.Name(), err)
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
if err = zip.Close(); nil != err {
|
||||
if err = zip.Close(); err != nil {
|
||||
logging.LogErrorf("close export markdown zip failed: %s", err)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ import (
|
|||
func mergeSubDocs(rootTree *parse.Tree) (ret *parse.Tree, err error) {
|
||||
ret = rootTree
|
||||
rootBlock := &Block{Box: rootTree.Box, ID: rootTree.ID, Path: rootTree.Path, HPath: rootTree.HPath}
|
||||
if err = buildBlockChildren(rootBlock); nil != err {
|
||||
if err = buildBlockChildren(rootBlock); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -53,7 +53,7 @@ func mergeSubDocs(rootTree *parse.Tree) (ret *parse.Tree, err error) {
|
|||
|
||||
for {
|
||||
i := 0
|
||||
if err = walkBlock(insertPoint, rootBlock, i); nil != err {
|
||||
if err = walkBlock(insertPoint, rootBlock, i); err != nil {
|
||||
return
|
||||
}
|
||||
if nil == rootBlock.Children {
|
||||
|
|
@ -67,7 +67,7 @@ func walkBlock(insertPoint *ast.Node, block *Block, level int) (err error) {
|
|||
level++
|
||||
for i := len(block.Children) - 1; i >= 0; i-- {
|
||||
c := block.Children[i]
|
||||
if err = walkBlock(insertPoint, c, level); nil != err {
|
||||
if err = walkBlock(insertPoint, c, level); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -87,7 +87,7 @@ func walkBlock(insertPoint *ast.Node, block *Block, level int) (err error) {
|
|||
func loadTreeNodes(box string, p string, level int) (ret []*ast.Node, err error) {
|
||||
luteEngine := NewLute()
|
||||
tree, err := filesys.LoadTree(box, p, luteEngine)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -112,7 +112,7 @@ func loadTreeNodes(box string, p string, level int) (ret []*ast.Node, err error)
|
|||
|
||||
func buildBlockChildren(block *Block) (err error) {
|
||||
files, _, err := ListDocTree(block.Box, block.Path, util.SortModeUnassigned, false, false, Conf.FileTree.MaxListCount)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -122,7 +122,7 @@ func buildBlockChildren(block *Block) (err error) {
|
|||
}
|
||||
|
||||
for _, c := range block.Children {
|
||||
if err = buildBlockChildren(c); nil != err {
|
||||
if err = buildBlockChildren(c); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ func (box *Box) docFromFileInfo(fileInfo *FileInfo, ial map[string]string) (ret
|
|||
|
||||
mTime := t
|
||||
if updated := ial["updated"]; "" != updated {
|
||||
if updatedTime, err := time.ParseInLocation("20060102150405", updated, time.Local); nil == err {
|
||||
if updatedTime, err := time.ParseInLocation("20060102150405", updated, time.Local); err == nil {
|
||||
mTime = updatedTime
|
||||
}
|
||||
}
|
||||
|
|
@ -122,7 +122,7 @@ func (box *Box) docIAL(p string) (ret map[string]string) {
|
|||
box.moveCorruptedData(filePath)
|
||||
return nil
|
||||
}
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read file [%s] failed: %s", p, err)
|
||||
return nil
|
||||
}
|
||||
|
|
@ -271,7 +271,7 @@ func ListDocTree(boxID, listPath string, sortMode int, flashcard, showHidden boo
|
|||
var files []*FileInfo
|
||||
start := time.Now()
|
||||
files, totals, err = box.Ls(listPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
elapsed := time.Now().Sub(start).Milliseconds()
|
||||
|
|
@ -300,7 +300,7 @@ func ListDocTree(boxID, listPath string, sortMode int, flashcard, showHidden boo
|
|||
|
||||
doc := box.docFromFileInfo(parentDocFile, ial)
|
||||
subFiles, err := os.ReadDir(filepath.Join(boxLocalPath, file.path))
|
||||
if nil == err {
|
||||
if err == nil {
|
||||
for _, subFile := range subFiles {
|
||||
subDocFilePath := path.Join(file.path, subFile.Name())
|
||||
if subIAL := box.docIAL(subDocFilePath); "true" == subIAL["custom-hidden"] {
|
||||
|
|
@ -602,7 +602,7 @@ func GetDoc(startID, endID, id string, index int, query string, queryTypes map[s
|
|||
|
||||
inputIndex := index
|
||||
tree, err := LoadTreeByBlockID(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
if ErrBlockNotFound == err {
|
||||
if 0 == mode {
|
||||
err = ErrTreeNotFound // 初始化打开文档时如果找不到则关闭编辑器
|
||||
|
|
@ -1055,7 +1055,7 @@ func loadNodesByMode(node *ast.Node, inputIndex, mode, size int, isDoc, isHeadin
|
|||
}
|
||||
|
||||
func writeTreeUpsertQueue(tree *parse.Tree) (err error) {
|
||||
if err = filesys.WriteTree(tree); nil != err {
|
||||
if err = filesys.WriteTree(tree); err != nil {
|
||||
return
|
||||
}
|
||||
sql.UpsertTreeQueue(tree)
|
||||
|
|
@ -1063,7 +1063,7 @@ func writeTreeUpsertQueue(tree *parse.Tree) (err error) {
|
|||
}
|
||||
|
||||
func writeTreeIndexQueue(tree *parse.Tree) (err error) {
|
||||
if err = filesys.WriteTree(tree); nil != err {
|
||||
if err = filesys.WriteTree(tree); err != nil {
|
||||
return
|
||||
}
|
||||
sql.IndexTreeQueue(tree)
|
||||
|
|
@ -1081,7 +1081,7 @@ func indexWriteTreeUpsertQueue(tree *parse.Tree) (err error) {
|
|||
}
|
||||
|
||||
func renameWriteJSONQueue(tree *parse.Tree) (err error) {
|
||||
if err = filesys.WriteTree(tree); nil != err {
|
||||
if err = filesys.WriteTree(tree); err != nil {
|
||||
return
|
||||
}
|
||||
sql.RenameTreeQueue(tree)
|
||||
|
|
@ -1140,7 +1140,7 @@ func CreateDocByMd(boxID, p, title, md string, sorts []string) (tree *parse.Tree
|
|||
luteEngine := util.NewLute()
|
||||
dom := luteEngine.Md2BlockDOM(md, false)
|
||||
tree, err = createDoc(box.ID, p, title, dom)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -1188,7 +1188,7 @@ func CreateDailyNote(boxID string) (p string, existed bool, err error) {
|
|||
}
|
||||
|
||||
hPath, err := RenderGoTemplate(boxConf.DailyNoteSavePath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -1208,7 +1208,7 @@ func CreateDailyNote(boxID string) (p string, existed bool, err error) {
|
|||
date := time.Now().Format("20060102")
|
||||
if tree.Root.IALAttr("custom-dailynote-"+date) == "" {
|
||||
tree.Root.SetIALAttr("custom-dailynote-"+date, date)
|
||||
if err = indexWriteTreeUpsertQueue(tree); nil != err {
|
||||
if err = indexWriteTreeUpsertQueue(tree); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -1216,7 +1216,7 @@ func CreateDailyNote(boxID string) (p string, existed bool, err error) {
|
|||
}
|
||||
|
||||
id, err := createDocsByHPath(box.ID, hPath, "", "", "")
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -1237,7 +1237,7 @@ func CreateDailyNote(boxID string) (p string, existed bool, err error) {
|
|||
if "" != templateDom {
|
||||
var tree *parse.Tree
|
||||
tree, err = LoadTreeByBlockID(id)
|
||||
if nil == err {
|
||||
if err == nil {
|
||||
tree.Root.FirstChild.Unlink()
|
||||
|
||||
luteEngine := util.NewLute()
|
||||
|
|
@ -1259,7 +1259,7 @@ func CreateDailyNote(boxID string) (p string, existed bool, err error) {
|
|||
}
|
||||
|
||||
tree.Root.SetIALAttr("updated", util.CurrentTimeSecondsStr())
|
||||
if err = indexWriteTreeUpsertQueue(tree); nil != err {
|
||||
if err = indexWriteTreeUpsertQueue(tree); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -1269,14 +1269,14 @@ func CreateDailyNote(boxID string) (p string, existed bool, err error) {
|
|||
WaitForWritingFiles()
|
||||
|
||||
tree, err := LoadTreeByBlockID(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("load tree by block id [%s] failed: %v", id, err)
|
||||
return
|
||||
}
|
||||
p = tree.Path
|
||||
date := time.Now().Format("20060102")
|
||||
tree.Root.SetIALAttr("custom-dailynote-"+date, date)
|
||||
if err = indexWriteTreeUpsertQueue(tree); nil != err {
|
||||
if err = indexWriteTreeUpsertQueue(tree); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -1291,7 +1291,7 @@ func GetHPathByPath(boxID, p string) (hPath string, err error) {
|
|||
|
||||
luteEngine := util.NewLute()
|
||||
tree, err := filesys.LoadTree(boxID, p, luteEngine)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
hPath = tree.HPath
|
||||
|
|
@ -1320,7 +1320,7 @@ func GetHPathsByPaths(paths []string) (hPaths []string, err error) {
|
|||
|
||||
func GetHPathByID(id string) (hPath string, err error) {
|
||||
tree, err := LoadTreeByBlockID(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
hPath = tree.HPath
|
||||
|
|
@ -1329,7 +1329,7 @@ func GetHPathByID(id string) (hPath string, err error) {
|
|||
|
||||
func GetPathByID(id string) (path string, err error) {
|
||||
tree, err := LoadTreeByBlockID(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -1339,7 +1339,7 @@ func GetPathByID(id string) (path string, err error) {
|
|||
|
||||
func GetFullHPathByID(id string) (hPath string, err error) {
|
||||
tree, err := LoadTreeByBlockID(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -1422,7 +1422,7 @@ func MoveDocs(fromPaths []string, toBoxID, toPath string, callback interface{})
|
|||
}
|
||||
|
||||
_, err = moveDoc(fromBox, fromPath, toBox, toPath, luteEngine, callback)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -1434,7 +1434,7 @@ func MoveDocs(fromPaths []string, toBoxID, toPath string, callback interface{})
|
|||
func countSubDocs(box, p string) (ret int) {
|
||||
p = strings.TrimSuffix(p, ".sy")
|
||||
_ = filepath.Walk(filepath.Join(util.DataDir, box, p), func(path string, info os.FileInfo, err error) error {
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if info.IsDir() {
|
||||
|
|
@ -1464,7 +1464,7 @@ func moveDoc(fromBox *Box, fromPath string, toBox *Box, toPath string, luteEngin
|
|||
}
|
||||
|
||||
tree, err := filesys.LoadTree(fromBox.ID, fromPath, luteEngine)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
err = ErrBlockNotFound
|
||||
return
|
||||
}
|
||||
|
|
@ -1480,7 +1480,7 @@ func moveDoc(fromBox *Box, fromPath string, toBox *Box, toPath string, luteEngin
|
|||
} else {
|
||||
toTree, err = filesys.LoadTree(toBox.ID, toPath, luteEngine)
|
||||
}
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
err = ErrBlockNotFound
|
||||
return
|
||||
}
|
||||
|
|
@ -1490,11 +1490,11 @@ func moveDoc(fromBox *Box, fromPath string, toBox *Box, toPath string, luteEngin
|
|||
}
|
||||
|
||||
if isSameBox {
|
||||
if err = fromBox.MkdirAll(toFolder); nil != err {
|
||||
if err = fromBox.MkdirAll(toFolder); err != nil {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if err = toBox.MkdirAll(toFolder); nil != err {
|
||||
if err = toBox.MkdirAll(toFolder); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -1505,7 +1505,7 @@ func moveDoc(fromBox *Box, fromPath string, toBox *Box, toPath string, luteEngin
|
|||
|
||||
newFolder := path.Join(toFolder, tree.ID)
|
||||
if isSameBox {
|
||||
if err = fromBox.Move(fromFolder, newFolder); nil != err {
|
||||
if err = fromBox.Move(fromFolder, newFolder); err != nil {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
|
|
@ -1514,7 +1514,7 @@ func moveDoc(fromBox *Box, fromPath string, toBox *Box, toPath string, luteEngin
|
|||
if filelock.IsExist(absToPath) {
|
||||
filelock.Remove(absToPath)
|
||||
}
|
||||
if err = filelock.Rename(absFromPath, absToPath); nil != err {
|
||||
if err = filelock.Rename(absFromPath, absToPath); err != nil {
|
||||
msg := fmt.Sprintf(Conf.Language(5), fromBox.Name, fromPath, err)
|
||||
logging.LogErrorf("move [path=%s] in box [%s] failed: %s", fromPath, fromBox.ID, err)
|
||||
err = errors.New(msg)
|
||||
|
|
@ -1526,12 +1526,12 @@ func moveDoc(fromBox *Box, fromPath string, toBox *Box, toPath string, luteEngin
|
|||
newPath = path.Join(toFolder, tree.ID+".sy")
|
||||
|
||||
if isSameBox {
|
||||
if err = fromBox.Move(fromPath, newPath); nil != err {
|
||||
if err = fromBox.Move(fromPath, newPath); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
tree, err = filesys.LoadTree(fromBox.ID, newPath, luteEngine)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -1539,7 +1539,7 @@ func moveDoc(fromBox *Box, fromPath string, toBox *Box, toPath string, luteEngin
|
|||
} else {
|
||||
absFromPath := filepath.Join(util.DataDir, fromBox.ID, fromPath)
|
||||
absToPath := filepath.Join(util.DataDir, toBox.ID, newPath)
|
||||
if err = filelock.Rename(absFromPath, absToPath); nil != err {
|
||||
if err = filelock.Rename(absFromPath, absToPath); err != nil {
|
||||
msg := fmt.Sprintf(Conf.Language(5), fromBox.Name, fromPath, err)
|
||||
logging.LogErrorf("move [path=%s] in box [%s] failed: %s", fromPath, fromBox.ID, err)
|
||||
err = errors.New(msg)
|
||||
|
|
@ -1547,7 +1547,7 @@ func moveDoc(fromBox *Box, fromPath string, toBox *Box, toPath string, luteEngin
|
|||
}
|
||||
|
||||
tree, err = filesys.LoadTree(toBox.ID, newPath, luteEngine)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -1624,14 +1624,14 @@ func removeDoc(box *Box, p string, luteEngine *lute.Lute) {
|
|||
}
|
||||
|
||||
historyDir, err := GetHistoryDir(HistoryOpDelete)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("get history dir failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
historyPath := filepath.Join(historyDir, box.ID, p)
|
||||
absPath := filepath.Join(util.DataDir, box.ID, p)
|
||||
if err = filelock.Copy(absPath, historyPath); nil != err {
|
||||
if err = filelock.Copy(absPath, historyPath); err != nil {
|
||||
logging.LogErrorf("backup [path=%s] to history [%s] failed: %s", absPath, historyPath, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -1655,7 +1655,7 @@ func removeDoc(box *Box, p string, luteEngine *lute.Lute) {
|
|||
if existChildren {
|
||||
absChildrenDir := filepath.Join(util.DataDir, tree.Box, childrenDir)
|
||||
historyPath = filepath.Join(historyDir, tree.Box, childrenDir)
|
||||
if err = filelock.Copy(absChildrenDir, historyPath); nil != err {
|
||||
if err = filelock.Copy(absChildrenDir, historyPath); err != nil {
|
||||
logging.LogErrorf("backup [path=%s] to history [%s] failed: %s", absChildrenDir, historyPath, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -1676,13 +1676,13 @@ func removeDoc(box *Box, p string, luteEngine *lute.Lute) {
|
|||
}
|
||||
|
||||
if existChildren {
|
||||
if err = box.Remove(childrenDir); nil != err {
|
||||
if err = box.Remove(childrenDir); err != nil {
|
||||
logging.LogErrorf("remove children dir [%s%s] failed: %s", box.ID, childrenDir, err)
|
||||
return
|
||||
}
|
||||
logging.LogInfof("removed children dir [%s%s]", box.ID, childrenDir)
|
||||
}
|
||||
if err = box.Remove(p); nil != err {
|
||||
if err = box.Remove(p); err != nil {
|
||||
logging.LogErrorf("remove [%s%s] failed: %s", box.ID, p, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -1692,7 +1692,7 @@ func removeDoc(box *Box, p string, luteEngine *lute.Lute) {
|
|||
RemoveRecentDoc(removeIDs)
|
||||
if "/" != dir {
|
||||
others, err := os.ReadDir(filepath.Join(util.DataDir, box.ID, dir))
|
||||
if nil == err && 1 > len(others) {
|
||||
if err == nil && 1 > len(others) {
|
||||
box.Remove(dir)
|
||||
}
|
||||
}
|
||||
|
|
@ -1723,7 +1723,7 @@ func RenameDoc(boxID, p, title string) (err error) {
|
|||
WaitForWritingFiles()
|
||||
luteEngine := util.NewLute()
|
||||
tree, err := filesys.LoadTree(box.ID, p, luteEngine)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -1745,7 +1745,7 @@ func RenameDoc(boxID, p, title string) (err error) {
|
|||
tree.HPath = path.Join(path.Dir(tree.HPath), title)
|
||||
tree.Root.SetIALAttr("title", title)
|
||||
tree.Root.SetIALAttr("updated", util.CurrentTimeSecondsStr())
|
||||
if err = renameWriteJSONQueue(tree); nil != err {
|
||||
if err = renameWriteJSONQueue(tree); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -1818,7 +1818,7 @@ func createDoc(boxID, p, title, dom string) (tree *parse.Tree, err error) {
|
|||
}
|
||||
|
||||
if !box.Exist(folder) {
|
||||
if err = box.MkdirAll(folder); nil != err {
|
||||
if err = box.MkdirAll(folder); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -1900,12 +1900,12 @@ func moveSorts(rootID, fromBox, toBox string) {
|
|||
fromFullSortIDs := map[string]int{}
|
||||
if filelock.IsExist(fromConfPath) {
|
||||
data, err := filelock.ReadFile(fromConfPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read sort conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &fromFullSortIDs); nil != err {
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &fromFullSortIDs); err != nil {
|
||||
logging.LogErrorf("unmarshal sort conf failed: %s", err)
|
||||
}
|
||||
}
|
||||
|
|
@ -1917,12 +1917,12 @@ func moveSorts(rootID, fromBox, toBox string) {
|
|||
toFullSortIDs := map[string]int{}
|
||||
if filelock.IsExist(toConfPath) {
|
||||
data, err := filelock.ReadFile(toConfPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read sort conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &toFullSortIDs); nil != err {
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &toFullSortIDs); err != nil {
|
||||
logging.LogErrorf("unmarshal sort conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -1933,11 +1933,11 @@ func moveSorts(rootID, fromBox, toBox string) {
|
|||
}
|
||||
|
||||
data, err := gulu.JSON.MarshalJSON(toFullSortIDs)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("marshal sort conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
if err = filelock.WriteFile(toConfPath, data); nil != err {
|
||||
if err = filelock.WriteFile(toConfPath, data); err != nil {
|
||||
logging.LogErrorf("write sort conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -1964,7 +1964,7 @@ func ChangeFileTreeSort(boxID string, paths []string) {
|
|||
parentPath := path.Dir(p)
|
||||
absParentPath := filepath.Join(util.DataDir, boxID, parentPath)
|
||||
files, err := os.ReadDir(absParentPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read dir [%s] failed: %s", absParentPath, err)
|
||||
}
|
||||
|
||||
|
|
@ -1984,7 +1984,7 @@ func ChangeFileTreeSort(boxID string, paths []string) {
|
|||
}
|
||||
|
||||
confDir := filepath.Join(util.DataDir, box.ID, ".siyuan")
|
||||
if err = os.MkdirAll(confDir, 0755); nil != err {
|
||||
if err = os.MkdirAll(confDir, 0755); err != nil {
|
||||
logging.LogErrorf("create conf dir failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -1993,12 +1993,12 @@ func ChangeFileTreeSort(boxID string, paths []string) {
|
|||
var data []byte
|
||||
if filelock.IsExist(confPath) {
|
||||
data, err = filelock.ReadFile(confPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read sort conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &fullSortIDs); nil != err {
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &fullSortIDs); err != nil {
|
||||
logging.LogErrorf("unmarshal sort conf failed: %s", err)
|
||||
}
|
||||
}
|
||||
|
|
@ -2008,11 +2008,11 @@ func ChangeFileTreeSort(boxID string, paths []string) {
|
|||
}
|
||||
|
||||
data, err = gulu.JSON.MarshalJSON(fullSortIDs)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("marshal sort conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
if err = filelock.WriteFile(confPath, data); nil != err {
|
||||
if err = filelock.WriteFile(confPath, data); err != nil {
|
||||
logging.LogErrorf("write sort conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -2027,13 +2027,13 @@ func (box *Box) fillSort(files *[]*File) {
|
|||
}
|
||||
|
||||
data, err := filelock.ReadFile(confPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read sort conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
fullSortIDs := map[string]int{}
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &fullSortIDs); nil != err {
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &fullSortIDs); err != nil {
|
||||
logging.LogErrorf("unmarshal sort conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -2051,13 +2051,13 @@ func (box *Box) removeSort(ids []string) {
|
|||
}
|
||||
|
||||
data, err := filelock.ReadFile(confPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read sort conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
fullSortIDs := map[string]int{}
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &fullSortIDs); nil != err {
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &fullSortIDs); err != nil {
|
||||
logging.LogErrorf("unmarshal sort conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -2067,11 +2067,11 @@ func (box *Box) removeSort(ids []string) {
|
|||
}
|
||||
|
||||
data, err = gulu.JSON.MarshalJSON(fullSortIDs)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("marshal sort conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
if err = filelock.WriteFile(confPath, data); nil != err {
|
||||
if err = filelock.WriteFile(confPath, data); err != nil {
|
||||
logging.LogErrorf("write sort conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -2079,7 +2079,7 @@ func (box *Box) removeSort(ids []string) {
|
|||
|
||||
func (box *Box) addMinSort(parentPath, id string) {
|
||||
docs, _, err := ListDocTree(box.ID, parentPath, util.SortModeUnassigned, false, false, 1)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("list doc tree failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -2090,7 +2090,7 @@ func (box *Box) addMinSort(parentPath, id string) {
|
|||
}
|
||||
|
||||
confDir := filepath.Join(util.DataDir, box.ID, ".siyuan")
|
||||
if err = os.MkdirAll(confDir, 0755); nil != err {
|
||||
if err = os.MkdirAll(confDir, 0755); err != nil {
|
||||
logging.LogErrorf("create conf dir failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -2099,12 +2099,12 @@ func (box *Box) addMinSort(parentPath, id string) {
|
|||
var data []byte
|
||||
if filelock.IsExist(confPath) {
|
||||
data, err = filelock.ReadFile(confPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read sort conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &fullSortIDs); nil != err {
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &fullSortIDs); err != nil {
|
||||
logging.LogErrorf("unmarshal sort conf failed: %s", err)
|
||||
}
|
||||
}
|
||||
|
|
@ -2112,11 +2112,11 @@ func (box *Box) addMinSort(parentPath, id string) {
|
|||
fullSortIDs[id] = sortVal
|
||||
|
||||
data, err = gulu.JSON.MarshalJSON(fullSortIDs)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("marshal sort conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
if err = filelock.WriteFile(confPath, data); nil != err {
|
||||
if err = filelock.WriteFile(confPath, data); err != nil {
|
||||
logging.LogErrorf("write sort conf failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ func SetFlashcardsDueTime(cardDues []*SetFlashcardDueTime) (err error) {
|
|||
card.SetDue(due)
|
||||
}
|
||||
|
||||
if err = deck.Save(); nil != err {
|
||||
if err = deck.Save(); err != nil {
|
||||
logging.LogErrorf("save deck [%s] failed: %s", builtinDeckID, err)
|
||||
}
|
||||
return
|
||||
|
|
@ -270,7 +270,7 @@ func GetNotebookFlashcards(boxID string, page, pageSize int) (blocks []*Block, t
|
|||
blocks = []*Block{}
|
||||
|
||||
entries, err := os.ReadDir(filepath.Join(util.DataDir, boxID))
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read dir failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -467,12 +467,12 @@ func ReviewFlashcard(deckID, cardID string, rating riff.Rating, reviewedCardIDs
|
|||
}
|
||||
|
||||
log := deck.Review(cardID, rating)
|
||||
if err = deck.Save(); nil != err {
|
||||
if err = deck.Save(); err != nil {
|
||||
logging.LogErrorf("save deck [%s] failed: %s", deckID, err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = deck.SaveLog(log); nil != err {
|
||||
if err = deck.SaveLog(log); err != nil {
|
||||
logging.LogErrorf("save review log [%s] failed: %s", deckID, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -538,7 +538,7 @@ func GetNotebookDueFlashcards(boxID string, reviewedCardIDs []string) (ret []*Fl
|
|||
waitForSyncingStorages()
|
||||
|
||||
entries, err := os.ReadDir(filepath.Join(util.DataDir, boxID))
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read dir failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -734,7 +734,7 @@ func (tx *Transaction) doRemoveFlashcards(operation *Operation) (ret *TxErr) {
|
|||
deckID := operation.DeckID
|
||||
blockIDs := operation.BlockIDs
|
||||
|
||||
if err := tx.removeBlocksDeckAttr(blockIDs, deckID); nil != err {
|
||||
if err := tx.removeBlocksDeckAttr(blockIDs, deckID); err != nil {
|
||||
return &TxErr{code: TxErrCodeWriteTree, msg: err.Error(), id: deckID}
|
||||
}
|
||||
|
||||
|
|
@ -803,7 +803,7 @@ func (tx *Transaction) removeBlocksDeckAttr(blockIDs []string, deckID string) (e
|
|||
node.SetIALAttr("custom-riff-decks", val)
|
||||
}
|
||||
|
||||
if err = tx.writeTree(tree); nil != err {
|
||||
if err = tx.writeTree(tree); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -829,7 +829,7 @@ func removeFlashcardsByBlockIDs(blockIDs []string, deck *riff.Deck) {
|
|||
deck.RemoveCard(card.ID())
|
||||
}
|
||||
err := deck.Save()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("save deck [%s] failed: %s", deck.ID, err)
|
||||
}
|
||||
}
|
||||
|
|
@ -899,7 +899,7 @@ func (tx *Transaction) doAddFlashcards(operation *Operation) (ret *TxErr) {
|
|||
val = strings.TrimSuffix(val, ",")
|
||||
node.SetIALAttr("custom-riff-decks", val)
|
||||
|
||||
if err := tx.writeTree(tree); nil != err {
|
||||
if err := tx.writeTree(tree); err != nil {
|
||||
return &TxErr{code: TxErrCodeWriteTree, msg: err.Error(), id: deckID}
|
||||
}
|
||||
|
||||
|
|
@ -924,7 +924,7 @@ func (tx *Transaction) doAddFlashcards(operation *Operation) (ret *TxErr) {
|
|||
deck.AddCard(cardID, blockID)
|
||||
}
|
||||
|
||||
if err := deck.Save(); nil != err {
|
||||
if err := deck.Save(); err != nil {
|
||||
logging.LogErrorf("save deck [%s] failed: %s", deckID, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -933,7 +933,7 @@ func (tx *Transaction) doAddFlashcards(operation *Operation) (ret *TxErr) {
|
|||
|
||||
func LoadFlashcards() {
|
||||
riffSavePath := getRiffDir()
|
||||
if err := os.MkdirAll(riffSavePath, 0755); nil != err {
|
||||
if err := os.MkdirAll(riffSavePath, 0755); err != nil {
|
||||
logging.LogErrorf("create riff dir [%s] failed: %s", riffSavePath, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -941,7 +941,7 @@ func LoadFlashcards() {
|
|||
Decks = map[string]*riff.Deck{}
|
||||
|
||||
entries, err := os.ReadDir(riffSavePath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read riff dir failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -978,7 +978,7 @@ func RenameDeck(deckID, name string) (err error) {
|
|||
deck := Decks[deckID]
|
||||
deck.Name = name
|
||||
err = deck.Save()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("save deck [%s] failed: %s", deckID, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -994,14 +994,14 @@ func RemoveDeck(deckID string) (err error) {
|
|||
riffSavePath := getRiffDir()
|
||||
deckPath := filepath.Join(riffSavePath, deckID+".deck")
|
||||
if filelock.IsExist(deckPath) {
|
||||
if err = filelock.Remove(deckPath); nil != err {
|
||||
if err = filelock.Remove(deckPath); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
cardsPath := filepath.Join(riffSavePath, deckID+".cards")
|
||||
if filelock.IsExist(cardsPath) {
|
||||
if err = filelock.Remove(cardsPath); nil != err {
|
||||
if err = filelock.Remove(cardsPath); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -1027,14 +1027,14 @@ func createDeck(name string) (deck *riff.Deck, err error) {
|
|||
func createDeck0(name string, deckID string) (deck *riff.Deck, err error) {
|
||||
riffSavePath := getRiffDir()
|
||||
deck, err = riff.LoadDeck(riffSavePath, deckID, Conf.Flashcard.RequestRetention, Conf.Flashcard.MaximumInterval, Conf.Flashcard.Weights)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("load deck [%s] failed: %s", deckID, err)
|
||||
return
|
||||
}
|
||||
deck.Name = name
|
||||
Decks[deckID] = deck
|
||||
err = deck.Save()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("save deck [%s] failed: %s", deckID, err)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@ import (
|
|||
|
||||
func AutoSpace(rootID string) (err error) {
|
||||
tree, err := LoadTreeByBlockID(rootID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -69,7 +69,7 @@ func AutoSpace(rootID string) (err error) {
|
|||
newTree.HPath = tree.HPath
|
||||
newTree.Box = tree.Box
|
||||
err = writeTreeUpsertQueue(newTree)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
logging.LogInfof("formatted tree [%s]", rootID)
|
||||
|
|
|
|||
|
|
@ -64,7 +64,7 @@ func BuildTreeGraph(id, query string) (boxID string, nodes []*GraphNode, links [
|
|||
links = []*GraphLink{}
|
||||
|
||||
tree, err := LoadTreeByBlockID(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
node := treenode.GetNodeInTree(tree, id)
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ import (
|
|||
func (tx *Transaction) doFoldHeading(operation *Operation) (ret *TxErr) {
|
||||
headingID := operation.ID
|
||||
tree, err := tx.loadTree(headingID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: headingID}
|
||||
}
|
||||
|
||||
|
|
@ -59,7 +59,7 @@ func (tx *Transaction) doFoldHeading(operation *Operation) (ret *TxErr) {
|
|||
})
|
||||
}
|
||||
heading.SetIALAttr("fold", "1")
|
||||
if err = tx.writeTree(tree); nil != err {
|
||||
if err = tx.writeTree(tree); err != nil {
|
||||
return &TxErr{code: TxErrCodeWriteTree, msg: err.Error(), id: headingID}
|
||||
}
|
||||
IncSync()
|
||||
|
|
@ -77,7 +77,7 @@ func (tx *Transaction) doUnfoldHeading(operation *Operation) (ret *TxErr) {
|
|||
headingID := operation.ID
|
||||
|
||||
tree, err := tx.loadTree(headingID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: headingID}
|
||||
}
|
||||
|
||||
|
|
@ -100,7 +100,7 @@ func (tx *Transaction) doUnfoldHeading(operation *Operation) (ret *TxErr) {
|
|||
}
|
||||
heading.RemoveIALAttr("fold")
|
||||
heading.RemoveIALAttr("heading-fold")
|
||||
if err = tx.writeTree(tree); nil != err {
|
||||
if err = tx.writeTree(tree); err != nil {
|
||||
return &TxErr{code: TxErrCodeWriteTree, msg: err.Error(), id: headingID}
|
||||
}
|
||||
IncSync()
|
||||
|
|
@ -272,7 +272,7 @@ func Heading2Doc(srcHeadingID, targetBoxID, targetPath string) (srcRootBlockID,
|
|||
srcRootBlockID = srcTree.Root.ID
|
||||
|
||||
headingBlock, err := getBlock(srcHeadingID, srcTree)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if nil == headingBlock {
|
||||
|
|
@ -308,7 +308,7 @@ func Heading2Doc(srcHeadingID, targetBoxID, targetPath string) (srcRootBlockID,
|
|||
|
||||
newTargetPath = path.Join(toFolder, srcHeadingID+".sy")
|
||||
if !box.Exist(toFolder) {
|
||||
if err = box.MkdirAll(toFolder); nil != err {
|
||||
if err = box.MkdirAll(toFolder); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -358,7 +358,7 @@ func Heading2Doc(srcHeadingID, targetBoxID, targetPath string) (srcRootBlockID,
|
|||
srcTree.Root.AppendChild(treenode.NewParagraph())
|
||||
}
|
||||
treenode.RemoveBlockTreesByRootID(srcTree.ID)
|
||||
if err = indexWriteTreeUpsertQueue(srcTree); nil != err {
|
||||
if err = indexWriteTreeUpsertQueue(srcTree); err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
|
|
@ -366,7 +366,7 @@ func Heading2Doc(srcHeadingID, targetBoxID, targetPath string) (srcRootBlockID,
|
|||
newTree.Root.SetIALAttr("updated", util.CurrentTimeSecondsStr())
|
||||
newTree.Root.Spec = "1"
|
||||
box.addMinSort(path.Dir(newTargetPath), newTree.ID)
|
||||
if err = indexWriteTreeUpsertQueue(newTree); nil != err {
|
||||
if err = indexWriteTreeUpsertQueue(newTree); err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
IncSync()
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ func ChangeHistoryTick(minutes int) {
|
|||
func ClearWorkspaceHistory() (err error) {
|
||||
historyDir := util.HistoryDir
|
||||
if gulu.File.IsDir(historyDir) {
|
||||
if err = os.RemoveAll(historyDir); nil != err {
|
||||
if err = os.RemoveAll(historyDir); err != nil {
|
||||
logging.LogErrorf("remove workspace history dir [%s] failed: %s", historyDir, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -109,7 +109,7 @@ func ClearWorkspaceHistory() (err error) {
|
|||
// 以下部分是老版本的清理逻辑,暂时保留
|
||||
|
||||
notebooks, err := ListNotebooks()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -120,7 +120,7 @@ func ClearWorkspaceHistory() (err error) {
|
|||
continue
|
||||
}
|
||||
|
||||
if err = os.RemoveAll(historyDir); nil != err {
|
||||
if err = os.RemoveAll(historyDir); err != nil {
|
||||
logging.LogErrorf("remove notebook history dir [%s] failed: %s", historyDir, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -129,7 +129,7 @@ func ClearWorkspaceHistory() (err error) {
|
|||
|
||||
historyDir = filepath.Join(util.DataDir, ".siyuan", "history")
|
||||
if gulu.File.IsDir(historyDir) {
|
||||
if err = os.RemoveAll(historyDir); nil != err {
|
||||
if err = os.RemoveAll(historyDir); err != nil {
|
||||
logging.LogErrorf("remove data history dir [%s] failed: %s", historyDir, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -137,7 +137,7 @@ func ClearWorkspaceHistory() (err error) {
|
|||
}
|
||||
historyDir = filepath.Join(util.DataDir, "assets", ".siyuan", "history")
|
||||
if gulu.File.IsDir(historyDir) {
|
||||
if err = os.RemoveAll(historyDir); nil != err {
|
||||
if err = os.RemoveAll(historyDir); err != nil {
|
||||
logging.LogErrorf("remove assets history dir [%s] failed: %s", historyDir, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -153,7 +153,7 @@ func GetDocHistoryContent(historyPath, keyword string) (id, rootID, content stri
|
|||
}
|
||||
|
||||
data, err := filelock.ReadFile(historyPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read file [%s] failed: %s", historyPath, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -161,7 +161,7 @@ func GetDocHistoryContent(historyPath, keyword string) (id, rootID, content stri
|
|||
|
||||
luteEngine := NewLute()
|
||||
historyTree, err := filesys.ParseJSONWithoutFix(data, luteEngine.ParseOptions)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("parse tree from file [%s] failed, remove it", historyPath)
|
||||
os.RemoveAll(historyPath)
|
||||
return
|
||||
|
|
@ -234,17 +234,17 @@ func RollbackDocHistory(boxID, historyPath string) (err error) {
|
|||
|
||||
workingDoc := treenode.GetBlockTree(id)
|
||||
if nil != workingDoc {
|
||||
if err = filelock.Remove(filepath.Join(util.DataDir, boxID, workingDoc.Path)); nil != err {
|
||||
if err = filelock.Remove(filepath.Join(util.DataDir, boxID, workingDoc.Path)); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
destPath, parentHPath, err = getRollbackDockPath(boxID, historyPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err = filelock.CopyNewtimes(srcPath, destPath); nil != err {
|
||||
if err = filelock.CopyNewtimes(srcPath, destPath); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -317,7 +317,7 @@ func getRollbackDockPath(boxID, historyPath string) (destPath, parentHPath strin
|
|||
// 父路径如果是文档,则恢复到父路径下
|
||||
parentDir := strings.TrimSuffix(parentWorkingDoc.Path, ".sy")
|
||||
parentDir = filepath.Join(util.DataDir, boxID, parentDir)
|
||||
if err = os.MkdirAll(parentDir, 0755); nil != err {
|
||||
if err = os.MkdirAll(parentDir, 0755); err != nil {
|
||||
return
|
||||
}
|
||||
destPath = filepath.Join(parentDir, baseName)
|
||||
|
|
@ -339,7 +339,7 @@ func RollbackAssetsHistory(historyPath string) (err error) {
|
|||
from := historyPath
|
||||
to := filepath.Join(util.DataDir, "assets", filepath.Base(historyPath))
|
||||
|
||||
if err = filelock.CopyNewtimes(from, to); nil != err {
|
||||
if err = filelock.CopyNewtimes(from, to); err != nil {
|
||||
logging.LogErrorf("copy file [%s] to [%s] failed: %s", from, to, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -357,7 +357,7 @@ func RollbackNotebookHistory(historyPath string) (err error) {
|
|||
from := historyPath
|
||||
to := filepath.Join(util.DataDir, filepath.Base(historyPath))
|
||||
|
||||
if err = filelock.CopyNewtimes(from, to); nil != err {
|
||||
if err = filelock.CopyNewtimes(from, to); err != nil {
|
||||
logging.LogErrorf("copy file [%s] to [%s] failed: %s", from, to, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -395,14 +395,14 @@ func FullTextSearchHistory(query, box, op string, typ, page int) (ret []string,
|
|||
countStmt := strings.ReplaceAll(stmt, "SELECT DISTINCT created", "SELECT COUNT(DISTINCT created) AS total")
|
||||
stmt += " ORDER BY created DESC LIMIT " + strconv.Itoa(fileHistoryPageSize) + " OFFSET " + strconv.Itoa(offset)
|
||||
result, err := sql.QueryHistory(stmt)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
for _, row := range result {
|
||||
ret = append(ret, row["created"].(string))
|
||||
}
|
||||
result, err = sql.QueryHistory(countStmt)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if 1 > len(ret) {
|
||||
|
|
@ -472,7 +472,7 @@ func GetNotebookHistory() (ret []*History, err error) {
|
|||
}
|
||||
|
||||
historyNotebookConfs, err := filepath.Glob(historyDir + "/*-delete/*/.siyuan/conf.json")
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read dir [%s] failed: %s", historyDir, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -495,7 +495,7 @@ func GetNotebookHistory() (ret []*History, err error) {
|
|||
logging.LogErrorf("read notebook conf [%s] failed: %s", historyNotebookConf, readErr)
|
||||
continue
|
||||
}
|
||||
if err = json.Unmarshal(data, &c); nil != err {
|
||||
if err = json.Unmarshal(data, &c); err != nil {
|
||||
logging.LogErrorf("parse notebook conf [%s] failed: %s", historyNotebookConf, err)
|
||||
continue
|
||||
}
|
||||
|
|
@ -523,19 +523,19 @@ func generateAssetsHistory() {
|
|||
}
|
||||
|
||||
historyDir, err := GetHistoryDir(HistoryOpUpdate)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("get history dir failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, file := range assets {
|
||||
historyPath := filepath.Join(historyDir, "assets", strings.TrimPrefix(file, filepath.Join(util.DataDir, "assets")))
|
||||
if err = os.MkdirAll(filepath.Dir(historyPath), 0755); nil != err {
|
||||
if err = os.MkdirAll(filepath.Dir(historyPath), 0755); err != nil {
|
||||
logging.LogErrorf("generate history failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = filelock.Copy(file, historyPath); nil != err {
|
||||
if err = filelock.Copy(file, historyPath); err != nil {
|
||||
logging.LogErrorf("copy file [%s] to [%s] failed: %s", file, historyPath, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -552,7 +552,7 @@ func (box *Box) generateDocHistory0() {
|
|||
}
|
||||
|
||||
historyDir, err := GetHistoryDir(HistoryOpUpdate)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("get history dir failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -560,7 +560,7 @@ func (box *Box) generateDocHistory0() {
|
|||
luteEngine := util.NewLute()
|
||||
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 {
|
||||
if err = os.MkdirAll(filepath.Dir(historyPath), 0755); err != nil {
|
||||
logging.LogErrorf("generate history failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -605,7 +605,7 @@ func clearOutdatedHistoryDir(historyDir string) {
|
|||
}
|
||||
|
||||
dirs, err := os.ReadDir(historyDir)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("clear history [%s] failed: %s", historyDir, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -615,7 +615,7 @@ func clearOutdatedHistoryDir(historyDir string) {
|
|||
var removes []string
|
||||
for _, dir := range dirs {
|
||||
dirInfo, err := dir.Info()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read history dir [%s] failed: %s", dir.Name(), err)
|
||||
continue
|
||||
}
|
||||
|
|
@ -624,7 +624,7 @@ func clearOutdatedHistoryDir(historyDir string) {
|
|||
}
|
||||
}
|
||||
for _, dir := range removes {
|
||||
if err = os.RemoveAll(dir); nil != err {
|
||||
if err = os.RemoveAll(dir); err != nil {
|
||||
logging.LogWarnf("remove history dir [%s] failed: %s", dir, err)
|
||||
continue
|
||||
}
|
||||
|
|
@ -692,13 +692,13 @@ const (
|
|||
|
||||
func generateOpTypeHistory(tree *parse.Tree, opType string) {
|
||||
historyDir, err := GetHistoryDir(opType)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
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 {
|
||||
if err = os.MkdirAll(filepath.Dir(historyPath), 0755); err != nil {
|
||||
logging.LogErrorf("generate history failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -723,7 +723,7 @@ func GetHistoryDir(suffix string) (ret string, err error) {
|
|||
|
||||
func getHistoryDir(suffix string, t time.Time) (ret string, err error) {
|
||||
ret = filepath.Join(util.HistoryDir, t.Format("2006-01-02-150405")+"-"+suffix)
|
||||
if err = os.MkdirAll(ret, 0755); nil != err {
|
||||
if err = os.MkdirAll(ret, 0755); err != nil {
|
||||
logging.LogErrorf("make history dir failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -737,7 +737,7 @@ func ReindexHistory() {
|
|||
|
||||
func fullReindexHistory() {
|
||||
historyDirs, err := os.ReadDir(util.HistoryDir)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read history dir [%s] failed: %s", util.HistoryDir, err)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,14 +109,14 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
|
|||
baseName = strings.TrimSuffix(baseName, ext)
|
||||
unzipPath := filepath.Join(filepath.Dir(zipPath), baseName+"-"+gulu.Rand.String(7))
|
||||
err = gulu.Zip.Unzip(zipPath, unzipPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer os.RemoveAll(unzipPath)
|
||||
|
||||
var syPaths []string
|
||||
filelock.Walk(unzipPath, func(path string, info fs.FileInfo, err error) error {
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -127,7 +127,7 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
|
|||
})
|
||||
|
||||
entries, err := os.ReadDir(unzipPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read unzip dir [%s] failed: %s", unzipPath, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -264,7 +264,7 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
|
|||
}
|
||||
}
|
||||
|
||||
if err = os.Rename(oldPath, newPath); nil != err {
|
||||
if err = os.Rename(oldPath, newPath); err != nil {
|
||||
logging.LogErrorf("rename av file from [%s] to [%s] failed: %s", oldPath, newPath, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -381,18 +381,18 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
|
|||
if !util.UseSingleLineSave {
|
||||
buf := bytes.Buffer{}
|
||||
buf.Grow(1024 * 1024 * 2)
|
||||
if err = json.Indent(&buf, data, "", "\t"); nil != err {
|
||||
if err = json.Indent(&buf, data, "", "\t"); err != nil {
|
||||
return
|
||||
}
|
||||
data = buf.Bytes()
|
||||
}
|
||||
|
||||
if err = os.WriteFile(syPath, data, 0644); nil != err {
|
||||
if err = os.WriteFile(syPath, data, 0644); err != nil {
|
||||
logging.LogErrorf("write .sy [%s] failed: %s", syPath, err)
|
||||
return
|
||||
}
|
||||
newSyPath := filepath.Join(filepath.Dir(syPath), tree.ID+".sy")
|
||||
if err = filelock.Rename(syPath, newSyPath); nil != err {
|
||||
if err = filelock.Rename(syPath, newSyPath); err != nil {
|
||||
logging.LogErrorf("rename .sy from [%s] to [%s] failed: %s", syPath, newSyPath, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -449,7 +449,7 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
|
|||
// 重命名文件路径
|
||||
renamePaths := map[string]string{}
|
||||
filelock.Walk(unzipRootPath, func(path string, info fs.FileInfo, err error) error {
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -492,7 +492,7 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
|
|||
})
|
||||
for i, oldPath := range oldPaths {
|
||||
newPath := renamePaths[oldPath]
|
||||
if err = filelock.Rename(oldPath, newPath); nil != err {
|
||||
if err = filelock.Rename(oldPath, newPath); err != nil {
|
||||
logging.LogErrorf("rename path from [%s] to [%s] failed: %s", oldPath, renamePaths[oldPath], err)
|
||||
return errors.New("rename path failed")
|
||||
}
|
||||
|
|
@ -532,7 +532,7 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
|
|||
dataAssets := filepath.Join(util.DataDir, "assets")
|
||||
for _, assets := range assetsDirs {
|
||||
if gulu.File.IsDir(assets) {
|
||||
if err = filelock.Copy(assets, dataAssets); nil != err {
|
||||
if err = filelock.Copy(assets, dataAssets); err != nil {
|
||||
logging.LogErrorf("copy assets from [%s] to [%s] failed: %s", assets, dataAssets, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -553,7 +553,7 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
|
|||
}
|
||||
|
||||
targetDir := filepath.Join(util.DataDir, boxID, baseTargetPath)
|
||||
if err = os.MkdirAll(targetDir, 0755); nil != err {
|
||||
if err = os.MkdirAll(targetDir, 0755); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -576,7 +576,7 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
|
|||
return nil
|
||||
})
|
||||
|
||||
if err = filelock.Copy(unzipRootPath, targetDir); nil != err {
|
||||
if err = filelock.Copy(unzipRootPath, targetDir); err != nil {
|
||||
logging.LogErrorf("copy data dir from [%s] to [%s] failed: %s", unzipRootPath, util.DataDir, err)
|
||||
err = errors.New("copy data failed")
|
||||
return
|
||||
|
|
@ -588,7 +588,7 @@ func ImportSY(zipPath, boxID, toPath string) (err error) {
|
|||
p := strings.TrimPrefix(absPath, boxAbsPath)
|
||||
p = filepath.ToSlash(p)
|
||||
tree, err := filesys.LoadTree(boxID, p, luteEngine)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("load tree [%s] failed: %s", treePath, err)
|
||||
continue
|
||||
}
|
||||
|
|
@ -613,13 +613,13 @@ func ImportData(zipPath string) (err error) {
|
|||
baseName = strings.TrimSuffix(baseName, ext)
|
||||
unzipPath := filepath.Join(filepath.Dir(zipPath), baseName)
|
||||
err = gulu.Zip.Unzip(zipPath, unzipPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer os.RemoveAll(unzipPath)
|
||||
|
||||
files, err := filepath.Glob(filepath.Join(unzipPath, "*/*.sy"))
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("check data.zip failed: %s", err)
|
||||
return errors.New("check data.zip failed")
|
||||
}
|
||||
|
|
@ -627,7 +627,7 @@ func ImportData(zipPath string) (err error) {
|
|||
return errors.New(Conf.Language(198))
|
||||
}
|
||||
dirs, err := os.ReadDir(unzipPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("check data.zip failed: %s", err)
|
||||
return errors.New("check data.zip failed")
|
||||
}
|
||||
|
|
@ -636,7 +636,7 @@ func ImportData(zipPath string) (err error) {
|
|||
}
|
||||
|
||||
tmpDataPath := filepath.Join(unzipPath, dirs[0].Name())
|
||||
if err = filelock.Copy(tmpDataPath, util.DataDir); nil != err {
|
||||
if err = filelock.Copy(tmpDataPath, util.DataDir); err != nil {
|
||||
logging.LogErrorf("copy data dir from [%s] to [%s] failed: %s", tmpDataPath, util.DataDir, err)
|
||||
err = errors.New("copy data failed")
|
||||
return
|
||||
|
|
@ -827,7 +827,7 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
|
|||
name = filepath.Base(fullPath)
|
||||
name = util.AssetName(name)
|
||||
assetTargetPath := filepath.Join(assetDirPath, name)
|
||||
if err = filelock.Copy(fullPath, assetTargetPath); nil != err {
|
||||
if err = filelock.Copy(fullPath, assetTargetPath); err != nil {
|
||||
logging.LogErrorf("copy asset from [%s] to [%s] failed: %s", fullPath, assetTargetPath, err)
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
|
@ -864,7 +864,7 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
|
|||
targetPath = path.Join(targetPath, id+".sy")
|
||||
var data []byte
|
||||
data, err = os.ReadFile(localPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tree := parseStdMd(data)
|
||||
|
|
@ -927,7 +927,7 @@ func ImportFromLocalPath(boxID, localPath string, toPath string) (err error) {
|
|||
name := filepath.Base(absolutePath)
|
||||
name = util.AssetName(name)
|
||||
assetTargetPath := filepath.Join(assetDirPath, name)
|
||||
if err = filelock.Copy(absolutePath, assetTargetPath); nil != err {
|
||||
if err = filelock.Copy(absolutePath, assetTargetPath); err != nil {
|
||||
logging.LogErrorf("copy asset from [%s] to [%s] failed: %s", absolutePath, assetTargetPath, err)
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
|
@ -1053,7 +1053,7 @@ func processBase64Img(n *ast.Node, dest string, assetDirPath string, err error)
|
|||
tmpFile.Close()
|
||||
|
||||
assetTargetPath := filepath.Join(assetDirPath, name)
|
||||
if err = filelock.Copy(tmp, assetTargetPath); nil != err {
|
||||
if err = filelock.Copy(tmp, assetTargetPath); err != nil {
|
||||
logging.LogErrorf("copy asset from [%s] to [%s] failed: %s", tmp, assetTargetPath, err)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ func RemoveIndexes(paths []string) {
|
|||
func listSyFiles(dir string) (ret []string) {
|
||||
dirPath := filepath.Join(util.DataDir, dir)
|
||||
err := filelock.Walk(dirPath, func(path string, d fs.FileInfo, err error) error {
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogWarnf("walk dir [%s] failed: %s", dirPath, err)
|
||||
return err
|
||||
}
|
||||
|
|
@ -98,7 +98,7 @@ func listSyFiles(dir string) (ret []string) {
|
|||
}
|
||||
return nil
|
||||
})
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogWarnf("walk dir [%s] failed: %s", dirPath, err)
|
||||
}
|
||||
return
|
||||
|
|
@ -169,7 +169,7 @@ func index(boxID string) {
|
|||
i := treeCount
|
||||
lock.Unlock()
|
||||
tree, err := filesys.LoadTree(box.ID, file.path, luteEngine)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read box [%s] tree [%s] failed: %s", box.ID, file.path, err)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -269,7 +269,7 @@ func recreateTree(tree *parse.Tree, absPath string) {
|
|||
treenode.RemoveBlockTreesByRootID(tree.ID)
|
||||
|
||||
resetTree(tree, "", true)
|
||||
if err := filesys.WriteTree(tree); nil != err {
|
||||
if err := filesys.WriteTree(tree); err != nil {
|
||||
logging.LogWarnf("write tree [%s] failed: %s", tree.Path, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -284,7 +284,7 @@ func recreateTree(tree *parse.Tree, absPath string) {
|
|||
}
|
||||
}
|
||||
|
||||
if err := filelock.Remove(absPath); nil != err {
|
||||
if err := filelock.Remove(absPath); err != nil {
|
||||
logging.LogWarnf("remove [%s] failed: %s", absPath, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -369,7 +369,7 @@ func fixDatabaseIndexByBlockTree() {
|
|||
util.PushStatusBar(fmt.Sprintf(Conf.Language(58), 4, 5))
|
||||
rootUpdatedMap := treenode.GetRootUpdated()
|
||||
dbRootUpdatedMap, err := sql.GetRootUpdated()
|
||||
if nil == err {
|
||||
if err == nil {
|
||||
reindexTreeByUpdated(rootUpdatedMap, dbRootUpdatedMap)
|
||||
}
|
||||
}
|
||||
|
|
@ -445,7 +445,7 @@ func reindexTreeByUpdated(rootUpdatedMap, dbRootUpdatedMap map[string]string) {
|
|||
|
||||
func reindexTreeByPath(box, p string, i, size int, luteEngine *lute.Lute) {
|
||||
tree, err := filesys.LoadTree(box, p, luteEngine)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -460,7 +460,7 @@ func reindexTree(rootID string, i, size int, luteEngine *lute.Lute) {
|
|||
}
|
||||
|
||||
tree, err := filesys.LoadTree(root.BoxID, root.Path, luteEngine)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
if os.IsNotExist(err) {
|
||||
// 文件系统上没有找到该 .sy 文件,则订正块树
|
||||
treenode.RemoveBlockTreesByRootID(rootID)
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ func ListItem2Doc(srcListItemID, targetBoxID, targetPath string) (srcRootBlockID
|
|||
|
||||
newTargetPath = path.Join(toFolder, srcListItemID+".sy")
|
||||
if !box.Exist(toFolder) {
|
||||
if err = box.MkdirAll(toFolder); nil != err {
|
||||
if err = box.MkdirAll(toFolder); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -97,7 +97,7 @@ func ListItem2Doc(srcListItemID, targetBoxID, targetPath string) (srcRootBlockID
|
|||
srcTree.Root.AppendChild(treenode.NewParagraph())
|
||||
}
|
||||
treenode.RemoveBlockTreesByRootID(srcTree.ID)
|
||||
if err = indexWriteTreeUpsertQueue(srcTree); nil != err {
|
||||
if err = indexWriteTreeUpsertQueue(srcTree); err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
|
||||
|
|
@ -105,7 +105,7 @@ func ListItem2Doc(srcListItemID, targetBoxID, targetPath string) (srcRootBlockID
|
|||
newTree.Root.SetIALAttr("updated", util.CurrentTimeSecondsStr())
|
||||
newTree.Root.Spec = "1"
|
||||
box.addMinSort(path.Dir(newTargetPath), newTree.ID)
|
||||
if err = indexWriteTreeUpsertQueue(newTree); nil != err {
|
||||
if err = indexWriteTreeUpsertQueue(newTree); err != nil {
|
||||
return "", "", err
|
||||
}
|
||||
IncSync()
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ func CreateBox(name string) (id string, err error) {
|
|||
id = ast.NewNodeID()
|
||||
boxLocalPath := filepath.Join(util.DataDir, id)
|
||||
err = os.MkdirAll(boxLocalPath, 0755)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -121,13 +121,13 @@ func RemoveBox(boxID string) (err error) {
|
|||
if !isUserGuide {
|
||||
var historyDir string
|
||||
historyDir, err = GetHistoryDir(HistoryOpDelete)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("get history dir failed: %s", err)
|
||||
return
|
||||
}
|
||||
p := strings.TrimPrefix(localPath, util.DataDir)
|
||||
historyPath := filepath.Join(historyDir, p)
|
||||
if err = filelock.Copy(localPath, historyPath); nil != err {
|
||||
if err = filelock.Copy(localPath, historyPath); err != nil {
|
||||
logging.LogErrorf("gen sync history failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -136,7 +136,7 @@ func RemoveBox(boxID string) (err error) {
|
|||
}
|
||||
|
||||
unmount0(boxID)
|
||||
if err = filelock.Remove(localPath); nil != err {
|
||||
if err = filelock.Remove(localPath); err != nil {
|
||||
return
|
||||
}
|
||||
IncSync()
|
||||
|
|
@ -191,18 +191,18 @@ func Mount(boxID string) (alreadyMount bool, err error) {
|
|||
reMountGuide = true
|
||||
}
|
||||
|
||||
if err = filelock.Remove(localPath); nil != err {
|
||||
if err = filelock.Remove(localPath); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
p := filepath.Join(util.WorkingDir, "guide", boxID)
|
||||
if err = filelock.Copy(p, localPath); nil != err {
|
||||
if err = filelock.Copy(p, localPath); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
avDirPath := filepath.Join(util.WorkingDir, "guide", boxID, "storage", "av")
|
||||
if filelock.IsExist(avDirPath) {
|
||||
if err = filelock.Copy(avDirPath, filepath.Join(util.DataDir, "storage", "av")); nil != err {
|
||||
if err = filelock.Copy(avDirPath, filepath.Join(util.DataDir, "storage", "av")); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ func (tx *Transaction) doMoveOutlineHeading(operation *Operation) (ret *TxErr) {
|
|||
parentID := operation.ParentID
|
||||
|
||||
tree, err := tx.loadTree(headingID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: headingID}
|
||||
}
|
||||
operation.RetData = tree.Root.ID
|
||||
|
|
@ -201,7 +201,7 @@ func (tx *Transaction) doMoveOutlineHeading(operation *Operation) (ret *TxErr) {
|
|||
}
|
||||
}
|
||||
|
||||
if err = tx.writeTree(tree); nil != err {
|
||||
if err = tx.writeTree(tree); err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ func createDocsByHPath(boxID, hPath, content, parentID, id string) (retID string
|
|||
if nil != preferredParent && preferredParent.ID == parentID {
|
||||
// 如果父文档存在且 ID 一致,则直接在父文档下创建
|
||||
p := strings.TrimSuffix(preferredParent.Path, ".sy") + "/" + id + ".sy"
|
||||
if _, err = createDoc(boxID, p, name, content); nil != err {
|
||||
if _, err = createDoc(boxID, p, name, content); err != nil {
|
||||
logging.LogErrorf("create doc [%s] failed: %s", p, err)
|
||||
}
|
||||
return
|
||||
|
|
@ -101,18 +101,18 @@ func createDocsByHPath(boxID, hPath, content, parentID, id string) (retID string
|
|||
pathBuilder.WriteString(rootID)
|
||||
docP := pathBuilder.String() + ".sy"
|
||||
if isNotLast {
|
||||
if _, err = createDoc(boxID, docP, part, ""); nil != err {
|
||||
if _, err = createDoc(boxID, docP, part, ""); err != nil {
|
||||
return
|
||||
}
|
||||
} else {
|
||||
if _, err = createDoc(boxID, docP, part, content); nil != err {
|
||||
if _, err = createDoc(boxID, docP, part, content); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if isNotLast {
|
||||
dirPath := filepath.Join(util.DataDir, boxID, pathBuilder.String())
|
||||
if err = os.MkdirAll(dirPath, 0755); nil != err {
|
||||
if err = os.MkdirAll(dirPath, 0755); err != nil {
|
||||
logging.LogErrorf("mkdir [%s] failed: %s", dirPath, err)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -113,7 +113,7 @@ func loadCode(petal *Petal) {
|
|||
}
|
||||
|
||||
data, err := filelock.ReadFile(jsPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read plugin [%s] js failed: %s", petal.Name, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -122,7 +122,7 @@ func loadCode(petal *Petal) {
|
|||
cssPath := filepath.Join(pluginDir, "index.css")
|
||||
if filelock.IsExist(cssPath) {
|
||||
data, err = filelock.ReadFile(cssPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read plugin [%s] css failed: %s", petal.Name, err)
|
||||
} else {
|
||||
petal.CSS = string(data)
|
||||
|
|
@ -167,11 +167,11 @@ func loadCode(petal *Petal) {
|
|||
}
|
||||
|
||||
data, err = filelock.ReadFile(filepath.Join(i18nDir, preferredLang))
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read plugin [%s] i18n failed: %s", petal.Name, err)
|
||||
} else {
|
||||
petal.I18n = map[string]interface{}{}
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &petal.I18n); nil != err {
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &petal.I18n); err != nil {
|
||||
logging.LogErrorf("unmarshal plugin [%s] i18n failed: %s", petal.Name, err)
|
||||
}
|
||||
}
|
||||
|
|
@ -188,11 +188,11 @@ func savePetals(petals []*Petal) {
|
|||
petalDir := filepath.Join(util.DataDir, "storage", "petal")
|
||||
confPath := filepath.Join(petalDir, "petals.json")
|
||||
data, err := gulu.JSON.MarshalIndentJSON(petals, "", "\t")
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("marshal petals failed: %s", err)
|
||||
return
|
||||
}
|
||||
if err = filelock.WriteFile(confPath, data); nil != err {
|
||||
if err = filelock.WriteFile(confPath, data); err != nil {
|
||||
logging.LogErrorf("write petals [%s] failed: %s", confPath, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -204,7 +204,7 @@ func getPetals() (ret []*Petal) {
|
|||
|
||||
ret = []*Petal{}
|
||||
petalDir := filepath.Join(util.DataDir, "storage", "petal")
|
||||
if err := os.MkdirAll(petalDir, 0755); nil != err {
|
||||
if err := os.MkdirAll(petalDir, 0755); err != nil {
|
||||
logging.LogErrorf("create petal dir [%s] failed: %s", petalDir, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -212,11 +212,11 @@ func getPetals() (ret []*Petal) {
|
|||
confPath := filepath.Join(petalDir, "petals.json")
|
||||
if !filelock.IsExist(confPath) {
|
||||
data, err := gulu.JSON.MarshalIndentJSON(ret, "", "\t")
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("marshal petals failed: %s", err)
|
||||
return
|
||||
}
|
||||
if err = filelock.WriteFile(confPath, data); nil != err {
|
||||
if err = filelock.WriteFile(confPath, data); err != nil {
|
||||
logging.LogErrorf("write petals [%s] failed: %s", confPath, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -224,12 +224,12 @@ func getPetals() (ret []*Petal) {
|
|||
}
|
||||
|
||||
data, err := filelock.ReadFile(confPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read petal file [%s] failed: %s", confPath, err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &ret); nil != err {
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &ret); err != nil {
|
||||
logging.LogErrorf("unmarshal petals failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -87,13 +87,13 @@ var uiProcNames = []string{"siyuan", "electron"}
|
|||
func getAttachedUIProcCount() (ret int) {
|
||||
util.UIProcessIDs.Range(func(uiProcIDArg, _ interface{}) bool {
|
||||
uiProcID, err := strconv.Atoi(uiProcIDArg.(string))
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("invalid UI proc ID [%s]: %s", uiProcIDArg, err)
|
||||
return true
|
||||
}
|
||||
|
||||
proc, err := goPS.FindProcess(uiProcID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("find UI proc [%d] failed: %s", uiProcID, err)
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -282,7 +282,7 @@ func renderBlockMarkdownR(id string, rendered *[]string) (ret []*ast.Node) {
|
|||
|
||||
var err error
|
||||
var t *parse.Tree
|
||||
if t, err = LoadTreeByBlockID(b.ID); nil != err {
|
||||
if t, err = LoadTreeByBlockID(b.ID); err != nil {
|
||||
return
|
||||
}
|
||||
node := treenode.GetNodeInTree(t, b.ID)
|
||||
|
|
|
|||
|
|
@ -65,12 +65,12 @@ func GetRepoFile(fileID string) (ret []byte, p string, err error) {
|
|||
}
|
||||
|
||||
repo, err := newRepository()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
file, err := repo.GetFile(fileID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -86,17 +86,17 @@ func OpenRepoSnapshotDoc(fileID string) (content string, isProtyleDoc bool, upda
|
|||
}
|
||||
|
||||
repo, err := newRepository()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
file, err := repo.GetFile(fileID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
data, err := repo.OpenFile(file)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -106,7 +106,7 @@ func OpenRepoSnapshotDoc(fileID string) (content string, isProtyleDoc bool, upda
|
|||
luteEngine := NewLute()
|
||||
var snapshotTree *parse.Tree
|
||||
isProtyleDoc, snapshotTree, err = parseTreeInSnapshot(data, luteEngine)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("parse tree from snapshot file [%s] failed", fileID)
|
||||
return
|
||||
}
|
||||
|
|
@ -204,12 +204,12 @@ func DiffRepoSnapshots(left, right string) (ret *LeftRightDiff, err error) {
|
|||
}
|
||||
|
||||
repo, err := newRepository()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
diff, err := repo.DiffIndex(left, right)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -300,7 +300,7 @@ func DiffRepoSnapshots(left, right string) (ret *LeftRightDiff, err error) {
|
|||
|
||||
func parseTitleInSnapshot(fileID string, repo *dejavu.Repo, luteEngine *lute.Lute) (title string, err error) {
|
||||
file, err := repo.GetFile(fileID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("get file [%s] failed: %s", fileID, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -309,14 +309,14 @@ func parseTitleInSnapshot(fileID string, repo *dejavu.Repo, luteEngine *lute.Lut
|
|||
if strings.HasSuffix(file.Path, ".sy") {
|
||||
var data []byte
|
||||
data, err = repo.OpenFile(file)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("open file [%s] failed: %s", fileID, err)
|
||||
return
|
||||
}
|
||||
|
||||
var tree *parse.Tree
|
||||
tree, err = filesys.ParseJSONWithoutFix(data, luteEngine.ParseOptions)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("parse file [%s] failed: %s", fileID, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -329,7 +329,7 @@ func parseTitleInSnapshot(fileID string, repo *dejavu.Repo, luteEngine *lute.Lut
|
|||
func parseTreeInSnapshot(data []byte, luteEngine *lute.Lute) (isProtyleDoc bool, tree *parse.Tree, err error) {
|
||||
isProtyleDoc = 1024*1024*1 <= len(data)
|
||||
tree, err = filesys.ParseJSONWithoutFix(data, luteEngine.ParseOptions)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
|
|
@ -353,12 +353,12 @@ func GetRepoSnapshots(page int) (ret []*Snapshot, pageCount, totalCount int, err
|
|||
}
|
||||
|
||||
repo, err := newRepository()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
logs, pageCount, totalCount, err := repo.GetIndexLogs(page, 32)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
if dejavu.ErrNotFoundIndex == err {
|
||||
logs = []*dejavu.Log{}
|
||||
err = nil
|
||||
|
|
@ -435,7 +435,7 @@ func ImportRepoKey(base64Key string) (retKey string, err error) {
|
|||
}
|
||||
|
||||
key, err := base64.StdEncoding.DecodeString(retKey)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("import data repo key failed: %s", err)
|
||||
return "", errors.New(Conf.Language(157))
|
||||
}
|
||||
|
|
@ -446,10 +446,10 @@ func ImportRepoKey(base64Key string) (retKey string, err error) {
|
|||
Conf.Repo.Key = key
|
||||
Conf.Save()
|
||||
|
||||
if err = os.RemoveAll(Conf.Repo.GetSaveDir()); nil != err {
|
||||
if err = os.RemoveAll(Conf.Repo.GetSaveDir()); err != nil {
|
||||
return
|
||||
}
|
||||
if err = os.MkdirAll(Conf.Repo.GetSaveDir(), 0755); nil != err {
|
||||
if err = os.MkdirAll(Conf.Repo.GetSaveDir(), 0755); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -462,11 +462,11 @@ func ResetRepo() (err error) {
|
|||
msgId := util.PushMsg(Conf.Language(144), 1000*60)
|
||||
|
||||
repo, err := newRepository()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err = repo.Reset(); nil != err {
|
||||
if err = repo.Reset(); err != nil {
|
||||
logging.LogErrorf("reset data repo failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -490,12 +490,12 @@ func PurgeCloud() (err error) {
|
|||
defer util.PushClearProgress()
|
||||
|
||||
repo, err := newRepository()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
stat, err := repo.PurgeCloud()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -513,12 +513,12 @@ func PurgeRepo() (err error) {
|
|||
defer util.PushClearProgress()
|
||||
|
||||
repo, err := newRepository()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
stat, err := repo.Purge()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -538,10 +538,10 @@ func InitRepoKeyFromPassphrase(passphrase string) (err error) {
|
|||
}
|
||||
|
||||
util.PushMsg(Conf.Language(136), 3000)
|
||||
if err = os.RemoveAll(Conf.Repo.GetSaveDir()); nil != err {
|
||||
if err = os.RemoveAll(Conf.Repo.GetSaveDir()); err != nil {
|
||||
return
|
||||
}
|
||||
if err = os.MkdirAll(Conf.Repo.GetSaveDir(), 0755); nil != err {
|
||||
if err = os.MkdirAll(Conf.Repo.GetSaveDir(), 0755); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -554,7 +554,7 @@ func InitRepoKeyFromPassphrase(passphrase string) (err error) {
|
|||
} else {
|
||||
salt := fmt.Sprintf("%x", sha256.Sum256([]byte(passphrase)))[:16]
|
||||
key, err = encryption.KDF(passphrase, salt)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("init data repo key failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -570,29 +570,29 @@ func InitRepoKeyFromPassphrase(passphrase string) (err error) {
|
|||
func InitRepoKey() (err error) {
|
||||
util.PushMsg(Conf.Language(136), 3000)
|
||||
|
||||
if err = os.RemoveAll(Conf.Repo.GetSaveDir()); nil != err {
|
||||
if err = os.RemoveAll(Conf.Repo.GetSaveDir()); err != nil {
|
||||
return
|
||||
}
|
||||
if err = os.MkdirAll(Conf.Repo.GetSaveDir(), 0755); nil != err {
|
||||
if err = os.MkdirAll(Conf.Repo.GetSaveDir(), 0755); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
randomBytes := make([]byte, 16)
|
||||
_, err = rand.Read(randomBytes)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
password := string(randomBytes)
|
||||
randomBytes = make([]byte, 16)
|
||||
_, err = rand.Read(randomBytes)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("init data repo key failed: %s", err)
|
||||
return
|
||||
}
|
||||
salt := string(randomBytes)
|
||||
|
||||
key, err := encryption.KDF(password, salt)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("init data repo key failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -624,7 +624,7 @@ func checkoutRepo(id string) {
|
|||
}
|
||||
|
||||
repo, err := newRepository()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("new repository failed: %s", err)
|
||||
util.PushErrMsg(Conf.Language(141), 7000)
|
||||
return
|
||||
|
|
@ -643,7 +643,7 @@ func checkoutRepo(id string) {
|
|||
Conf.Save()
|
||||
|
||||
_, _, err = repo.Checkout(id, map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBarAndProgress})
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("checkout repository failed: %s", err)
|
||||
util.PushClearProgress()
|
||||
util.PushErrMsg(Conf.Language(141), 7000)
|
||||
|
|
@ -674,7 +674,7 @@ func DownloadCloudSnapshot(tag, id string) (err error) {
|
|||
}
|
||||
|
||||
repo, err := newRepository()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -700,7 +700,7 @@ func DownloadCloudSnapshot(tag, id string) (err error) {
|
|||
} else {
|
||||
downloadFileCount, downloadChunkCount, downloadBytes, err = repo.DownloadTagIndex(tag, id, map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBarAndProgress})
|
||||
}
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
msg := fmt.Sprintf(Conf.Language(153), downloadFileCount, downloadChunkCount, humanize.BytesCustomCeil(uint64(downloadBytes), 2))
|
||||
|
|
@ -716,7 +716,7 @@ func UploadCloudSnapshot(tag, id string) (err error) {
|
|||
}
|
||||
|
||||
repo, err := newRepository()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -736,7 +736,7 @@ func UploadCloudSnapshot(tag, id string) (err error) {
|
|||
util.PushEndlessProgress(Conf.Language(116))
|
||||
defer util.PushClearProgress()
|
||||
uploadFileCount, uploadChunkCount, uploadBytes, err := repo.UploadTagIndex(tag, id, map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBarAndProgress})
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
if errors.Is(err, dejavu.ErrCloudBackupCountExceeded) {
|
||||
err = fmt.Errorf(Conf.Language(84), Conf.Language(154))
|
||||
return
|
||||
|
|
@ -762,7 +762,7 @@ func RemoveCloudRepoTag(tag string) (err error) {
|
|||
}
|
||||
|
||||
repo, err := newRepository()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -780,7 +780,7 @@ func RemoveCloudRepoTag(tag string) (err error) {
|
|||
}
|
||||
|
||||
err = repo.RemoveCloudRepoTag(tag)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
|
|
@ -794,7 +794,7 @@ func GetCloudRepoTagSnapshots() (ret []*dejavu.Log, err error) {
|
|||
}
|
||||
|
||||
repo, err := newRepository()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -812,7 +812,7 @@ func GetCloudRepoTagSnapshots() (ret []*dejavu.Log, err error) {
|
|||
}
|
||||
|
||||
logs, err := repo.GetCloudRepoTagLogs(map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBar})
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
ret = logs
|
||||
|
|
@ -830,7 +830,7 @@ func GetCloudRepoSnapshots(page int) (ret []*dejavu.Log, pageCount, totalCount i
|
|||
}
|
||||
|
||||
repo, err := newRepository()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -852,7 +852,7 @@ func GetCloudRepoSnapshots(page int) (ret []*dejavu.Log, pageCount, totalCount i
|
|||
}
|
||||
|
||||
logs, pageCount, totalCount, err := repo.GetCloudRepoLogs(page)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
ret = logs
|
||||
|
|
@ -870,12 +870,12 @@ func GetTagSnapshots() (ret []*Snapshot, err error) {
|
|||
}
|
||||
|
||||
repo, err := newRepository()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
logs, err := repo.GetTagLogs()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
ret = buildSnapshots(logs)
|
||||
|
|
@ -892,7 +892,7 @@ func RemoveTagSnapshot(tag string) (err error) {
|
|||
}
|
||||
|
||||
repo, err := newRepository()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -919,16 +919,16 @@ func TagSnapshot(id, name string) (err error) {
|
|||
}
|
||||
|
||||
repo, err := newRepository()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
index, err := repo.GetIndex(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err = repo.AddTag(index.ID, name); nil != err {
|
||||
if err = repo.AddTag(index.ID, name); err != nil {
|
||||
msg := fmt.Sprintf("Add tag to data snapshot [%s] failed: %s", index.ID, err)
|
||||
util.PushStatusBar(msg)
|
||||
return
|
||||
|
|
@ -950,7 +950,7 @@ func IndexRepo(memo string) (err error) {
|
|||
}
|
||||
|
||||
repo, err := newRepository()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -962,7 +962,7 @@ func IndexRepo(memo string) (err error) {
|
|||
index, err := repo.Index(memo, map[string]interface{}{
|
||||
eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBarAndProgress,
|
||||
})
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
util.PushStatusBar("Index data repo failed: " + html.EscapeString(err.Error()))
|
||||
return
|
||||
}
|
||||
|
|
@ -1011,7 +1011,7 @@ func syncRepoDownload() (err error) {
|
|||
}
|
||||
|
||||
repo, err := newRepository()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
planSyncAfter(fixSyncInterval)
|
||||
|
||||
msg := fmt.Sprintf("sync repo failed: %s", err)
|
||||
|
|
@ -1024,7 +1024,7 @@ func syncRepoDownload() (err error) {
|
|||
logging.LogInfof("downloading data repo [device=%s, kernel=%s, provider=%d, mode=%s/%t]", Conf.System.ID, KernelID, Conf.Sync.Provider, "d", true)
|
||||
start := time.Now()
|
||||
_, _, err = indexRepoBeforeCloudSync(repo)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
planSyncAfter(fixSyncInterval)
|
||||
|
||||
logging.LogErrorf("sync data repo download failed: %s", err)
|
||||
|
|
@ -1039,7 +1039,7 @@ func syncRepoDownload() (err error) {
|
|||
syncContext := map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBar}
|
||||
mergeResult, trafficStat, err := repo.SyncDownload(syncContext)
|
||||
elapsed := time.Since(start)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
planSyncAfter(fixSyncInterval)
|
||||
|
||||
logging.LogErrorf("sync data repo download failed: %s", err)
|
||||
|
|
@ -1082,7 +1082,7 @@ func syncRepoUpload() (err error) {
|
|||
}
|
||||
|
||||
repo, err := newRepository()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
planSyncAfter(fixSyncInterval)
|
||||
|
||||
msg := fmt.Sprintf("sync repo failed: %s", err)
|
||||
|
|
@ -1095,7 +1095,7 @@ func syncRepoUpload() (err error) {
|
|||
logging.LogInfof("uploading data repo [device=%s, kernel=%s, provider=%d, mode=%s/%t]", Conf.System.ID, KernelID, Conf.Sync.Provider, "u", true)
|
||||
start := time.Now()
|
||||
_, _, err = indexRepoBeforeCloudSync(repo)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
planSyncAfter(fixSyncInterval)
|
||||
|
||||
logging.LogErrorf("sync data repo upload failed: %s", err)
|
||||
|
|
@ -1110,7 +1110,7 @@ func syncRepoUpload() (err error) {
|
|||
syncContext := map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBar}
|
||||
trafficStat, err := repo.SyncUpload(syncContext)
|
||||
elapsed := time.Since(start)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
planSyncAfter(fixSyncInterval)
|
||||
|
||||
logging.LogErrorf("sync data repo upload failed: %s", err)
|
||||
|
|
@ -1156,7 +1156,7 @@ func bootSyncRepo() (err error) {
|
|||
}
|
||||
|
||||
repo, err := newRepository()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
autoSyncErrCount++
|
||||
planSyncAfter(fixSyncInterval)
|
||||
|
||||
|
|
@ -1171,7 +1171,7 @@ func bootSyncRepo() (err error) {
|
|||
|
||||
start := time.Now()
|
||||
_, _, err = indexRepoBeforeCloudSync(repo)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
autoSyncErrCount++
|
||||
planSyncAfter(fixSyncInterval)
|
||||
|
||||
|
|
@ -1217,7 +1217,7 @@ func bootSyncRepo() (err error) {
|
|||
|
||||
elapsed := time.Since(start)
|
||||
logging.LogInfof("boot get sync cloud files elapsed [%.2fs]", elapsed.Seconds())
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
autoSyncErrCount++
|
||||
planSyncAfter(fixSyncInterval)
|
||||
|
||||
|
|
@ -1243,7 +1243,7 @@ func bootSyncRepo() (err error) {
|
|||
go func() {
|
||||
_, syncErr := syncRepo(false, false)
|
||||
isBootSyncing.Store(false)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("boot background sync repo failed: %s", syncErr)
|
||||
return
|
||||
}
|
||||
|
|
@ -1267,7 +1267,7 @@ func syncRepo(exit, byHand bool) (dataChanged bool, err error) {
|
|||
}
|
||||
|
||||
repo, err := newRepository()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
autoSyncErrCount++
|
||||
planSyncAfter(fixSyncInterval)
|
||||
|
||||
|
|
@ -1281,7 +1281,7 @@ func syncRepo(exit, byHand bool) (dataChanged bool, err error) {
|
|||
logging.LogInfof("syncing data repo [device=%s, kernel=%s, provider=%d, mode=%s/%t]", Conf.System.ID, KernelID, Conf.Sync.Provider, "a", byHand)
|
||||
start := time.Now()
|
||||
beforeIndex, afterIndex, err := indexRepoBeforeCloudSync(repo)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
autoSyncErrCount++
|
||||
planSyncAfter(fixSyncInterval)
|
||||
|
||||
|
|
@ -1302,7 +1302,7 @@ func syncRepo(exit, byHand bool) (dataChanged bool, err error) {
|
|||
syncContext := map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBar}
|
||||
mergeResult, trafficStat, err := repo.Sync(syncContext)
|
||||
elapsed := time.Since(start)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
autoSyncErrCount++
|
||||
planSyncAfter(fixSyncInterval)
|
||||
|
||||
|
|
@ -1610,7 +1610,7 @@ func indexRepoBeforeCloudSync(repo *dejavu.Repo) (beforeIndex, afterIndex *entit
|
|||
afterIndex, err = repo.Index("[Sync] Cloud sync", map[string]interface{}{
|
||||
eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBar,
|
||||
})
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("index data repo before cloud sync failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -1619,7 +1619,7 @@ func indexRepoBeforeCloudSync(repo *dejavu.Repo) (beforeIndex, afterIndex *entit
|
|||
if nil == beforeIndex || beforeIndex.ID != afterIndex.ID {
|
||||
// 对新创建的快照需要更新备注,加入耗时统计
|
||||
afterIndex.Memo = fmt.Sprintf("[Sync] Cloud sync, completed in %.2fs", elapsed.Seconds())
|
||||
if err = repo.PutIndex(afterIndex); nil != err {
|
||||
if err = repo.PutIndex(afterIndex); err != nil {
|
||||
util.PushStatusBar("Save data snapshot for cloud sync failed")
|
||||
logging.LogErrorf("put index into data repo before cloud sync failed: %s", err)
|
||||
return
|
||||
|
|
@ -1651,7 +1651,7 @@ func indexRepoBeforeCloudSync(repo *dejavu.Repo) (beforeIndex, afterIndex *entit
|
|||
|
||||
func newRepository() (ret *dejavu.Repo, err error) {
|
||||
cloudConf, err := buildCloudConf()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -1680,7 +1680,7 @@ func newRepository() (ret *dejavu.Repo, err error) {
|
|||
ignoreLines := getSyncIgnoreLines()
|
||||
ignoreLines = append(ignoreLines, "/.siyuan/conf.json") // 忽略旧版同步配置
|
||||
ret, err = dejavu.NewRepo(util.DataDir, util.RepoDir, util.HistoryDir, util.TempDir, Conf.System.ID, Conf.System.Name, Conf.System.OS, Conf.Repo.Key, ignoreLines, cloudRepo)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("init data repo failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -1978,7 +1978,7 @@ type Sync struct {
|
|||
|
||||
func GetCloudSpace() (s *Sync, b *Backup, hSize, hAssetSize, hTotalSize, hExchangeSize, hTrafficUploadSize, hTrafficDownloadSize, hTrafficAPIGet, hTrafficAPIPut string, err error) {
|
||||
stat, err := getCloudSpace()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
err = errors.New(Conf.Language(30) + " " + err.Error())
|
||||
return
|
||||
}
|
||||
|
|
@ -2027,12 +2027,12 @@ func GetCloudSpace() (s *Sync, b *Backup, hSize, hAssetSize, hTotalSize, hExchan
|
|||
|
||||
func getCloudSpace() (stat *cloud.Stat, err error) {
|
||||
repo, err := newRepository()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
stat, err = repo.GetCloudRepoStat()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("get cloud repo stat failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ func ListInvalidBlockRefs(page, pageSize int) (ret []*Block, matchedBlockCount,
|
|||
blockMap := map[string]bool{}
|
||||
var invalidBlockIDs []string
|
||||
notebooks, err := ListNotebooks()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
luteEngine := util.NewLute()
|
||||
|
|
@ -469,7 +469,7 @@ func FindReplace(keyword, replacement string, replaceTypes map[string]bool, ids
|
|||
cachedTrees := map[string]*parse.Tree{}
|
||||
|
||||
historyDir, err := getHistoryDir(HistoryOpReplace, time.Now())
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("get history dir failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -499,7 +499,7 @@ func FindReplace(keyword, replacement string, replaceTypes map[string]bool, ids
|
|||
}
|
||||
|
||||
historyPath := filepath.Join(historyDir, tree.Box, tree.Path)
|
||||
if err = os.MkdirAll(filepath.Dir(historyPath), 0755); nil != err {
|
||||
if err = os.MkdirAll(filepath.Dir(historyPath), 0755); err != nil {
|
||||
logging.LogErrorf("generate history failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -773,7 +773,7 @@ func FindReplace(keyword, replacement string, replaceTypes map[string]bool, ids
|
|||
unlink.Unlink()
|
||||
}
|
||||
|
||||
if err = writeTreeUpsertQueue(tree); nil != err {
|
||||
if err = writeTreeUpsertQueue(tree); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -1069,7 +1069,7 @@ func buildOrderBy(query string, method, orderBy int) string {
|
|||
|
||||
func buildTypeFilter(types map[string]bool) string {
|
||||
s := conf.NewSearch()
|
||||
if err := copier.Copy(s, Conf.Search); nil != err {
|
||||
if err := copier.Copy(s, Conf.Search); err != nil {
|
||||
logging.LogErrorf("copy search conf failed: %s", err)
|
||||
}
|
||||
if nil != types {
|
||||
|
|
@ -1141,7 +1141,7 @@ func searchBySQL(stmt string, beforeLen, page, pageSize int) (ret []*Block, matc
|
|||
|
||||
func removeLimitClause(stmt string) string {
|
||||
parsedStmt, err := sqlparser.Parse(stmt)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return stmt
|
||||
}
|
||||
|
||||
|
|
@ -1728,17 +1728,17 @@ func getSearchIgnoreLines() (ret []string) {
|
|||
|
||||
searchIgnorePath := filepath.Join(util.DataDir, ".siyuan", "searchignore")
|
||||
err := os.MkdirAll(filepath.Dir(searchIgnorePath), 0755)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if !gulu.File.IsExist(searchIgnorePath) {
|
||||
if err = gulu.File.WriteFileSafer(searchIgnorePath, nil, 0644); nil != err {
|
||||
if err = gulu.File.WriteFileSafer(searchIgnorePath, nil, 0644); err != nil {
|
||||
logging.LogErrorf("create searchignore [%s] failed: %s", searchIgnorePath, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
data, err := os.ReadFile(searchIgnorePath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read searchignore [%s] failed: %s", searchIgnorePath, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -1778,17 +1778,17 @@ func getRefSearchIgnoreLines() (ret []string) {
|
|||
|
||||
searchIgnorePath := filepath.Join(util.DataDir, ".siyuan", "refsearchignore")
|
||||
err := os.MkdirAll(filepath.Dir(searchIgnorePath), 0755)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if !gulu.File.IsExist(searchIgnorePath) {
|
||||
if err = gulu.File.WriteFileSafer(searchIgnorePath, nil, 0644); nil != err {
|
||||
if err = gulu.File.WriteFileSafer(searchIgnorePath, nil, 0644); err != nil {
|
||||
logging.LogErrorf("create refsearchignore [%s] failed: %s", searchIgnorePath, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
data, err := os.ReadFile(searchIgnorePath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read refsearchignore [%s] failed: %s", searchIgnorePath, err)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ func LogoutAuth(c *gin.Context) {
|
|||
|
||||
session := util.GetSession(c)
|
||||
util.RemoveWorkspaceSession(session)
|
||||
if err := session.Save(c); nil != err {
|
||||
if err := session.Save(c); err != nil {
|
||||
logging.LogErrorf("saves session failed: " + err.Error())
|
||||
ret.Code = -1
|
||||
ret.Msg = "save session failed"
|
||||
|
|
@ -102,7 +102,7 @@ func LoginAuth(c *gin.Context) {
|
|||
ret.Code = 1 // 需要渲染验证码
|
||||
}
|
||||
|
||||
if err := session.Save(c); nil != err {
|
||||
if err := session.Save(c); err != nil {
|
||||
logging.LogErrorf("save session failed: " + err.Error())
|
||||
c.Status(http.StatusInternalServerError)
|
||||
return
|
||||
|
|
@ -114,7 +114,7 @@ func LoginAuth(c *gin.Context) {
|
|||
util.WrongAuthCount = 0
|
||||
workspaceSession.Captcha = gulu.Rand.String(7)
|
||||
logging.LogInfof("auth success [ip=%s]", util.GetRemoteAddr(c.Request))
|
||||
if err := session.Save(c); nil != err {
|
||||
if err := session.Save(c); err != nil {
|
||||
logging.LogErrorf("save session failed: " + err.Error())
|
||||
c.Status(http.StatusInternalServerError)
|
||||
return
|
||||
|
|
@ -128,7 +128,7 @@ func GetCaptcha(c *gin.Context) {
|
|||
options.CurveNumber = 0
|
||||
options.BackgroundColor = color.White
|
||||
})
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("generates captcha failed: " + err.Error())
|
||||
c.Status(http.StatusInternalServerError)
|
||||
return
|
||||
|
|
@ -137,13 +137,13 @@ func GetCaptcha(c *gin.Context) {
|
|||
session := util.GetSession(c)
|
||||
workspaceSession := util.GetWorkspaceSession(session)
|
||||
workspaceSession.Captcha = img.Text
|
||||
if err = session.Save(c); nil != err {
|
||||
if err = session.Save(c); err != nil {
|
||||
logging.LogErrorf("save session failed: " + err.Error())
|
||||
c.Status(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
if err = img.WriteImage(c.Writer); nil != err {
|
||||
if err = img.WriteImage(c.Writer); err != nil {
|
||||
logging.LogErrorf("writes captcha image failed: " + err.Error())
|
||||
c.Status(http.StatusInternalServerError)
|
||||
return
|
||||
|
|
@ -369,7 +369,7 @@ func Timing(c *gin.Context) {
|
|||
timing := 15 * 1000
|
||||
if timingEnv := os.Getenv("SIYUAN_PERFORMANCE_TIMING"); "" != timingEnv {
|
||||
val, err := strconv.Atoi(timingEnv)
|
||||
if nil == err {
|
||||
if err == nil {
|
||||
timing = val
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ func RemoveSnippet(id string) (ret *conf.Snippet, err error) {
|
|||
defer snippetsLock.Unlock()
|
||||
|
||||
snippets, err := loadSnippets()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -73,12 +73,12 @@ func loadSnippets() (ret []*conf.Snippet, err error) {
|
|||
}
|
||||
|
||||
data, err := filelock.ReadFile(confPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("load js snippets failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &ret); nil != err {
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &ret); err != nil {
|
||||
logging.LogErrorf("unmarshal js snippets failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -98,12 +98,12 @@ func loadSnippets() (ret []*conf.Snippet, err error) {
|
|||
|
||||
func writeSnippetsConf(snippets []*conf.Snippet) (err error) {
|
||||
data, err := gulu.JSON.MarshalIndentJSON(snippets, "", " ")
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("marshal snippets failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = os.MkdirAll(util.SnippetsPath, 0755); nil != err {
|
||||
if err = os.MkdirAll(util.SnippetsPath, 0755); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ func RemoveRecentDoc(ids []string) {
|
|||
defer recentDocLock.Unlock()
|
||||
|
||||
recentDocs, err := getRecentDocs()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -57,7 +57,7 @@ func RemoveRecentDoc(ids []string) {
|
|||
}
|
||||
|
||||
err = setRecentDocs(recentDocs)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
|
|
@ -74,7 +74,7 @@ func setRecentDocByTree(tree *parse.Tree) {
|
|||
defer recentDocLock.Unlock()
|
||||
|
||||
recentDocs, err := getRecentDocs()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -102,20 +102,20 @@ func GetRecentDocs() (ret []*RecentDoc, err error) {
|
|||
|
||||
func setRecentDocs(recentDocs []*RecentDoc) (err error) {
|
||||
dirPath := filepath.Join(util.DataDir, "storage")
|
||||
if err = os.MkdirAll(dirPath, 0755); nil != err {
|
||||
if err = os.MkdirAll(dirPath, 0755); err != nil {
|
||||
logging.LogErrorf("create storage [recent-doc] dir failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
data, err := gulu.JSON.MarshalIndentJSON(recentDocs, "", " ")
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("marshal storage [recent-doc] failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
lsPath := filepath.Join(dirPath, "recent-doc.json")
|
||||
err = filelock.WriteFile(lsPath, data)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("write storage [recent-doc] failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -130,12 +130,12 @@ func getRecentDocs() (ret []*RecentDoc, err error) {
|
|||
}
|
||||
|
||||
data, err := filelock.ReadFile(dataPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read storage [recent-doc] failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &tmp); nil != err {
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &tmp); err != nil {
|
||||
logging.LogErrorf("unmarshal storage [recent-doc] failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -227,7 +227,7 @@ func RemoveCriterion(name string) (err error) {
|
|||
defer criteriaLock.Unlock()
|
||||
|
||||
criteria, err := getCriteria()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -251,7 +251,7 @@ func SetCriterion(criterion *Criterion) (err error) {
|
|||
defer criteriaLock.Unlock()
|
||||
|
||||
criteria, err := getCriteria()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -280,20 +280,20 @@ func GetCriteria() (ret []*Criterion) {
|
|||
|
||||
func setCriteria(criteria []*Criterion) (err error) {
|
||||
dirPath := filepath.Join(util.DataDir, "storage")
|
||||
if err = os.MkdirAll(dirPath, 0755); nil != err {
|
||||
if err = os.MkdirAll(dirPath, 0755); err != nil {
|
||||
logging.LogErrorf("create storage [criteria] dir failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
data, err := gulu.JSON.MarshalIndentJSON(criteria, "", " ")
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("marshal storage [criteria] failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
lsPath := filepath.Join(dirPath, "criteria.json")
|
||||
err = filelock.WriteFile(lsPath, data)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("write storage [criteria] failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -308,12 +308,12 @@ func getCriteria() (ret []*Criterion, err error) {
|
|||
}
|
||||
|
||||
data, err := filelock.ReadFile(dataPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read storage [criteria] failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &ret); nil != err {
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &ret); err != nil {
|
||||
logging.LogErrorf("unmarshal storage [criteria] failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -360,20 +360,20 @@ func setLocalStorage(val interface{}) (err error) {
|
|||
}
|
||||
|
||||
dirPath := filepath.Join(util.DataDir, "storage")
|
||||
if err = os.MkdirAll(dirPath, 0755); nil != err {
|
||||
if err = os.MkdirAll(dirPath, 0755); err != nil {
|
||||
logging.LogErrorf("create storage [local] dir failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
data, err := gulu.JSON.MarshalIndentJSON(val, "", " ")
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("marshal storage [local] failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
lsPath := filepath.Join(dirPath, "local.json")
|
||||
err = filelock.WriteFile(lsPath, data)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("write storage [local] failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -389,12 +389,12 @@ func getLocalStorage() (ret map[string]interface{}) {
|
|||
}
|
||||
|
||||
data, err := filelock.ReadFile(lsPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read storage [local] failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &ret); nil != err {
|
||||
if err = gulu.JSON.UnmarshalJSON(data, &ret); err != nil {
|
||||
logging.LogErrorf("unmarshal storage [local] failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ func SyncDataDownload() {
|
|||
|
||||
err := syncRepoDownload()
|
||||
code := 1
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
code = 2
|
||||
}
|
||||
util.BroadcastByType("main", "syncing", code, Conf.Sync.Stat, nil)
|
||||
|
|
@ -92,7 +92,7 @@ func SyncDataUpload() {
|
|||
|
||||
err := syncRepoUpload()
|
||||
code := 1
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
code = 2
|
||||
}
|
||||
util.BroadcastByType("main", "syncing", code, Conf.Sync.Stat, nil)
|
||||
|
|
@ -151,7 +151,7 @@ func BootSyncData() {
|
|||
util.BroadcastByType("main", "syncing", 0, Conf.Language(81), nil)
|
||||
err := bootSyncRepo()
|
||||
code := 1
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
code = 2
|
||||
}
|
||||
util.BroadcastByType("main", "syncing", code, Conf.Sync.Stat, nil)
|
||||
|
|
@ -202,7 +202,7 @@ func syncData(exit, byHand bool) {
|
|||
|
||||
dataChanged, err := syncRepo(exit, byHand)
|
||||
code := 1
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
code = 2
|
||||
}
|
||||
util.BroadcastByType("main", "syncing", code, Conf.Sync.Stat, nil)
|
||||
|
|
@ -474,12 +474,12 @@ func CreateCloudSyncDir(name string) (err error) {
|
|||
}
|
||||
|
||||
repo, err := newRepository()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = repo.CreateCloudRepo(name)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
err = errors.New(formatRepoErrorMsg(err))
|
||||
return
|
||||
}
|
||||
|
|
@ -499,12 +499,12 @@ func RemoveCloudSyncDir(name string) (err error) {
|
|||
}
|
||||
|
||||
repo, err := newRepository()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
err = repo.RemoveCloudRepo(name)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
err = errors.New(formatRepoErrorMsg(err))
|
||||
return
|
||||
}
|
||||
|
|
@ -525,12 +525,12 @@ func ListCloudSyncDir() (syncDirs []*Sync, hSize string, err error) {
|
|||
var size int64
|
||||
|
||||
repo, err := newRepository()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
dirs, size, err = repo.GetCloudRepos()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
err = errors.New(formatRepoErrorMsg(err))
|
||||
return
|
||||
}
|
||||
|
|
@ -606,17 +606,17 @@ func formatRepoErrorMsg(err error) string {
|
|||
func getSyncIgnoreLines() (ret []string) {
|
||||
ignore := filepath.Join(util.DataDir, ".siyuan", "syncignore")
|
||||
err := os.MkdirAll(filepath.Dir(ignore), 0755)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
if !gulu.File.IsExist(ignore) {
|
||||
if err = gulu.File.WriteFileSafer(ignore, nil, 0644); nil != err {
|
||||
if err = gulu.File.WriteFileSafer(ignore, nil, 0644); err != nil {
|
||||
logging.LogErrorf("create syncignore [%s] failed: %s", ignore, err)
|
||||
return
|
||||
}
|
||||
}
|
||||
data, err := os.ReadFile(ignore)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read syncignore [%s] failed: %s", ignore, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -831,7 +831,7 @@ func dialSyncWebSocket() (c *websocket.Conn, err error) {
|
|||
"x-siyuan-repo": []string{Conf.Sync.CloudName},
|
||||
}
|
||||
c, _, err = websocket.DefaultDialer.Dial(endpoint, header)
|
||||
if nil == err {
|
||||
if err == nil {
|
||||
closedSyncWebSocket.Store(false)
|
||||
}
|
||||
return
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ func RemoveTag(label string) (err error) {
|
|||
n.Unlink()
|
||||
}
|
||||
util.PushEndlessProgress(fmt.Sprintf(Conf.Language(111), util.EscapeHTML(tree.Root.IALAttr("title"))))
|
||||
if err = writeTreeUpsertQueue(tree); nil != err {
|
||||
if err = writeTreeUpsertQueue(tree); err != nil {
|
||||
util.ClearPushProgress(100)
|
||||
return
|
||||
}
|
||||
|
|
@ -176,7 +176,7 @@ func RenameTag(oldLabel, newLabel string) (err error) {
|
|||
}
|
||||
}
|
||||
util.PushEndlessProgress(fmt.Sprintf(Conf.Language(111), util.EscapeHTML(tree.Root.IALAttr("title"))))
|
||||
if err = writeTreeUpsertQueue(tree); nil != err {
|
||||
if err = writeTreeUpsertQueue(tree); err != nil {
|
||||
util.ClearPushProgress(100)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,14 +46,14 @@ func RenderGoTemplate(templateContent string) (ret string, err error) {
|
|||
sql.SQLTemplateFuncs(&tplFuncMap)
|
||||
tmpl = tmpl.Funcs(tplFuncMap)
|
||||
tpl, err := tmpl.Parse(templateContent)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return "", errors.New(fmt.Sprintf(Conf.Language(44), err.Error()))
|
||||
}
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
buf.Grow(4096)
|
||||
err = tpl.Execute(buf, nil)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return "", errors.New(fmt.Sprintf(Conf.Language(44), err.Error()))
|
||||
}
|
||||
ret = buf.String()
|
||||
|
|
@ -62,7 +62,7 @@ func RenderGoTemplate(templateContent string) (ret string, err error) {
|
|||
|
||||
func RemoveTemplate(p string) (err error) {
|
||||
err = filelock.Remove(p)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("remove template failed: %s", err)
|
||||
}
|
||||
return
|
||||
|
|
@ -77,7 +77,7 @@ func SearchTemplate(keyword string) (ret []*Block) {
|
|||
}
|
||||
|
||||
groups, err := os.ReadDir(templates)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read templates failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -195,7 +195,7 @@ func DocSaveAsTemplate(id, name string, overwrite bool) (code int, err error) {
|
|||
|
||||
func RenderTemplate(p, id string, preview bool) (tree *parse.Tree, dom string, err error) {
|
||||
tree, err = LoadTreeByBlockID(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -206,7 +206,7 @@ func RenderTemplate(p, id string, preview bool) (tree *parse.Tree, dom string, e
|
|||
}
|
||||
block := sql.BuildBlockFromNode(node, tree)
|
||||
md, err := os.ReadFile(p)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -228,14 +228,14 @@ func RenderTemplate(p, id string, preview bool) (tree *parse.Tree, dom string, e
|
|||
sql.SQLTemplateFuncs(&tplFuncMap)
|
||||
goTpl = goTpl.Funcs(tplFuncMap)
|
||||
tpl, err := goTpl.Funcs(tplFuncMap).Parse(gulu.Str.FromBytes(md))
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
err = errors.New(fmt.Sprintf(Conf.Language(44), err.Error()))
|
||||
return
|
||||
}
|
||||
|
||||
buf := &bytes.Buffer{}
|
||||
buf.Grow(4096)
|
||||
if err = tpl.Execute(buf, dataModel); nil != err {
|
||||
if err = tpl.Execute(buf, dataModel); err != nil {
|
||||
err = errors.New(fmt.Sprintf(Conf.Language(44), err.Error()))
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -109,7 +109,7 @@ func getThemeStyleVar(theme string) (ret map[string]string) {
|
|||
ret = map[string]string{}
|
||||
|
||||
data, err := os.ReadFile(filepath.Join(util.ThemesPath, theme, "theme.css"))
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read theme [%s] css file failed: %s", theme, err)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -155,7 +155,7 @@ func performTx(tx *Transaction) (ret *TxErr) {
|
|||
//defer pprof.StopCPUProfile()
|
||||
|
||||
var err error
|
||||
if err = tx.begin(); nil != err {
|
||||
if err = tx.begin(); err != nil {
|
||||
if strings.Contains(err.Error(), "database is closed") {
|
||||
return
|
||||
}
|
||||
|
|
@ -302,7 +302,7 @@ func (tx *Transaction) doMove(operation *Operation) (ret *TxErr) {
|
|||
var err error
|
||||
id := operation.ID
|
||||
srcTree, err := tx.loadTree(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("load tree [%s] failed: %s", id, err)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: id}
|
||||
}
|
||||
|
|
@ -335,7 +335,7 @@ func (tx *Transaction) doMove(operation *Operation) (ret *TxErr) {
|
|||
|
||||
var targetTree *parse.Tree
|
||||
targetTree, err = tx.loadTree(targetPreviousID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("load tree [%s] failed: %s", targetPreviousID, err)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: targetPreviousID}
|
||||
}
|
||||
|
|
@ -374,11 +374,11 @@ func (tx *Transaction) doMove(operation *Operation) (ret *TxErr) {
|
|||
|
||||
refreshUpdated(srcNode)
|
||||
refreshUpdated(srcTree.Root)
|
||||
if err = tx.writeTree(srcTree); nil != err {
|
||||
if err = tx.writeTree(srcTree); err != nil {
|
||||
return
|
||||
}
|
||||
if !isSameTree {
|
||||
if err = tx.writeTree(targetTree); nil != err {
|
||||
if err = tx.writeTree(targetTree); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -390,7 +390,7 @@ func (tx *Transaction) doMove(operation *Operation) (ret *TxErr) {
|
|||
}
|
||||
|
||||
targetTree, err := tx.loadTree(targetParentID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("load tree [%s] failed: %s", targetParentID, err)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: targetParentID}
|
||||
}
|
||||
|
|
@ -452,11 +452,11 @@ func (tx *Transaction) doMove(operation *Operation) (ret *TxErr) {
|
|||
|
||||
refreshUpdated(srcNode)
|
||||
refreshUpdated(srcTree.Root)
|
||||
if err = tx.writeTree(srcTree); nil != err {
|
||||
if err = tx.writeTree(srcTree); err != nil {
|
||||
return &TxErr{code: TxErrCodeWriteTree, msg: err.Error(), id: id}
|
||||
}
|
||||
if !isSameTree {
|
||||
if err = tx.writeTree(targetTree); nil != err {
|
||||
if err = tx.writeTree(targetTree); err != nil {
|
||||
return &TxErr{code: TxErrCodeWriteTree, msg: err.Error(), id: id}
|
||||
}
|
||||
}
|
||||
|
|
@ -482,7 +482,7 @@ func (tx *Transaction) doPrependInsert(operation *Operation) (ret *TxErr) {
|
|||
return
|
||||
}
|
||||
tree, err := tx.loadTree(block.ID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("load tree [%s] failed: %s", block.ID, err)
|
||||
logging.LogErrorf(msg)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: block.ID}
|
||||
|
|
@ -542,7 +542,7 @@ func (tx *Transaction) doPrependInsert(operation *Operation) (ret *TxErr) {
|
|||
}
|
||||
createdUpdated(insertedNode)
|
||||
tx.nodes[insertedNode.ID] = insertedNode
|
||||
if err = tx.writeTree(tree); nil != err {
|
||||
if err = tx.writeTree(tree); err != nil {
|
||||
return &TxErr{code: TxErrCodeWriteTree, msg: err.Error(), id: block.ID}
|
||||
}
|
||||
|
||||
|
|
@ -566,7 +566,7 @@ func (tx *Transaction) doAppendInsert(operation *Operation) (ret *TxErr) {
|
|||
return
|
||||
}
|
||||
tree, err := tx.loadTree(block.ID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("load tree [%s] failed: %s", block.ID, err)
|
||||
logging.LogErrorf(msg)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: block.ID}
|
||||
|
|
@ -631,7 +631,7 @@ func (tx *Transaction) doAppendInsert(operation *Operation) (ret *TxErr) {
|
|||
|
||||
createdUpdated(insertedNode)
|
||||
tx.nodes[insertedNode.ID] = insertedNode
|
||||
if err = tx.writeTree(tree); nil != err {
|
||||
if err = tx.writeTree(tree); err != nil {
|
||||
return &TxErr{code: TxErrCodeWriteTree, msg: err.Error(), id: block.ID}
|
||||
}
|
||||
|
||||
|
|
@ -650,7 +650,7 @@ func (tx *Transaction) doAppend(operation *Operation) (ret *TxErr) {
|
|||
var err error
|
||||
id := operation.ID
|
||||
srcTree, err := tx.loadTree(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("load tree [%s] failed: %s", id, err)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: id}
|
||||
}
|
||||
|
|
@ -688,7 +688,7 @@ func (tx *Transaction) doAppend(operation *Operation) (ret *TxErr) {
|
|||
}
|
||||
|
||||
targetTree, err := tx.loadTree(targetRootID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("load tree [%s] failed: %s", targetRootID, err)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: targetRootID}
|
||||
}
|
||||
|
|
@ -719,12 +719,12 @@ func (tx *Transaction) doAppend(operation *Operation) (ret *TxErr) {
|
|||
srcEmptyList.Unlink()
|
||||
}
|
||||
|
||||
if err = tx.writeTree(srcTree); nil != err {
|
||||
if err = tx.writeTree(srcTree); err != nil {
|
||||
return &TxErr{code: TxErrCodeWriteTree, msg: err.Error(), id: id}
|
||||
}
|
||||
|
||||
if !isSameTree {
|
||||
if err = tx.writeTree(targetTree); nil != err {
|
||||
if err = tx.writeTree(targetTree); err != nil {
|
||||
return &TxErr{code: TxErrCodeWriteTree, msg: err.Error(), id: id}
|
||||
}
|
||||
}
|
||||
|
|
@ -737,7 +737,7 @@ func (tx *Transaction) doDelete(operation *Operation) (ret *TxErr) {
|
|||
var err error
|
||||
id := operation.ID
|
||||
tree, err := tx.loadTree(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
if errors.Is(err, ErrBlockNotFound) {
|
||||
// move 以后这里会空,算作正常情况
|
||||
return
|
||||
|
|
@ -768,7 +768,7 @@ func (tx *Transaction) doDelete(operation *Operation) (ret *TxErr) {
|
|||
treenode.RemoveBlockTree(node.ID)
|
||||
|
||||
delete(tx.nodes, node.ID)
|
||||
if err = tx.writeTree(tree); nil != err {
|
||||
if err = tx.writeTree(tree); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -824,7 +824,7 @@ func syncDelete2Block(node *ast.Node) {
|
|||
}
|
||||
|
||||
attrView, err := av.ParseAttributeView(avID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
||||
|
|
@ -919,7 +919,7 @@ func (tx *Transaction) doInsert(operation *Operation) (ret *TxErr) {
|
|||
}
|
||||
|
||||
tree, err := tx.loadTree(block.ID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
msg := fmt.Sprintf("load tree [%s] failed: %s", block.ID, err)
|
||||
logging.LogErrorf(msg)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: block.ID}
|
||||
|
|
@ -953,7 +953,7 @@ func (tx *Transaction) doInsert(operation *Operation) (ret *TxErr) {
|
|||
|
||||
// 只有全局 assets 才移动到相对 assets
|
||||
targetP := filepath.Join(assets, filepath.Base(assetPath))
|
||||
if e = filelock.Rename(assetPath, targetP); nil != err {
|
||||
if e = filelock.Rename(assetPath, targetP); err != nil {
|
||||
logging.LogErrorf("copy path of asset from [%s] to [%s] failed: %s", assetPath, targetP, err)
|
||||
return ast.WalkContinue
|
||||
}
|
||||
|
|
@ -1048,7 +1048,7 @@ func (tx *Transaction) doInsert(operation *Operation) (ret *TxErr) {
|
|||
|
||||
createdUpdated(insertedNode)
|
||||
tx.nodes[insertedNode.ID] = insertedNode
|
||||
if err = tx.writeTree(tree); nil != err {
|
||||
if err = tx.writeTree(tree); err != nil {
|
||||
return &TxErr{code: TxErrCodeWriteTree, msg: err.Error(), id: block.ID}
|
||||
}
|
||||
|
||||
|
|
@ -1078,7 +1078,7 @@ func (tx *Transaction) doInsert(operation *Operation) (ret *TxErr) {
|
|||
func (tx *Transaction) doUpdate(operation *Operation) (ret *TxErr) {
|
||||
id := operation.ID
|
||||
tree, err := tx.loadTree(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("load tree [%s] failed: %s", id, err)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: id}
|
||||
}
|
||||
|
|
@ -1151,7 +1151,7 @@ func (tx *Transaction) doUpdate(operation *Operation) (ret *TxErr) {
|
|||
createdUpdated(updatedNode)
|
||||
|
||||
tx.nodes[updatedNode.ID] = updatedNode
|
||||
if err = tx.writeTree(tree); nil != err {
|
||||
if err = tx.writeTree(tree); err != nil {
|
||||
return &TxErr{code: TxErrCodeWriteTree, msg: err.Error(), id: id}
|
||||
}
|
||||
|
||||
|
|
@ -1185,7 +1185,7 @@ func upsertAvBlockRel(node *ast.Node) {
|
|||
func (tx *Transaction) doUpdateUpdated(operation *Operation) (ret *TxErr) {
|
||||
id := operation.ID
|
||||
tree, err := tx.loadTree(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
if errors.Is(err, ErrBlockNotFound) {
|
||||
logging.LogWarnf("not found block [%s]", id)
|
||||
return
|
||||
|
|
@ -1204,7 +1204,7 @@ func (tx *Transaction) doUpdateUpdated(operation *Operation) (ret *TxErr) {
|
|||
node.SetIALAttr("updated", operation.Data.(string))
|
||||
createdUpdated(node)
|
||||
tx.nodes[node.ID] = node
|
||||
if err = tx.writeTree(tree); nil != err {
|
||||
if err = tx.writeTree(tree); err != nil {
|
||||
return &TxErr{code: TxErrCodeWriteTree, msg: err.Error(), id: id}
|
||||
}
|
||||
return
|
||||
|
|
@ -1221,7 +1221,7 @@ func (tx *Transaction) doCreate(operation *Operation) (ret *TxErr) {
|
|||
func (tx *Transaction) doSetAttrs(operation *Operation) (ret *TxErr) {
|
||||
id := operation.ID
|
||||
tree, err := tx.loadTree(id)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("load tree [%s] failed: %s", id, err)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: id}
|
||||
}
|
||||
|
|
@ -1233,7 +1233,7 @@ func (tx *Transaction) doSetAttrs(operation *Operation) (ret *TxErr) {
|
|||
}
|
||||
|
||||
attrs := map[string]string{}
|
||||
if err = gulu.JSON.UnmarshalJSON([]byte(operation.Data.(string)), &attrs); nil != err {
|
||||
if err = gulu.JSON.UnmarshalJSON([]byte(operation.Data.(string)), &attrs); err != nil {
|
||||
logging.LogErrorf("unmarshal attrs failed: %s", err)
|
||||
return &TxErr{code: TxErrCodeBlockNotFound, id: id}
|
||||
}
|
||||
|
|
@ -1259,7 +1259,7 @@ func (tx *Transaction) doSetAttrs(operation *Operation) (ret *TxErr) {
|
|||
}
|
||||
}
|
||||
|
||||
if err = tx.writeTree(tree); nil != err {
|
||||
if err = tx.writeTree(tree); err != nil {
|
||||
return
|
||||
}
|
||||
cache.PutBlockIAL(id, parse.IAL2Map(node.KramdownIAL))
|
||||
|
|
@ -1366,7 +1366,7 @@ func (tx *Transaction) begin() (err error) {
|
|||
|
||||
func (tx *Transaction) commit() (err error) {
|
||||
for _, tree := range tx.trees {
|
||||
if err = writeTreeUpsertQueue(tree); nil != err {
|
||||
if err = writeTreeUpsertQueue(tree); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -1404,7 +1404,7 @@ func (tx *Transaction) loadTree(id string) (ret *parse.Tree, err error) {
|
|||
}
|
||||
|
||||
ret, err = filesys.LoadTree(box, p, tx.luteEngine)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
tx.trees[rootID] = ret
|
||||
|
|
@ -1466,7 +1466,7 @@ func refreshDynamicRefTexts(updatedDefNodes map[string]*ast.Node, updatedTrees m
|
|||
if !ok {
|
||||
var err error
|
||||
refTree, err = LoadTreeByBlockID(refTreeID)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -153,13 +153,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.ReadFile(localPath)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("get data [path=%s] failed: %s", localPath, err)
|
||||
return
|
||||
}
|
||||
|
||||
ret, err = filesys.ParseJSONWithoutFix(data, luteEngine.ParseOptions)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("parse json to tree [%s] failed: %s", localPath, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -284,7 +284,7 @@ func searchTreeInFilesystem(rootID string) {
|
|||
}
|
||||
|
||||
tree, err := filesys.LoadTree(boxID, treePath, util.NewLute())
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("load tree [%s] failed: %s", treePath, err)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
|
|
@ -60,7 +60,7 @@ func getNewVerInstallPkgPath() string {
|
|||
}
|
||||
|
||||
downloadPkgURLs, checksum, err := getUpdatePkg()
|
||||
if nil != err || 1 > len(downloadPkgURLs) || "" == checksum {
|
||||
if err != nil || 1 > len(downloadPkgURLs) || "" == checksum {
|
||||
return ""
|
||||
}
|
||||
|
||||
|
|
@ -88,7 +88,7 @@ func checkDownloadInstallPkg() {
|
|||
defer checkDownloadInstallPkgLock.Unlock()
|
||||
|
||||
downloadPkgURLs, checksum, err := getUpdatePkg()
|
||||
if nil != err || 1 > len(downloadPkgURLs) || "" == checksum {
|
||||
if err != nil || 1 > len(downloadPkgURLs) || "" == checksum {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -96,7 +96,7 @@ func checkDownloadInstallPkg() {
|
|||
succ := false
|
||||
for _, downloadPkgURL := range downloadPkgURLs {
|
||||
err = downloadInstallPkg(downloadPkgURL, checksum)
|
||||
if nil == err {
|
||||
if err == nil {
|
||||
succ = true
|
||||
break
|
||||
|
||||
|
|
@ -110,7 +110,7 @@ func checkDownloadInstallPkg() {
|
|||
func getUpdatePkg() (downloadPkgURLs []string, checksum string, err error) {
|
||||
defer logging.Recover()
|
||||
result, err := util.GetRhyResult(false)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -170,7 +170,7 @@ func downloadInstallPkg(pkgURL, checksum string) (err error) {
|
|||
}
|
||||
|
||||
err = os.MkdirAll(filepath.Join(util.TempDir, "install"), 0755)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("create temp install dir failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -183,7 +183,7 @@ func downloadInstallPkg(pkgURL, checksum string) (err error) {
|
|||
util.PushStatusBar(fmt.Sprintf(Conf.Language(133), progress))
|
||||
}
|
||||
_, err = client.R().SetOutputFile(savePath).SetDownloadCallbackWithInterval(callback, 1*time.Second).Get(pkgURL)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("download install package [%s] failed: %s", pkgURL, err)
|
||||
return
|
||||
}
|
||||
|
|
@ -200,7 +200,7 @@ func downloadInstallPkg(pkgURL, checksum string) (err error) {
|
|||
|
||||
func sha256Hash(filename string) (ret string, err error) {
|
||||
file, err := os.Open(filename)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
|
|
@ -229,7 +229,7 @@ type Announcement struct {
|
|||
|
||||
func GetAnnouncements() (ret []*Announcement) {
|
||||
result, err := util.GetRhyResult(false)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("get announcement failed: %s", err)
|
||||
return
|
||||
}
|
||||
|
|
@ -261,7 +261,7 @@ func CheckUpdate(showMsg bool) {
|
|||
}
|
||||
|
||||
result, err := util.GetRhyResult(showMsg)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ func InsertLocalAssets(id string, assetPaths []string, isUpload bool) (succMap m
|
|||
docDirLocalPath := filepath.Join(util.DataDir, bt.BoxID, path.Dir(bt.Path))
|
||||
assetsDirPath := getAssetsDir(filepath.Join(util.DataDir, bt.BoxID), docDirLocalPath)
|
||||
if !gulu.File.IsExist(assetsDirPath) {
|
||||
if err = os.MkdirAll(assetsDirPath, 0755); nil != err {
|
||||
if err = os.MkdirAll(assetsDirPath, 0755); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
|
@ -91,11 +91,11 @@ func InsertLocalAssets(id string, assetPaths []string, isUpload bool) (succMap m
|
|||
fName = fName[0 : len(fName)-len(ext)]
|
||||
fName = fName + "-" + ast.NewNodeID() + ext
|
||||
writePath := filepath.Join(assetsDirPath, fName)
|
||||
if _, err = f.Seek(0, io.SeekStart); nil != err {
|
||||
if _, err = f.Seek(0, io.SeekStart); err != nil {
|
||||
f.Close()
|
||||
return
|
||||
}
|
||||
if err = filelock.WriteFileByReader(writePath, f); nil != err {
|
||||
if err = filelock.WriteFileByReader(writePath, f); err != nil {
|
||||
f.Close()
|
||||
return
|
||||
}
|
||||
|
|
@ -112,7 +112,7 @@ func Upload(c *gin.Context) {
|
|||
defer c.JSON(200, ret)
|
||||
|
||||
form, err := c.MultipartForm()
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("insert asset failed: %s", err)
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
|
|
@ -137,7 +137,7 @@ func Upload(c *gin.Context) {
|
|||
assetsDirPath = filepath.Join(util.DataDir, relAssetsDirPath)
|
||||
}
|
||||
if !gulu.File.IsExist(assetsDirPath) {
|
||||
if err = os.MkdirAll(assetsDirPath, 0755); nil != err {
|
||||
if err = os.MkdirAll(assetsDirPath, 0755); err != nil {
|
||||
ret.Code = -1
|
||||
ret.Msg = err.Error()
|
||||
return
|
||||
|
|
@ -206,7 +206,7 @@ func Upload(c *gin.Context) {
|
|||
writePath := filepath.Join(assetsDirPath, fName)
|
||||
tmpDir := filepath.Join(util.TempDir, "convert", "zip", gulu.Rand.String(7))
|
||||
if needUnzip2Dir {
|
||||
if err = os.MkdirAll(tmpDir, 0755); nil != err {
|
||||
if err = os.MkdirAll(tmpDir, 0755); err != nil {
|
||||
errFiles = append(errFiles, fName)
|
||||
ret.Msg = err.Error()
|
||||
f.Close()
|
||||
|
|
@ -215,14 +215,14 @@ func Upload(c *gin.Context) {
|
|||
writePath = filepath.Join(tmpDir, fName)
|
||||
}
|
||||
|
||||
if _, err = f.Seek(0, io.SeekStart); nil != err {
|
||||
if _, err = f.Seek(0, io.SeekStart); err != nil {
|
||||
logging.LogErrorf("seek failed: %s", err)
|
||||
errFiles = append(errFiles, fName)
|
||||
ret.Msg = err.Error()
|
||||
f.Close()
|
||||
break
|
||||
}
|
||||
if err = filelock.WriteFileByReader(writePath, f); nil != err {
|
||||
if err = filelock.WriteFileByReader(writePath, f); err != nil {
|
||||
logging.LogErrorf("write file failed: %s", err)
|
||||
errFiles = append(errFiles, fName)
|
||||
ret.Msg = err.Error()
|
||||
|
|
@ -241,7 +241,7 @@ func Upload(c *gin.Context) {
|
|||
fName += ext
|
||||
fName = util.AssetName(fName)
|
||||
tmpDir2 := filepath.Join(util.TempDir, "convert", "zip", gulu.Rand.String(7))
|
||||
if err = gulu.Zip.Unzip(writePath, tmpDir2); nil != err {
|
||||
if err = gulu.Zip.Unzip(writePath, tmpDir2); err != nil {
|
||||
errFiles = append(errFiles, fName)
|
||||
ret.Msg = err.Error()
|
||||
break
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ func SearchWidget(keyword string) (ret []*Block) {
|
|||
ret = []*Block{}
|
||||
widgetsDir := filepath.Join(util.DataDir, "widgets")
|
||||
entries, err := os.ReadDir(widgetsDir)
|
||||
if nil != err {
|
||||
if err != nil {
|
||||
logging.LogErrorf("read dir [%s] failed: %s", widgetsDir, err)
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue