Merge pull request #4231 from dpalou/MOBILE-4653

MOBILE-4653 core: Fix race condition when uploading files
main
Pau Ferrer Ocaña 2024-11-07 15:54:06 +01:00 committed by GitHub
commit bb4cdb6f01
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 5 additions and 7 deletions

View File

@ -639,7 +639,8 @@ export class CoreFileUploaderProvider {
}
});
await Promise.all(filesToUpload.map(async (file) => {
// Upload files 1 by 1 to avoid race conditions in the server.
for (const file of filesToUpload) {
// Make sure the file name is unique in the area.
const name = CoreFile.calculateUniqueName(usedNames, file.name);
usedNames[name] = file;
@ -649,7 +650,7 @@ export class CoreFileUploaderProvider {
const options = this.getFileUploadOptions(filePath, name, undefined, false, 'draft', itemId);
await this.uploadFile(filePath, options, undefined, siteId);
}));
}
}
/**
@ -742,15 +743,12 @@ export class CoreFileUploaderProvider {
// Upload only the first file first to get a draft id.
const itemId = await this.uploadOrReuploadFile(files[0], 0, component, componentId, siteId);
const promises: Promise<number>[] = [];
// Upload files 1 by 1 to avoid race conditions in the server.
for (let i = 1; i < files.length; i++) {
const file = files[i];
promises.push(this.uploadOrReuploadFile(file, itemId, component, componentId, siteId));
await this.uploadOrReuploadFile(file, itemId, component, componentId, siteId);
}
await Promise.all(promises);
return itemId;
}