Skip to content

Commit

Permalink
尽量删除已下载和解压后的文件
Browse files Browse the repository at this point in the history
  • Loading branch information
beikejinmiao committed Apr 8, 2023
1 parent 8e24152 commit 06462b1
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions modules/interaction/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from modules.interaction.extractor import TextExtractor
from modules.interaction.persistence import DbPersistence
from libs.web.url import urlsite
from utils.filedir import traverse
from libs.logger import logger

browser_protocols = ('http', 'https', 'ftp')
Expand Down Expand Up @@ -118,9 +119,21 @@ def clear():
os.remove(CRAWL_METRIC_PATH)
if os.path.exists(EXTRACT_METRIC_PATH):
os.remove(EXTRACT_METRIC_PATH)
# TODO 无法删除RAR压缩包解压后的文件
# 错误信息:
# [WinError 3] 系统找不到指定的路径。 # 文件确定存在,路径无空格和特殊字符,python3.5.4下判断不存在,python3.8.10判断存在!!
# [WinError 5] 拒绝访问。
if os.path.exists(DOWNLOADS):
shutil.rmtree(DOWNLOADS)
os.makedirs(DOWNLOADS)
try:
shutil.rmtree(DOWNLOADS)
except:
for filepath in traverse(DOWNLOADS):
try:
os.remove(filepath)
except Exception as e:
logger.error(e)
if not os.path.exists(DOWNLOADS):
os.makedirs(DOWNLOADS)
#
sqlite = Sqlite()
sqlite.truncate([TABLES.CrawlStat.value, TABLES.Extractor.value, TABLES.Sensitives.value])
Expand Down

0 comments on commit 06462b1

Please sign in to comment.