Skip to content

Commit 1a7dd7d

Browse files
committed
fix(Sync): Check if the local folder path has changed before syncing
fixes #2090 Signed-off-by: Marcel Klehr <[email protected]>
1 parent 2e2922a commit 1a7dd7d

File tree

6 files changed

+38
-5
lines changed

6 files changed

+38
-5
lines changed

_locales/en/messages.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@
131131
"Error044": {
132132
"message": "E044: Git push operation failed: {0}"
133133
},
134+
"Error045": {
135+
"message": "E045: Unexpected folder path. The local sync folder for this profile used to be at `{0}` but is now at `{1}`. Please make sure this is intended and set the local sync folder again in the profile settings."
136+
},
134137
"LabelWebdavurl": {
135138
"message": "WebDAV URL"
136139
},
@@ -329,9 +332,6 @@
329332
"DescriptionFunddevelopment": {
330333
"message": "Work on floccus is fuelled by a voluntary subscription model. If you think what I do is worthwhile, and if you can spare a few coins each month without hardship, please support my work. Also, please consider giving floccus a rating on the addon store of your choice. Thank you!💙"
331334
},
332-
"LabelSelect": {
333-
"message": "Select"
334-
},
335335
"LabelUntitledfolder": {
336336
"message": "Untitled folder"
337337
},

src/errors/Error.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,4 +379,17 @@ export class GitPushError extends FloccusError {
379379
this.errorMessage = errorMessage
380380
Object.setPrototypeOf(this, GitPushError.prototype)
381381
}
382+
}
383+
384+
export class UnexpectedFolderPathError extends FloccusError {
385+
public originalPath: string
386+
public newPath: string
387+
388+
constructor(originalPath: string, newPath: string) {
389+
super(`E045: Unexpected folder path. The local sync folder for this profile used to be at '${originalPath}' but is now at '${newPath}'. Please make sure this is intended and set the local sync folder again in the profile settings.`)
390+
this.code = 45
391+
this.originalPath = originalPath
392+
this.newPath = newPath
393+
Object.setPrototypeOf(this, UnexpectedFolderPathError.prototype)
394+
}
382395
}

src/lib/Account.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import { isTest } from './isTest'
1414
import { setUser, setContext, withScope, captureException } from '@sentry/browser'
1515
import AsyncLock from 'async-lock'
1616
import CachingTreeWrapper from './CachingTreeWrapper'
17+
import BrowserTree from './browser/BrowserTree'
18+
import { UnexpectedFolderPathError } from '../errors/Error'
1719

1820
declare const DEBUG: boolean
1921

@@ -184,6 +186,14 @@ export default class Account {
184186
await this.init()
185187
}
186188

189+
if (Capacitor.getPlatform() === 'web') {
190+
const newPath = await BrowserTree.getPathFromLocalId(this.getData().localRoot)
191+
const oldPath = this.getData().rootPath
192+
if (oldPath && newPath !== oldPath) {
193+
throw new UnexpectedFolderPathError(oldPath, newPath)
194+
}
195+
}
196+
187197
if (this.server.onSyncStart) {
188198
const needLock = (strategy || this.getData().strategy) !== 'slave'
189199
let status

src/lib/browser/BrowserAccount.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
HttpError,
1111
InconsistentBookmarksExistenceError, LockFileError,
1212
MissingItemOrderError,
13-
ParseResponseError,
13+
ParseResponseError, UnexpectedFolderPathError,
1414
UnknownFolderItemOrderError, UpdateBookmarkError
1515
} from '../../errors/Error'
1616
import {i18n} from '../native/I18n'
@@ -53,6 +53,7 @@ export default class BrowserAccount extends Account {
5353
accData.rootPath = await BrowserTree.getPathFromLocalId(node.id)
5454
await this.setData(accData)
5555
}
56+
await this.setData({rootPath: await BrowserTree.getPathFromLocalId(accData.localRoot)})
5657
await this.storage.initMappings()
5758
await this.storage.initCache()
5859
this.localTree = new BrowserTree(this.storage, accData.localRoot)
@@ -122,6 +123,9 @@ export default class BrowserAccount extends Account {
122123
if (er instanceof GitPushError) {
123124
return i18n.getMessage('Error' + String(er.code).padStart(3, '0'), [er.errorMessage])
124125
}
126+
if (er instanceof UnexpectedFolderPathError) {
127+
return i18n.getMessage('Error' + String(er.code).padStart(3, '0'), [er.originalPath, er.newPath])
128+
}
125129
if (er instanceof FloccusError) {
126130
return i18n.getMessage('Error' + String(er.code).padStart(3, '0'))
127131
}

src/lib/native/NativeAccount.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
HttpError,
1111
InconsistentBookmarksExistenceError, LockFileError,
1212
MissingItemOrderError,
13-
ParseResponseError,
13+
ParseResponseError, UnexpectedFolderPathError,
1414
UnknownFolderItemOrderError, UpdateBookmarkError
1515
} from '../../errors/Error'
1616
import Logger from '../Logger'
@@ -100,6 +100,9 @@ export default class NativeAccount extends Account {
100100
if (er instanceof GitPushError) {
101101
return i18n.getMessage('Error' + String(er.code).padStart(3, '0'), [er.errorMessage])
102102
}
103+
if (er instanceof UnexpectedFolderPathError) {
104+
return i18n.getMessage('Error' + String(er.code).padStart(3, '0'), [er.originalPath, er.newPath])
105+
}
103106
if (er instanceof FloccusError) {
104107
return i18n.getMessage('Error' + String(er.code).padStart(3, '0'))
105108
}

src/ui/store/actions.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ export const actionsDefinition = {
7474
if (oldData.localRoot !== data.localRoot) {
7575
await account.init()
7676
}
77+
if (data.rootPath !== await BrowserTree.getPathFromLocalId(data.localRoot)) {
78+
await account.init()
79+
}
7780
if (oldData.bookmark_file !== data.bookmark_file) {
7881
await account.init()
7982
}

0 commit comments

Comments
 (0)