messages: fix EPERM error by verifying temp file removal when sending images (#1227)

* messages: add verification to remove temp file, solve EPERM operation not permitted

* fix lint on messages

* another try to fix lint for pr health

* Fixed, too many changes were breaking the code; this should be enough

* another try to fix this
This commit is contained in:
Lucas Maia
2025-02-02 06:52:55 -03:00
committed by GitHub
parent 0d9c0e4b2a
commit b78902fc8d

View File

@@ -225,8 +225,13 @@ export const prepareWAMessageMedia = async(
encWriteStream.destroy()
// remove tmp files
if(didSaveToTmpPath && bodyPath) {
await fs.unlink(bodyPath)
logger?.debug('removed tmp files')
try {
await fs.access(bodyPath)
await fs.unlink(bodyPath)
logger?.debug('removed tmp file')
} catch(error) {
logger?.warn('failed to remove tmp file')
}
}
}
)