From 43f9e6c8e4635375077b990e6f8f5f32c8959cd3 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Fri, 17 Jun 2022 15:09:45 -0400 Subject: [PATCH] fix: handle ENOENT on file deletion, closes #10645 --- public/language/en-GB/admin/settings/uploads.json | 1 + src/file.js | 5 +++++ src/views/admin/settings/uploads.tpl | 5 +++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/public/language/en-GB/admin/settings/uploads.json b/public/language/en-GB/admin/settings/uploads.json index 5ca546848c..078a19ccd2 100644 --- a/public/language/en-GB/admin/settings/uploads.json +++ b/public/language/en-GB/admin/settings/uploads.json @@ -5,6 +5,7 @@ "strip-exif-data": "Strip EXIF Data", "preserve-orphaned-uploads": "Keep uploaded files on disk after a post is purged", "orphanExpiryDays": "Days to keep orphaned files", + "orphanExpiryDays-help": "After this many days, orphaned uploads will be deleted from the file system.
Set 0 or leave blank to disable.", "private-extensions": "File extensions to make private", "private-uploads-extensions-help": "Enter comma-separated list of file extensions to make private here (e.g. pdf,xls,doc). An empty list means all files are private.", "resize-image-width-threshold": "Resize images if they are wider than specified width", diff --git a/src/file.js b/src/file.js index 6f1f0ebedd..ff836b05da 100644 --- a/src/file.js +++ b/src/file.js @@ -107,6 +107,11 @@ file.delete = async function (path) { try { await fs.promises.unlink(path); } catch (err) { + if (err.code === 'ENOENT') { + winston.verbose(`[file] Attempted to delete non-existent file: ${path}`); + return; + } + winston.warn(err); } }; diff --git a/src/views/admin/settings/uploads.tpl b/src/views/admin/settings/uploads.tpl index 8cb352c987..820d6943dc 100644 --- a/src/views/admin/settings/uploads.tpl +++ b/src/views/admin/settings/uploads.tpl @@ -135,9 +135,10 @@
-
+
- + +

[[admin/settings/uploads:orphanExpiryDays-help]]