mirror of
https://github.com/siyuan-note/siyuan.git
synced 2025-12-17 15:10:12 +01:00
🎨 同步时如果发现数据仓库损坏则自动重建仓库 Fix https://github.com/siyuan-note/siyuan/issues/6144
This commit is contained in:
parent
c1ec8035b2
commit
04a46b0c1a
3 changed files with 36 additions and 15 deletions
|
|
@ -37,7 +37,7 @@ require (
|
|||
github.com/patrickmn/go-cache v2.1.0+incompatible
|
||||
github.com/qiniu/go-sdk/v7 v7.13.0
|
||||
github.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-4f76b4f0ae5e
|
||||
github.com/siyuan-note/encryption v0.0.0-20220713091850-5ecd92177b75
|
||||
github.com/siyuan-note/eventbus v0.0.0-20220916025349-3ac6e75522da
|
||||
github.com/siyuan-note/filelock v0.0.0-20221007163134-7e64809023ef
|
||||
|
|
@ -91,8 +91,8 @@ require (
|
|||
github.com/marten-seemann/qpack v0.2.1 // indirect
|
||||
github.com/marten-seemann/qtls-go1-16 v0.1.5 // indirect
|
||||
github.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 // indirect
|
||||
github.com/mattn/go-isatty v0.0.16 // indirect
|
||||
github.com/mitchellh/copystructure v1.2.0 // indirect
|
||||
github.com/mitchellh/reflectwalk v1.0.2 // indirect
|
||||
|
|
|
|||
|
|
@ -239,9 +239,13 @@ github.com/marten-seemann/qtls-go1-17 v0.1.2 h1:JADBlm0LYiVbuSySCHeY863dNkcpMmDR
|
|||
github.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:QJTqeLYED
|
|||
github.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=
|
||||
|
|
|
|||
|
|
@ -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") // 忽略旧版同步配置
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue