diff --git a/package.json b/package.json index 401403a709a..71015e17168 100644 --- a/package.json +++ b/package.json @@ -1523,6 +1523,9 @@ "strip-ansi": "^7.2.0" } } + }, + "patchedDependencies": { + "@whiskeysockets/baileys@7.0.0-rc.9": "patches/@whiskeysockets__baileys@7.0.0-rc.9.patch" } } } diff --git a/patches/@whiskeysockets__baileys@7.0.0-rc.9.patch b/patches/@whiskeysockets__baileys@7.0.0-rc.9.patch new file mode 100644 index 00000000000..c3e95ad54c9 --- /dev/null +++ b/patches/@whiskeysockets__baileys@7.0.0-rc.9.patch @@ -0,0 +1,22 @@ +diff --git a/lib/Utils/messages-media.js b/lib/Utils/messages-media.js +index 0d32dfb4882dfe029ba8804772d7d89404b08e76..4eb2b214b48ef3af48f707237cd19c05e11632a6 100644 +--- a/lib/Utils/messages-media.js ++++ b/lib/Utils/messages-media.js +@@ -353,9 +353,17 @@ export const encryptedStream = async (media, mediaType, { logger, saveOriginalFi + const fileSha256 = sha256Plain.digest(); + const fileEncSha256 = sha256Enc.digest(); + encFileWriteStream.write(mac); ++ // Create finish promises before calling end() to avoid missing the event ++ const encFinishPromise = once(encFileWriteStream, 'finish'); ++ const originalFinishPromise = originalFileStream ? once(originalFileStream, 'finish') : Promise.resolve(); + encFileWriteStream.end(); + originalFileStream?.end?.(); + stream.destroy(); ++ // Wait for write streams to fully flush to disk before returning encFilePath. ++ // Without this await, the caller may open a read stream on the file before ++ // the OS has created it, causing a race-condition ENOENT crash. ++ await encFinishPromise; ++ await originalFinishPromise; + logger?.debug('encrypted data successfully'); + return { + mediaKey, diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b7fefafb71f..a7f9818cf5d 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -27,6 +27,11 @@ overrides: packageExtensionsChecksum: sha256-n+P/SQo4Pf+dHYpYn1Y6wL4cJEVoVzZ835N0OEp4TM8= +patchedDependencies: + '@whiskeysockets/baileys@7.0.0-rc.9': + hash: c79c66180c377cf57f4dd1657c85b572fafb3cf9667ea36af5d4a991eb6bb709 + path: patches/@whiskeysockets__baileys@7.0.0-rc.9.patch + importers: .: @@ -1221,7 +1226,7 @@ importers: dependencies: '@whiskeysockets/baileys': specifier: 7.0.0-rc.9 - version: 7.0.0-rc.9(audio-decode@2.2.3)(jimp@1.6.1)(sharp@0.34.5) + version: 7.0.0-rc.9(patch_hash=c79c66180c377cf57f4dd1657c85b572fafb3cf9667ea36af5d4a991eb6bb709)(audio-decode@2.2.3)(jimp@1.6.1)(sharp@0.34.5) jimp: specifier: ^1.6.1 version: 1.6.1 @@ -11423,7 +11428,7 @@ snapshots: '@wasm-audio-decoders/common': 9.0.7 optional: true - '@whiskeysockets/baileys@7.0.0-rc.9(audio-decode@2.2.3)(jimp@1.6.1)(sharp@0.34.5)': + '@whiskeysockets/baileys@7.0.0-rc.9(patch_hash=c79c66180c377cf57f4dd1657c85b572fafb3cf9667ea36af5d4a991eb6bb709)(audio-decode@2.2.3)(jimp@1.6.1)(sharp@0.34.5)': dependencies: '@cacheable/node-cache': 1.7.6 '@hapi/boom': 9.1.4