Skip to content

Commit

Permalink
fix: Really update files when metadata update is needed
Browse files Browse the repository at this point in the history
Removed the mix of `shouldReplace` and `forceReplaceFile` attributes.
  • Loading branch information
doubleface authored and doubleface committed Jan 13, 2025
1 parent 894b685 commit 55b18df
Showing 1 changed file with 10 additions and 8 deletions.
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

0 comments on commit 55b18df

Please sign in to comment.