From c31916057ff3e20c61d883c24dc3c8f84e1cbb92 Mon Sep 17 00:00:00 2001 From: Ife Lawal Date: Sun, 6 Jun 2021 23:21:38 -0400 Subject: [PATCH] Confirmed REST API does delete directories in s3 bucket. The local filesystem didn't though and that was updated. Closes #1758 (#1876) - Deleting uploads under the Filesystem upload provider will now delete the parent folder as well as the target file - Closes #1758 --- CTFd/utils/uploads/uploaders.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/CTFd/utils/uploads/uploaders.py b/CTFd/utils/uploads/uploaders.py index 9220c744..1a457d06 100644 --- a/CTFd/utils/uploads/uploaders.py +++ b/CTFd/utils/uploads/uploaders.py @@ -1,7 +1,8 @@ import os import posixpath import string -from shutil import copyfileobj +from pathlib import PurePath +from shutil import copyfileobj, rmtree import boto3 from flask import current_app, redirect, send_file @@ -64,7 +65,8 @@ class FilesystemUploader(BaseUploader): def delete(self, filename): if os.path.exists(os.path.join(self.base_path, filename)): - os.unlink(os.path.join(self.base_path, filename)) + file_path = PurePath(filename).parts[0] + rmtree(os.path.join(self.base_path, file_path)) return True return False