Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Really update files when metadata update is needed (SCR-839) #1021

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions packages/cozy-clisk/src/launcher/saveFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import { dataUriToArrayBuffer } from '../libs/utils'
* @property {string} [contract.id] - id of the contract
* @property {string} [contract.name] - name of the contract
* @property {import('cozy-client/types/types').IOCozyFile} [existingFile] - already existing file corresponding to the entry
* @property {boolean} [shouldReplace] - Internal result of the shouldReplaceFile function on the entry
* @property {boolean} [forceReplaceFile] - should the konnector force the replace of the current file
* @property {import('cozy-client/types/types').IOCozyFile} [fileDocument] - Resulting cozy file
*/
Expand Down Expand Up @@ -140,13 +139,17 @@ const saveFiles = async (client, entries, folderPath, options) => {
for (const entry of entries) {
const fileKey = calculateFileKey(entry, options.fileIdAttributes)
const existingFile = options.existingFilesIndex.get(fileKey)
let shouldReplace = false
let forceReplaceFile = false
if (existingFile) {
shouldReplace = shouldReplaceFile(existingFile, entry, saveOptions)
forceReplaceFile = shouldReplaceFile(existingFile, entry, saveOptions)
}

if (!existingFile || shouldReplace) {
toSaveEntries.push({ ...entry, existingFile, shouldReplace })
if (!existingFile || forceReplaceFile) {
toSaveEntries.push({
...entry,
existingFile,
forceReplaceFile
})
} else {
savedEntries.push({ ...entry, fileDocument: existingFile })
}
Expand Down Expand Up @@ -349,7 +352,7 @@ const saveFile = async function (client, entry, options) {

if (
entry.fileurl &&
(!entry.existingFile || entry.shouldReplace) &&
(!entry.existingFile || entry.forceReplaceFile) &&
options.downloadAndFormatFile
) {
const downloadedEntry = await options.downloadAndFormatFile(entry)
Expand All @@ -375,7 +378,7 @@ const saveFile = async function (client, entry, options) {
}

let method = 'create'
if (resultEntry.shouldReplace && resultEntry.existingFile) {
if (resultEntry.forceReplaceFile && resultEntry.existingFile) {
method = 'updateById'
options.log(
'debug',
Expand Down Expand Up @@ -863,7 +866,6 @@ function sanitizeEntry(entry) {
delete entry.filestream
delete entry.shouldReplaceFile
delete entry.existingFile
delete entry.shouldReplace
delete entry.forceReplaceFile
delete entry.fileAttributes
return entry
Expand Down