add:当最后一个文件被删除时,删除整个存放目录
This commit is contained in:
+10
@@ -75,11 +75,21 @@ class FileSystemStorage:
|
||||
filepath = await self.get_filepath(text)
|
||||
if filepath.exists():
|
||||
await asyncio.to_thread(os.remove, filepath)
|
||||
await asyncio.to_thread(self.judge_delete_folder, filepath)
|
||||
|
||||
async def delete_files(self, texts):
|
||||
tasks = [self.delete_file(text) for text in texts]
|
||||
await asyncio.gather(*tasks)
|
||||
|
||||
def judge_delete_folder(self, filepath):
|
||||
currpath = os.path.dirname(filepath)
|
||||
if os.listdir(currpath):
|
||||
return
|
||||
while str(currpath) != (str(self.DATA_ROOT) + '\\upload'):
|
||||
if not os.listdir(currpath):
|
||||
os.rmdir(os.path.abspath(currpath))
|
||||
currpath = os.path.dirname(currpath)
|
||||
|
||||
|
||||
STORAGE_ENGINE = {
|
||||
"filesystem": FileSystemStorage
|
||||
|
||||
Reference in New Issue
Block a user