From b78902fc8db9b586d890d2f8446607c0fb20d5e5 Mon Sep 17 00:00:00 2001 From: Lucas Maia <58118141+Iucasmaia@users.noreply.github.com> Date: Sun, 2 Feb 2025 06:52:55 -0300 Subject: [PATCH] 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 --- src/Utils/messages.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Utils/messages.ts b/src/Utils/messages.ts index ae23122..3e80215 100644 --- a/src/Utils/messages.ts +++ b/src/Utils/messages.ts @@ -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') + } } } )