From 3a4ad93167b7f3fe6327a3b954bd22c62af0bad5 Mon Sep 17 00:00:00 2001 From: Ldoppea Date: Fri, 20 Dec 2024 17:39:12 +0100 Subject: [PATCH] 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 --- .../backup/services/manageLocalBackupConfig.ts | 6 +++++- .../backup/services/manageRemoteBackupConfig.ts | 16 +++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/app/domain/backup/services/manageLocalBackupConfig.ts b/src/app/domain/backup/services/manageLocalBackupConfig.ts index 77334baff..26a61ba53 100644 --- a/src/app/domain/backup/services/manageLocalBackupConfig.ts +++ b/src/app/domain/backup/services/manageLocalBackupConfig.ts @@ -205,11 +205,15 @@ export const fixLocalBackupConfigIfNecessary = async ( const fileQuery = buildFileQuery( localBackupConfig.remoteBackupConfig.backupFolder.id ) + const fileQueryOptions = { forceStack: true } let remoteBackupFolderUpdated try { - const { data } = (await client.query(fileQuery)) as FileCollectionGetResult + const { data } = (await client.query( + fileQuery, + fileQueryOptions + )) as FileCollectionGetResult remoteBackupFolderUpdated = data } catch (e) { diff --git a/src/app/domain/backup/services/manageRemoteBackupConfig.ts b/src/app/domain/backup/services/manageRemoteBackupConfig.ts index 2a163d5f6..e267d162a 100644 --- a/src/app/domain/backup/services/manageRemoteBackupConfig.ts +++ b/src/app/domain/backup/services/manageRemoteBackupConfig.ts @@ -230,9 +230,11 @@ export const createRemoteBackupFolder = async ( ) const fileQuery = buildFileQuery(backupFolderId) + const fileQueryOptions = { forceStack: true } const { data: backupFolder } = (await client.query( - fileQuery + fileQuery, + fileQueryOptions )) as FileCollectionGetResult const remoteBackupConfig = { @@ -331,8 +333,12 @@ export const getRemoteFiles = (): File[] => { const fetchAllRemoteFiles = async (client: CozyClient): Promise => { const filesQuery = buildAllMediasFilesQuery() + const fileQueryOptions = { forceStack: true } - const remoteFiles = (await client.queryAll(filesQuery)) as FilesQueryAllResult + const remoteFiles = (await client.queryAll( + filesQuery, + fileQueryOptions + )) as FilesQueryAllResult const remoteFilesNotInTrash = remoteFiles.filter( file => !isInTrash(file.path) @@ -372,7 +378,11 @@ export const fetchBackupedMedias = async ( const filesQuery = buildFilesQuery(deviceId) - const data = (await client.queryAll(filesQuery)) as FilesQueryAllResult + const filesQueryOption = { forceStack: true } + const data = (await client.queryAll( + filesQuery, + filesQueryOption + )) as FilesQueryAllResult const backupedMedias = filterMediasAlreadyBackuped(allMedias, data)