Skip to content

Commit 741c14b

Browse files
committed
fix(CachingAdapter): set initialTreeHash after getBookmarksTree
to make sure setHashSettings has been called before Signed-off-by: Marcel Klehr <[email protected]>
1 parent f240866 commit 741c14b

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

src/lib/Tree.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ export class Bookmark<L extends TItemLocation> {
8787
async hash({preserveOrder = false, hashFn = 'sha256'}: IHashSettings = {preserveOrder: false, hashFn: 'sha256'}):Promise<string> {
8888
if (!this.hashValue) {
8989
this.hashValue = {}
90+
}
91+
if (typeof this.hashValue[hashFn] !== 'undefined') {
9092
const json = JSON.stringify({ title: this.title, url: this.url })
9193
if (hashFn === 'sha256') {
9294
this.hashValue[hashFn] = await Crypto.sha256(json)

src/lib/adapters/Git.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
SlashError
1616
} from '../../errors/Error'
1717
import Crypto from '../Crypto'
18+
import { Folder, TItemLocation } from '../Tree'
1819

1920
const LOCK_INTERVAL = 2 * 60 * 1000 // Lock every 2mins while syncing
2021
const LOCK_TIMEOUT = 15 * 60 * 1000 // Override lock 0.25h after last time lock has been set
@@ -65,6 +66,13 @@ export default class GitAdapter extends CachingAdapter {
6566
this.cancelCallback && this.cancelCallback()
6667
}
6768

69+
async getBookmarksTree(): Promise<Folder<TItemLocation>> {
70+
// setHashSettings is called after onSyncStart only but before getBookmarksTree
71+
// thus we get the hash here again
72+
this.initialTreeHash = await this.bookmarksCache.hash(this.hashSettings)
73+
return super.getBookmarksTree()
74+
}
75+
6876
async onSyncStart(needLock = true, forceLock = false) {
6977
Logger.log('onSyncStart: begin')
7078

src/lib/adapters/GoogleDrive.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
} from '../../errors/Error'
1313
import { OAuth2Client } from '@byteowls/capacitor-oauth2'
1414
import { Capacitor, CapacitorHttp as Http } from '@capacitor/core'
15+
import { Folder, TItemLocation } from '../Tree'
1516

1617
const OAuthConfig = {
1718
authorizationBaseUrl: 'https://accounts.google.com/o/oauth2/auth',
@@ -197,6 +198,13 @@ export default class GoogleDriveAdapter extends CachingAdapter {
197198
})
198199
}
199200

201+
async getBookmarksTree(): Promise<Folder<TItemLocation>> {
202+
// setHashSettings is called after onSyncStart only but before getBookmarksTree
203+
// thus we get the hash here again
204+
this.initialTreeHash = await this.bookmarksCache.hash(this.hashSettings)
205+
return super.getBookmarksTree()
206+
}
207+
200208
async onSyncStart(needLock = true, forceLock = false) {
201209
Logger.log('onSyncStart: begin')
202210

src/lib/adapters/WebDav.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
import { CapacitorHttp as Http } from '@capacitor/core'
1616
import { Capacitor } from '@capacitor/core'
1717
import Html from '../serializers/Html'
18+
import { Folder, TItemLocation } from '../Tree'
1819

1920
const LOCK_INTERVAL = 2 * 60 * 1000 // Lock every 2mins while syncing
2021
const LOCK_TIMEOUT = 15 * 60 * 1000 // Override lock 0.25h after last time lock has been set
@@ -284,6 +285,13 @@ export default class WebDavAdapter extends CachingAdapter {
284285
return response
285286
}
286287

288+
async getBookmarksTree(): Promise<Folder<TItemLocation>> {
289+
// setHashSettings is called after onSyncStart only but before getBookmarksTree
290+
// thus we get the hash here again
291+
this.initialTreeHash = await this.bookmarksCache.hash(this.hashSettings)
292+
return super.getBookmarksTree()
293+
}
294+
287295
async onSyncStart(needLock = true, forceLock = false) {
288296
Logger.log('onSyncStart: begin')
289297
this.ended = false

0 commit comments

Comments
 (0)