An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: 同步时如果发现数据仓库损坏则自动重建仓库 Fix https://github.com/siyuan-note/siyuan/issues/6144
Liang Ding04a46b0c1a1d
diff --git a/kernel/go.mod b/kernel/go.modindex 74338c4eb4..9475533b3f 100644--- a/kernel/go.mod+++ b/kernel/go.mod@@ -37,7 +37,7 @@ require (github.com/patrickmn/go-cache v2.1.0+incompatiblegithub.com/qiniu/go-sdk/v7 v7.13.0github.com/radovskyb/watcher v1.0.7- github.com/siyuan-note/dejavu v0.0.0-20221009014342-57351eb27c75+ github.com/siyuan-note/dejavu v0.0.0-20221010122243-4f76b4f0ae5egithub.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75github.com/siyuan-note/eventbus v0.0.0-20220916025349-3ac6e75522dagithub.com/siyuan-note/filelock v0.0.0-20221007163134-7e64809023ef@@ -91,8 +91,8 @@ require (github.com/marten-seemann/qpack v0.2.1 // indirectgithub.com/marten-seemann/qtls-go1-16 v0.1.5 // indirectgithub.com/marten-seemann/qtls-go1-17 v0.1.2 // indirect- github.com/marten-seemann/qtls-go1-18 v0.1.2 // indirect- github.com/marten-seemann/qtls-go1-19 v0.1.0 // indirect+ github.com/marten-seemann/qtls-go1-18 v0.1.3 // indirect+ github.com/marten-seemann/qtls-go1-19 v0.1.1 // indirectgithub.com/mattn/go-isatty v0.0.16 // indirectgithub.com/mitchellh/copystructure v1.2.0 // indirectgithub.com/mitchellh/reflectwalk v1.0.2 // indirectdiff --git a/kernel/go.sum b/kernel/go.sumindex 9e86394e49..5ebaef98f4 100644--- a/kernel/go.sum+++ b/kernel/go.sum@@ -239,9 +239,13 @@ github.com/marten-seemann/qtls-go1-17 v0.1.2 h1:JADBlm0LYiVbuSySCHeY863dNkcpMmDRgithub.com/marten-seemann/qtls-go1-17 v0.1.2/go.mod h1:C2ekUKcDdz9SDWxec1N/MvcXBpaX9l3Nx67XaR84L5s=github.com/marten-seemann/qtls-go1-18 v0.1.2 h1:JH6jmzbduz0ITVQ7ShevK10Av5+jBEKAHMntXmIV7kM=github.com/marten-seemann/qtls-go1-18 v0.1.2/go.mod h1:mJttiymBAByA49mhlNZZGrH5u1uXYZJ+RW28Py7f4m4=+github.com/marten-seemann/qtls-go1-18 v0.1.3 h1:R4H2Ks8P6pAtUagjFty2p7BVHn3XiwDAl7TTQf5h7TI=+github.com/marten-seemann/qtls-go1-18 v0.1.3/go.mod h1:mJttiymBAByA49mhlNZZGrH5u1uXYZJ+RW28Py7f4m4=github.com/marten-seemann/qtls-go1-19 v0.1.0-beta.1/go.mod h1:5HTDWtVudo/WFsHKRNuOhWlbdjrfs5JHrYb0wIJqGpI=github.com/marten-seemann/qtls-go1-19 v0.1.0 h1:rLFKD/9mp/uq1SYGYuVZhm83wkmU95pK5df3GufyYYU=github.com/marten-seemann/qtls-go1-19 v0.1.0/go.mod h1:5HTDWtVudo/WFsHKRNuOhWlbdjrfs5JHrYb0wIJqGpI=+github.com/marten-seemann/qtls-go1-19 v0.1.1 h1:mnbxeq3oEyQxQXwI4ReCgW9DPoPR94sNlqWoDZnjRIE=+github.com/marten-seemann/qtls-go1-19 v0.1.1/go.mod h1:5HTDWtVudo/WFsHKRNuOhWlbdjrfs5JHrYb0wIJqGpI=github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=github.com/mattn/go-isatty v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=@@ -347,6 +351,8 @@ github.com/shurcooL/users v0.0.0-20180125191416-49c67e49c537/go.mod h1:QJTqeLYEDgithub.com/shurcooL/webdavfs v0.0.0-20170829043945-18c3829fa133/go.mod h1:hKmq5kWdCj2z2KEozexVbfEZIWiTjhE0+UjmZgPqehw=github.com/siyuan-note/dejavu v0.0.0-20221009014342-57351eb27c75 h1:4aExF0IlFsBj+54knKzWfr+9FVui4lzua/fwXqjKmjQ=github.com/siyuan-note/dejavu v0.0.0-20221009014342-57351eb27c75/go.mod h1:Y+bg0j0Z7C66oJWPPYMs+wZuFeiTRWhh2aLkqctJFKk=+github.com/siyuan-note/dejavu v0.0.0-20221010122243-4f76b4f0ae5e h1:l3NnxHDj+A+zd0I2diqa2a8tSpTt5qzDqYj+PfzpOoE=+github.com/siyuan-note/dejavu v0.0.0-20221010122243-4f76b4f0ae5e/go.mod h1:Y+bg0j0Z7C66oJWPPYMs+wZuFeiTRWhh2aLkqctJFKk=github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75 h1:Bi7/7f29LW+Fm0cHc0J1NO1cZqyJwljSWVmfOqVZgaE=github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75/go.mod h1:H8fyqqAbp9XreANjeSbc72zEdFfKTXYN34tc1TjZwtw=github.com/siyuan-note/eventbus v0.0.0-20220916025349-3ac6e75522da h1:/jNhl7LC+9BhkWvNxuJDdsNfA/2wvfuj9mqWx4CbV90=diff --git a/kernel/model/repository.go b/kernel/model/repository.goindex 21eeae7e24..0a5a55f5bd 100644--- a/kernel/model/repository.go+++ b/kernel/model/repository.go@@ -507,6 +507,12 @@ func syncRepo(boot, exit, byHand bool) (err error) {syncContext := map[string]interface{}{eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBar}_, mergeResult, trafficStat, err := repo.Sync(cloudInfo, syncContext)+ if errors.Is(err, dejavu.ErrRepoFatalErr) {+ // 重置仓库并再次尝试同步+ if _, resetErr := resetRepository(repo); nil == resetErr {+ _, mergeResult, trafficStat, err = repo.Sync(cloudInfo, syncContext)+ }+ }elapsed := time.Since(start)if nil != err {syncDownloadErrCount++@@ -682,21 +688,11 @@ func indexRepoBeforeCloudSync(repo *dejavu.Repo) (err error) {eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBar,})if errors.Is(err, dejavu.ErrNotFoundObject) {- logging.LogWarnf("data repo is corrupted, try to reset it")- resetErr := os.RemoveAll(filepath.Join(repo.Path))+ var resetErr error+ index, resetErr = resetRepository(repo)if nil != resetErr {- logging.LogErrorf("remove data repo failed: %s", resetErr)return}- index, err = repo.Index("[Sync] Cloud sync", map[string]interface{}{- eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBar,- })- logging.LogWarnf("data repo has been reset")-- go func() {- time.Sleep(5 * time.Second)- util.PushMsg(Conf.Language(105), 5000)- }()}if nil != err {@@ -727,6 +723,25 @@ func indexRepoBeforeCloudSync(repo *dejavu.Repo) (err error) {return}+func resetRepository(repo *dejavu.Repo) (index *entity.Index, err error) {+ logging.LogWarnf("data repo is corrupted, try to reset it")+ err = os.RemoveAll(filepath.Join(repo.Path))+ if nil != err {+ logging.LogErrorf("remove data repo failed: %s", err)+ return+ }+ index, err = repo.Index("[Sync] Cloud sync", map[string]interface{}{+ eventbus.CtxPushMsg: eventbus.CtxPushMsgToStatusBar,+ })+ logging.LogWarnf("data repo has been reset")++ go func() {+ time.Sleep(5 * time.Second)+ util.PushMsg(Conf.Language(105), 5000)+ }()+ return+}+func newRepository() (ret *dejavu.Repo, err error) {ignoreLines := getIgnoreLines()ignoreLines = append(ignoreLines, "/.siyuan/conf.json") // 忽略旧版同步配置