mirror of
https://gitee.com/g1879/DrissionPage.git
synced 2024-12-10 04:00:23 +08:00
下载结束确保文件移动
This commit is contained in:
parent
6d552330cd
commit
cc3ff505cf
@ -203,7 +203,6 @@ class DownloadManager(object):
|
|||||||
|
|
||||||
def _onDownloadProgress(self, **kwargs):
|
def _onDownloadProgress(self, **kwargs):
|
||||||
"""下载状态变化时执行"""
|
"""下载状态变化时执行"""
|
||||||
# print(kwargs)
|
|
||||||
if kwargs['guid'] in self._missions:
|
if kwargs['guid'] in self._missions:
|
||||||
mission = self._missions[kwargs['guid']]
|
mission = self._missions[kwargs['guid']]
|
||||||
if kwargs['state'] == 'inProgress':
|
if kwargs['state'] == 'inProgress':
|
||||||
@ -219,7 +218,17 @@ class DownloadManager(object):
|
|||||||
mission.total_bytes = kwargs['totalBytes']
|
mission.total_bytes = kwargs['totalBytes']
|
||||||
form_path = f'{mission.save_path}{sep}{mission.id}'
|
form_path = f'{mission.save_path}{sep}{mission.id}'
|
||||||
to_path = str(get_usable_path(f'{mission.path}{sep}{mission.name}'))
|
to_path = str(get_usable_path(f'{mission.path}{sep}{mission.name}'))
|
||||||
|
not_moved = True
|
||||||
|
for _ in range(10):
|
||||||
|
try:
|
||||||
move(form_path, to_path)
|
move(form_path, to_path)
|
||||||
|
not_moved = False
|
||||||
|
break
|
||||||
|
except PermissionError:
|
||||||
|
sleep(.5)
|
||||||
|
if not_moved:
|
||||||
|
from shutil import copy
|
||||||
|
copy(form_path, to_path)
|
||||||
self.set_done(mission, 'completed', final_path=to_path)
|
self.set_done(mission, 'completed', final_path=to_path)
|
||||||
|
|
||||||
else: # 'canceled'
|
else: # 'canceled'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user