Skip to content

Commit cd700c0

Browse files
committed
fix: Enforce Stack queries when doing backup
When doing a backup, we don't want instable network to make the CozyClient use local PouchLink for some queries that need to read files paths In cozy/cozy-client#1575 we implemented the `forceStack` option that allows to enforce the usage of StackLink instead of other links that may retrieve local incomplete data This commit enforce the stack on backup related queries Related PR: cozy/cozy-client#1575
1 parent 37305e6 commit cd700c0

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/app/domain/backup/services/manageLocalBackupConfig.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,15 @@ export const fixLocalBackupConfigIfNecessary = async (
205205
const fileQuery = buildFileQuery(
206206
localBackupConfig.remoteBackupConfig.backupFolder.id
207207
)
208+
const fileQueryOptions = { forceStack: true }
208209

209210
let remoteBackupFolderUpdated
210211

211212
try {
212-
const { data } = (await client.query(fileQuery)) as FileCollectionGetResult
213+
const { data } = (await client.query(
214+
fileQuery,
215+
fileQueryOptions
216+
)) as FileCollectionGetResult
213217

214218
remoteBackupFolderUpdated = data
215219
} catch (e) {

src/app/domain/backup/services/manageRemoteBackupConfig.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,11 @@ export const createRemoteBackupFolder = async (
230230
)
231231

232232
const fileQuery = buildFileQuery(backupFolderId)
233+
const fileQueryOptions = { forceStack: true }
233234

234235
const { data: backupFolder } = (await client.query(
235-
fileQuery
236+
fileQuery,
237+
fileQueryOptions
236238
)) as FileCollectionGetResult
237239

238240
const remoteBackupConfig = {
@@ -331,8 +333,12 @@ export const getRemoteFiles = (): File[] => {
331333

332334
const fetchAllRemoteFiles = async (client: CozyClient): Promise<File[]> => {
333335
const filesQuery = buildAllMediasFilesQuery()
336+
const fileQueryOptions = { forceStack: true }
334337

335-
const remoteFiles = (await client.queryAll(filesQuery)) as FilesQueryAllResult
338+
const remoteFiles = (await client.queryAll(
339+
filesQuery,
340+
fileQueryOptions
341+
)) as FilesQueryAllResult
336342

337343
const remoteFilesNotInTrash = remoteFiles.filter(
338344
file => !isInTrash(file.path)
@@ -372,7 +378,11 @@ export const fetchBackupedMedias = async (
372378

373379
const filesQuery = buildFilesQuery(deviceId)
374380

375-
const data = (await client.queryAll(filesQuery)) as FilesQueryAllResult
381+
const filesQueryOption = { forceStack: true }
382+
const data = (await client.queryAll(
383+
filesQuery,
384+
filesQueryOption
385+
)) as FilesQueryAllResult
376386

377387
const backupedMedias = filterMediasAlreadyBackuped(allMedias, data)
378388

0 commit comments

Comments
 (0)