Skip to content

Commit

Permalink
[Fix] #41
Browse files Browse the repository at this point in the history
  • Loading branch information
wxy1343 committed Aug 10, 2021
1 parent dee0f93 commit 11c1601
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 35 deletions.
2 changes: 1 addition & 1 deletion aliyunpan/about.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.7.5'
__version__ = '2.7.6'
36 changes: 36 additions & 0 deletions aliyunpan/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from treelib.exceptions import NodeIDAbsentError

from aliyunpan.api.type import FileInfo, ShareInfo
from aliyunpan.api.utils import get_sha1
from aliyunpan.common import GetFileListBar

_all_ = ['PathList', 'parse_share_url', 'AliyunpanPath']
Expand Down Expand Up @@ -35,6 +36,10 @@ def update_path_list(self, file_id='root', depth=None, is_fid=True, **kwargs):
if depth == max_depth:
get_file_list_bar.refresh_line()
return False
old_file_list = self._tree.children(file_id)
for i in old_file_list:
if i.identifier not in [j['file_id'] for j in file_list]:
self._tree.remove_node(i.identifier)
for i, info in enumerate(file_list):
if depth == max_depth:
ratio = (i + 1) / len(file_list) if file_list else None
Expand All @@ -51,6 +56,37 @@ def update_path_list(self, file_id='root', depth=None, is_fid=True, **kwargs):
get_file_list_bar.refresh_line()
return True

def check_path_diff(self, local_path, disk_path_list):
p = Path(local_path)
change_file_list = []
for path in p.iterdir():
flag = False
for i, path_ in enumerate(disk_path_list, 1):
name, file_info = list(path_.items())[0]
if p / name not in p.iterdir():
change_file_list.append(p / name)
if Path(path) == p / name:
if Path(path).is_dir() and file_info['data'] and path.is_dir() != file_info['data'].type:
if 'children' in file_info:
children = file_info['children']
change_file_list.extend(self.check_path_diff(p / name, children))
elif list(path.iterdir()):
change_file_list.extend(list(path.iterdir()))
if file_info and file_info['data'] and path.is_file() == file_info['data'].type:
if path.is_file() and get_sha1(path).lower() != file_info['data'].content_hash.lower():
continue
flag = True
if not flag and i == len(disk_path_list):
change_file_list.append(path)
if not len(list(p.iterdir())):
for path_ in disk_path_list:
name, file_info = list(path_.items())[0]
change_file_list.append(p / name)
if not len(disk_path_list):
for path_ in p.iterdir():
change_file_list.append(path_)
return list(set(change_file_list))

@staticmethod
def get_file_info(info):
file_info_list = []
Expand Down
35 changes: 1 addition & 34 deletions aliyunpan/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,52 +548,19 @@ def sync(self, path, upload_path, sync_time, time_out, chunk_size, retry, first=
self._path_list.update_path_list(p, is_fid=False)
file_id = self._path_list.get_path_fid(p, update=False)
path_ = self._path_list._tree.to_dict(file_id, with_data=True)[str(relative_path)]
change_file_list = self.check_path_diff(path, path_['children'] if 'children' in path_ else [])
self._print.refresh_line()
change_file_list = self._path_list.check_path_diff(path, path_['children'] if 'children' in path_ else [])
for path_ in change_file_list:
relative_path = path.name / (path - path_)
if path_.exists():
self.upload(path_, upload_path / relative_path.parent, force=True, timeout=time_out,
chunk_size=chunk_size, retry=retry)
else:
self.rm(upload_path / relative_path)
self._print.print_line()
if sync_time:
self._print.wait_info('等待{time}秒后再次同步', t=sync_time, refresh_line=True)
self._print.refresh_line()
self.sync(path, upload_path, sync_time, time_out, chunk_size, retry, first=first)

def check_path_diff(self, local_path, disk_path_list):
p = Path(local_path)
change_file_list = []
for path in p.iterdir():
flag = False
for i, path_ in enumerate(disk_path_list, 1):
name, file_info = list(path_.items())[0]
if p / name not in p.iterdir():
change_file_list.append(p / name)
if Path(path) == p / name:
if Path(path).is_dir() and file_info['data'] and path.is_dir() != file_info['data'].type:
if 'children' in file_info:
children = file_info['children']
change_file_list.extend(self.check_path_diff(p / name, children))
elif list(path.iterdir()):
change_file_list.extend(list(path.iterdir()))
if file_info and file_info['data'] and path.is_file() == file_info['data'].type:
if path.is_file() and get_sha1(path).lower() != file_info['data'].content_hash.lower():
continue
flag = True
if not flag and i == len(disk_path_list):
change_file_list.append(path)
if not len(list(p.iterdir())):
for path_ in disk_path_list:
name, file_info = list(path_.items())[0]
change_file_list.append(p / name)
if not len(disk_path_list):
for path_ in p.iterdir():
change_file_list.append(path_)
return list(set(change_file_list))

def share_link(self, path_list, file_id_list=None, expiration=None):
t = '' if expiration is None else time.time() + expiration
if not file_id_list:
Expand Down
7 changes: 7 additions & 0 deletions aliyunpan/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ def wait_info(self, title=None, t=3, refresh_line=False):

def upload_info(self, path, status=None, refresh_line=False, rapid_upload=False, t=None, average_speed=None, *args,
**kwargs):
self._output = True
t = self._time_info.format(t) if t else None
average_speed = self.avg_info.format(*str_of_size(average_speed, tuple_=True)) if average_speed else None
rapid_title = self._rapid_upload_title if rapid_upload else None
Expand All @@ -242,6 +243,7 @@ def upload_info(self, path, status=None, refresh_line=False, rapid_upload=False,
self.output = info

def download_info(self, path, status=None, refresh_line=False, t=None, average_speed=None, aria2=False, *args):
self._output = True
t = self._time_info.format(t) if t else None
aria2 = self._aria2_title if aria2 else aria2
average_speed = self.avg_info.format(*str_of_size(average_speed, tuple_=True)) if average_speed else None
Expand All @@ -250,22 +252,26 @@ def download_info(self, path, status=None, refresh_line=False, t=None, average_s
self.output = info

def mkdir_info(self, path, status=None, *args, **kwargs):
self._output = True
info = self.get_info(status, path, self._mkdir_title, *args, **kwargs)
info.color = self._mkdir_color or info.color
self.output = info

def move_info(self, path, target_path, status=None, *args, **kwargs):
self._output = True
info = self.get_info(status, path, self._move_title, *args, target_path=target_path, **kwargs)
info.color = self._move_color or info.color
self.output = info

def remove_info(self, path, status=None, *args, **kwargs):
self._output = True
info = self.get_info(status, path, self._remove_title, *args, **kwargs)
info.error = False
info.color = self._remove_color or info.color
self.output = info

def rename_info(self, path, name, status=None, *args, **kwargs):
self._output = True
info = self.get_info(status, path, self._rename_title, *args, target_path=name, **kwargs)
info.color = self._rename_color or info.color
self.output = info
Expand All @@ -284,6 +290,7 @@ def print_line(self):
self._print.print_line = True

def print_info(self, info, error=False, refresh_line=False, *args, **kwargs):
self._output = True
self.output = Info(info, error, refresh_line, *args, **kwargs)


Expand Down

0 comments on commit 11c1601

Please sign in to comment.