Try to fix concurrent modification error

This commit is contained in:
Vishesh Handa
2021-08-17 14:08:32 +02:00
parent ddf3ef021a
commit 2863a26543

View File

@ -63,17 +63,21 @@ class NotesFolderFS with NotesFolderNotifier implements NotesFolder {
} }
void _noteRenamed(Note note, String oldPath) { void _noteRenamed(Note note, String oldPath) {
_lock.synchronized(() {
assert(_entityMap.containsKey(oldPath)); assert(_entityMap.containsKey(oldPath));
_entityMap.remove(oldPath); _entityMap.remove(oldPath);
_entityMap[note.filePath] = note; _entityMap[note.filePath] = note;
notifyNoteRenamed(-1, note, oldPath); notifyNoteRenamed(-1, note, oldPath);
});
} }
void _subFolderRenamed(NotesFolderFS folder, String oldPath) { void _subFolderRenamed(NotesFolderFS folder, String oldPath) {
_lock.synchronized(() {
assert(_entityMap.containsKey(oldPath)); assert(_entityMap.containsKey(oldPath));
_entityMap.remove(oldPath); _entityMap.remove(oldPath);
_entityMap[folder.folderPath] = folder; _entityMap[folder.folderPath] = folder;
});
} }
void reset(String folderPath) { void reset(String folderPath) {
@ -168,6 +172,7 @@ class NotesFolderFS with NotesFolderNotifier implements NotesFolder {
futures = <Future>[]; futures = <Future>[];
// Remove notes which have errors // Remove notes which have errors
await _lock.synchronized(() {
var errFunc = (Note n) => n.loadState == NoteLoadState.Error; var errFunc = (Note n) => n.loadState == NoteLoadState.Error;
var hasBadNotes = _notes.any(errFunc); var hasBadNotes = _notes.any(errFunc);
if (hasBadNotes) { if (hasBadNotes) {
@ -180,6 +185,7 @@ class NotesFolderFS with NotesFolderNotifier implements NotesFolder {
notifyNoteRemoved(i, note); notifyNoteRemoved(i, note);
} }
} }
});
for (var folder in _folders) { for (var folder in _folders) {
var f = folder.loadRecursively(); var f = folder.loadRecursively();