From 3058069a7da33d907813e155894f0b8be258cd0d Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Thu, 16 Apr 2020 19:05:25 +0200 Subject: [PATCH] Check files before deleting them --- src/helpers/AccountImageHelper.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/helpers/AccountImageHelper.ts b/src/helpers/AccountImageHelper.ts index 7062748..8be9676 100644 --- a/src/helpers/AccountImageHelper.ts +++ b/src/helpers/AccountImageHelper.ts @@ -34,7 +34,7 @@ export class AccountImageHelper { // First, delete any previous account image const currInfo = await this.Get(userID); - if(currInfo.hasImage) + if(currInfo.hasImage && existsSync(currInfo.sysPath)) unlinkSync(currInfo.sysPath); writeFileSync(this.GetPathMetadataFile(userID), path.replace("avatars/", "")); @@ -48,10 +48,12 @@ export class AccountImageHelper { public static async Delete(userID: number) { const currInfo = await this.Get(userID); if(currInfo.hasImage) { - unlinkSync(currInfo.sysPath); + if(existsSync(currInfo.sysPath)) + unlinkSync(currInfo.sysPath); // Delete meta file - unlinkSync(this.GetPathMetadataFile(userID)); + if(existsSync(this.GetPathMetadataFile(userID))) + unlinkSync(this.GetPathMetadataFile(userID)); // Delete visiblity file (if any) const visibilityFile = this.GetPathVisibilityFile(userID);