Skip to content

Commit 143d479

Browse files
authored
Merge pull request #19 from ZHYCarge/master
add:当最后一个文件被删除时,删除整个存放目录
2 parents 757e8ec + 58c1d3d commit 143d479

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

storage.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,21 @@ async def delete_file(self, text: str):
7575
filepath = await self.get_filepath(text)
7676
if filepath.exists():
7777
await asyncio.to_thread(os.remove, filepath)
78+
await asyncio.to_thread(self.judge_delete_folder, filepath)
7879

7980
async def delete_files(self, texts):
8081
tasks = [self.delete_file(text) for text in texts]
8182
await asyncio.gather(*tasks)
8283

84+
def judge_delete_folder(self, filepath):
85+
currpath = os.path.dirname(filepath)
86+
if os.listdir(currpath):
87+
return
88+
while str(currpath) != (str(self.DATA_ROOT) + '\\upload'):
89+
if not os.listdir(currpath):
90+
os.rmdir(os.path.abspath(currpath))
91+
currpath = os.path.dirname(currpath)
92+
8393

8494
STORAGE_ENGINE = {
8595
"filesystem": FileSystemStorage

0 commit comments

Comments
 (0)