From 181258797028a002e6bcfb8077ea3b51f57dcccc Mon Sep 17 00:00:00 2001 From: Henry Heino <46334387+personalizedrefrigerator@users.noreply.github.com> Date: Thu, 11 Apr 2024 00:43:39 -0700 Subject: [PATCH] Chore: Fixes #10285: Fix failing tarExtract test (#10295) --- packages/app-mobile/utils/fs-driver/tarExtract.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/app-mobile/utils/fs-driver/tarExtract.ts b/packages/app-mobile/utils/fs-driver/tarExtract.ts index 34ad137b6..0fedfc129 100644 --- a/packages/app-mobile/utils/fs-driver/tarExtract.ts +++ b/packages/app-mobile/utils/fs-driver/tarExtract.ts @@ -30,8 +30,12 @@ const tarExtract = async (options: TarExtractOptions) => { throw new Error(`Extracting ${outPath} would overwrite`); } - // Move to the next item when all available data has been read. - stream.once('end', () => next()); + // Allows moving to the next item after all data for this entry has been read + // **and** this data has been processed. + // See https://github.com/laurent22/joplin/issues/10285 + const streamEndPromise = new Promise((resolve) => { + stream.once('end', () => resolve()); + }); if (header.type === 'directory') { await fsDriver.mkdir(outPath); @@ -46,7 +50,8 @@ const tarExtract = async (options: TarExtractOptions) => { // Drain the rest of the stream. stream.resume(); - + await streamEndPromise; + next(); }); let finished = false;