🎨 Flashcards are not allowed to be modified during data sync to avoid data overwriting https://github.com/siyuan-note/siyuan/issues/10167

This commit is contained in:
Daniel 2024-01-13 22:30:57 +08:00
parent c3b4aa971d
commit 651f245662
No known key found for this signature in database
GPG key ID: 86211BA83DF03017
2 changed files with 16 additions and 3 deletions

View file

@ -641,7 +641,7 @@ func (tx *Transaction) doRemoveFlashcards(operation *Operation) (ret *TxErr) {
deckLock.Lock()
defer deckLock.Unlock()
if isSyncing.Load() {
if isSyncingStorages() {
ret = &TxErr{code: TxErrCodeDataIsSyncing}
return
}
@ -753,7 +753,7 @@ func (tx *Transaction) doAddFlashcards(operation *Operation) (ret *TxErr) {
deckLock.Lock()
defer deckLock.Unlock()
if isSyncing.Load() {
if isSyncingStorages() {
ret = &TxErr{code: TxErrCodeDataIsSyncing}
return
}

View file

@ -955,11 +955,15 @@ var syncingFiles = sync.Map{}
var syncingStorages = atomic.Bool{}
func waitForSyncingStorages() {
for syncingStorages.Load() {
for isSyncingStorages() {
time.Sleep(time.Second)
}
}
func isSyncingStorages() bool {
return syncingStorages.Load() || isBootSyncing.Load()
}
func IsSyncingFile(rootID string) (ret bool) {
_, ret = syncingFiles.Load(rootID)
return
@ -1105,6 +1109,8 @@ func syncRepoUpload() (err error) {
return
}
var isBootSyncing = atomic.Bool{}
func bootSyncRepo() (err error) {
if 1 > len(Conf.Repo.Key) {
autoSyncErrCount++
@ -1129,11 +1135,14 @@ func bootSyncRepo() (err error) {
return
}
isBootSyncing.Store(true)
start := time.Now()
_, _, err = indexRepoBeforeCloudSync(repo)
if nil != err {
autoSyncErrCount++
planSyncAfter(fixSyncInterval)
isBootSyncing.Store(false)
return
}
@ -1180,17 +1189,21 @@ func bootSyncRepo() (err error) {
util.PushStatusBar(msg)
util.PushErrMsg(msg, 0)
BootSyncSucc = 1
isBootSyncing.Store(false)
return
}
if 0 < len(fetchedFiles) {
go func() {
_, syncErr := syncRepo(false, false)
isBootSyncing.Store(false)
if nil != err {
logging.LogErrorf("boot background sync repo failed: %s", syncErr)
return
}
}()
} else {
isBootSyncing.Store(false)
}
return
}