diff --git a/CHANGELOG.md b/CHANGELOG.md index 9cc2d99f00e411f7cc1fc5e9ca3231b199f568fc..ebc87df40a0b844a1c2b61add7c6a201b496be89 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 diff --git a/app/classes/web/routes/api/crafty/upload/index.py b/app/classes/web/routes/api/crafty/upload/index.py index a3718b0479ffc6d0c5e228cd3d754cfdf6215410..3393d4493ff9bf2cc5a377a3d1a56f1a035db697 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)