Skip to content

Commit 29d17f3

Browse files
committed
fix: Multiple small hardenings
Signed-off-by: Marcel Klehr <[email protected]>
1 parent 9b01100 commit 29d17f3

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

src/lib/Account.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ export default class Account {
286286
direction = ItemLocation.SERVER
287287
break
288288
default:
289-
if (!cacheTree.children.length) {
289+
if (!cacheTree.children?.length) {
290290
Logger.log('Using "merge default" strategy (no cache available)')
291291
strategyClass = MergeSyncProcess
292292
} else {
@@ -308,15 +308,16 @@ export default class Account {
308308
if (direction) {
309309
this.syncProcess.setDirection(direction)
310310
}
311-
await this.syncProcess.sync()
312311
} else {
313-
// if there is a pending continuation, we resume it
314-
312+
// if there is a pending continuation, we resume it (see construction above)
315313
Logger.log('Found existing persisted pending continuation. Resuming last sync')
314+
// When resuming a continuation, the CachingTreeWrapper is usually not initialized yet, because the localTree is
315+
// set from the persisted continuation
316316
await this.localCachingResource.setCacheTree(await this.localCachingResource.getBookmarksTree())
317-
await this.syncProcess.sync()
318317
}
319318

319+
await this.syncProcess.sync()
320+
320321
await this.setData({ scheduled: false, syncing: 1 })
321322

322323
// update cache

src/lib/browser/BrowserTree.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export default class BrowserTree implements IResource<typeof ItemLocation.LOCAL>
9797
if (node.id === this.absoluteRoot.id) {
9898
isRoot = true
9999
}
100-
if (node.children) {
100+
if (Array.isArray(node.children)) {
101101
// seeded pseudo random number generator for separator IDs
102102
// We use this because we want IDs that are (largely) collision-free even
103103
// between folders and still consistent across browsers
@@ -138,7 +138,11 @@ export default class BrowserTree implements IResource<typeof ItemLocation.LOCAL>
138138
})
139139
}
140140
}
141-
return recurse(tree) as Folder<typeof ItemLocation.LOCAL>
141+
const processedTree = recurse(tree) as Folder<typeof ItemLocation.LOCAL>
142+
if (!processedTree) {
143+
throw new LocalFolderNotFoundError()
144+
}
145+
return processedTree
142146
}
143147

144148
async createBookmark(bookmark:Bookmark<typeof ItemLocation.LOCAL>): Promise<string|number> {

src/lib/strategies/Default.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ export default class SyncProcess {
426426
this.localTree.setHashSettings(this.hashSettings)
427427
this.server.setHashSettings(this.hashSettings)
428428

429-
if (!this.localTreeRoot) {
429+
if (!this.localTreeRoot || typeof this.localTreeRoot.children === 'undefined') {
430430
Logger.log('Retrieving local tree')
431431
const localTreeRoot = await this.localTree.getBookmarksTree()
432432
Logger.log('Filtering out unaccepted local bookmarks')
@@ -525,21 +525,29 @@ export default class SyncProcess {
525525
}
526526

527527
filterOutInvalidBookmarks(tree: Folder<TItemLocation>): void {
528+
const invalidBookmarks = []
528529
tree.children = tree.children.filter(child => {
529530
if (child instanceof Bookmark) {
530531
// Chrome URLs cannot be added in firefox
531532
if (this.isFirefox && child.url.startsWith('chrome')) {
533+
invalidBookmarks.push(child)
532534
return false
533535
}
534536
// Linkwarden supports bookmarks that have no URL eg. for directly uploaded files
535537
if (child.url === null) {
538+
invalidBookmarks.push(child)
536539
return false
537540
}
538541
} else {
539542
this.filterOutInvalidBookmarks(child)
540543
}
541544
return true
542545
})
546+
invalidBookmarks.length &&
547+
Logger.log(
548+
'Filtered out the following invalid bookmarks before syncing',
549+
invalidBookmarks
550+
)
543551
}
544552

545553
async filterOutDuplicatesInTheSameFolder(tree: Folder<TItemLocation>): Promise<void> {

src/lib/strategies/Unidirectional.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ export default class UnidirectionalSyncProcess extends DefaultStrategy {
3333

3434
// Stage 2
3535
'revertReorders',
36+
37+
'direction'
3638
]
3739
}
3840

0 commit comments

Comments
 (0)