From 18c2da9bcfbf8151853e00f83602e32266ddbcf7 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 14 Sep 2025 13:39:32 -0400 Subject: [PATCH 1/2] Use async unlink for file removal on upload --- app/classes/web/routes/api/crafty/upload/index.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/classes/web/routes/api/crafty/upload/index.py b/app/classes/web/routes/api/crafty/upload/index.py index a3718b04..3393d449 100644 --- a/app/classes/web/routes/api/crafty/upload/index.py +++ b/app/classes/web/routes/api/crafty/upload/index.py @@ -298,7 +298,14 @@ class ApiFilesUploadHandler(BaseApiHandler): chunk_file = os.path.join(self.temp_dir, f"{self.filename}.part{i}") async with await anyio.open_file(chunk_file, "rb") as infile: await outfile.write(await infile.read()) - os.remove(chunk_file) + try: + await anyio.Path(chunk_file).unlink(missing_ok=True) + except (PermissionError, FileNotFoundError) as why: + logger.error("Failed to remove chunk file with error: %s", why) + try: + self.file_helper.del_dirs(self.temp_dir) + except (PermissionError, FileNotFoundError) as why: + logger.error("Failed to import remove temp dir with error: %s", why) if upload_type == "background": # Strip EXIF data image_path = os.path.join(file_path) -- GitLab From e5e40aba92b17fe80d8b42c5213e8f007d6873fe Mon Sep 17 00:00:00 2001 From: Zedifus Date: Mon, 15 Sep 2025 00:29:19 +0100 Subject: [PATCH 2/2] Update changelog !894 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9cc2d99f..ebc87df4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,7 @@ ### New features TBD ### Bug fixes -TBD +- Refactor to upload chunk removal to ensure file operations are asynchronous ([Merge Request](https://gitlab.com/crafty-controller/crafty-4/-/merge_requests/894)) ### Tweaks TBD ### Lang -- GitLab