fix #508
This commit is contained in:
parent
c05ffed6df
commit
7ce656148f
@ -590,20 +590,26 @@ class TransferChain(ChainBase):
|
|||||||
logger.info(f"开始删除文件以及空目录:{path} ...")
|
logger.info(f"开始删除文件以及空目录:{path} ...")
|
||||||
if not path.exists():
|
if not path.exists():
|
||||||
return
|
return
|
||||||
elif path.is_file():
|
if path.is_file():
|
||||||
# 删除文件
|
# 删除文件
|
||||||
path.unlink()
|
path.unlink()
|
||||||
logger.warn(f"文件 {path} 已删除")
|
logger.warn(f"文件 {path} 已删除")
|
||||||
# 判断目录是否为空, 为空则删除
|
# 需要删除父目录
|
||||||
if str(path.parent.parent) != str(path.root):
|
elif str(path.parent) == str(path.root):
|
||||||
# 父目录非根目录,才删除父目录
|
# 根目录,不删除
|
||||||
files = SystemUtils.list_files(path.parent, settings.RMT_MEDIAEXT)
|
logger.warn(f"根目录 {path} 不能删除!")
|
||||||
if not files:
|
return
|
||||||
shutil.rmtree(path.parent)
|
|
||||||
logger.warn(f"目录 {path.parent} 已删除")
|
|
||||||
else:
|
else:
|
||||||
if str(path.parent) != str(path.root):
|
# 非根目录,才删除目录
|
||||||
# 父目录非根目录,才删除目录
|
shutil.rmtree(path)
|
||||||
shutil.rmtree(path)
|
# 删除目录
|
||||||
# 删除目录
|
logger.warn(f"目录 {path} 已删除")
|
||||||
logger.warn(f"目录 {path} 已删除")
|
# 需要删除父目录
|
||||||
|
# 判断父目录是否为空, 为空则删除
|
||||||
|
for parent_path in path.parents:
|
||||||
|
if str(parent_path.parent) != str(path.root):
|
||||||
|
# 父目录非根目录,才删除父目录
|
||||||
|
files = SystemUtils.list_files(parent_path, settings.RMT_MEDIAEXT)
|
||||||
|
if not files:
|
||||||
|
shutil.rmtree(parent_path)
|
||||||
|
logger.warn(f"目录 {parent_path} 已删除")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user