diff --git a/aliyunpan/about.py b/aliyunpan/about.py index f2df444..80e22f7 100644 --- a/aliyunpan/about.py +++ b/aliyunpan/about.py @@ -1 +1 @@ -__version__ = '2.8.0' +__version__ = '2.8.1' diff --git a/aliyunpan/api/core.py b/aliyunpan/api/core.py index bc152d6..73cad9f 100644 --- a/aliyunpan/api/core.py +++ b/aliyunpan/api/core.py @@ -296,7 +296,8 @@ def create_file(self, file_name: str, parent_file_id: str = 'root', file_type: b return r def upload_file(self, parent_file_id: str = 'root', path: str = None, upload_timeout: float = 10, - retry_num: int = 3, force: bool = False, chunk_size: int = None, c: bool = False): + retry_num: int = 3, force: bool = False, chunk_size: int = None, c: bool = False, + ignore: bool = False): """ 上传文件 :param parent_file_id: 上传目录的id @@ -306,6 +307,7 @@ def upload_file(self, parent_file_id: str = 'root', path: str = None, upload_tim :param force: 强制覆盖 :param chunk_size: 分块大小 :param c: 断点续传 + :param ignore: 忽略上传失败的文件 :return: """ path = Path(path) @@ -313,7 +315,13 @@ def upload_file(self, parent_file_id: str = 'root', path: str = None, upload_tim file_name = path.name self._chunk_size = chunk_size or self._chunk_size # 获取sha1 - content_hash = get_sha1(path, self._chunk_size) + try: + content_hash = get_sha1(path, self._chunk_size) + except PermissionError: + if not ignore: + self._print.upload_info(path, status=False) + self._print.print_line() + return False while True: # 分片列表 part_info_list = [] @@ -497,9 +505,10 @@ def upload_file(self, parent_file_id: str = 'root', path: str = None, upload_tim try: file_info = self.complete(file_id, upload_id) except InvalidContentHash: - upload_bar.upload_info(path, status=False, refresh_line=True) - if get_real_path(log_file) != get_real_path(path): - raise + if not ignore: + upload_bar.upload_info(path, status=False, refresh_line=True) + if get_real_path(log_file) != get_real_path(path): + raise if file_info: upload_bar.upload_info(path, status=True, t=upload_bar.time, average_speed=upload_bar.average_speed, refresh_line=True) @@ -508,8 +517,9 @@ def upload_file(self, parent_file_id: str = 'root', path: str = None, upload_tim GLOBAL_VAR.file_set.add((content_hash, str(get_real_path(path)))) return file_info else: - upload_bar.upload_info(path, status=False, refresh_line=True) - self._print.print_line() + if not ignore: + upload_bar.upload_info(path, status=False, refresh_line=True) + self._print.print_line() return False def complete(self, file_id, upload_id): diff --git a/aliyunpan/cli/cli.py b/aliyunpan/cli/cli.py index adf24cc..4df4bf6 100644 --- a/aliyunpan/cli/cli.py +++ b/aliyunpan/cli/cli.py @@ -213,7 +213,7 @@ def mkdir(self, path, name=None, parent_file_id=None): return file_id_list def upload(self, path, upload_path='root', timeout=10.0, retry=3, force=False, share=False, chunk_size=None, - c=False): + c=False, ignore=False): if isinstance(path, (str, AliyunpanPath, Path)): path_list = (path,) else: @@ -264,7 +264,8 @@ def upload(self, path, upload_path='root', timeout=10.0, retry=3, force=False, s try: result = self._disk.upload_file( parent_file_id=parent_file_id, path=str(path), - upload_timeout=timeout, retry_num=retry, force=force, chunk_size=chunk_size, c=c) + upload_timeout=timeout, retry_num=retry, force=force, chunk_size=chunk_size, c=c, + ignore=ignore) except KeyboardInterrupt: self.__del__() raise @@ -287,7 +288,8 @@ def upload(self, path, upload_path='root', timeout=10.0, retry=3, force=False, s parent_file_id = self._path_list.get_path_fid(file[0], update=False) result = self._disk.upload_file( parent_file_id=parent_file_id, path=file[1], - upload_timeout=timeout, retry_num=retry, force=force, chunk_size=chunk_size, c=c) + upload_timeout=timeout, retry_num=retry, force=force, chunk_size=chunk_size, c=c, + ignore=ignore) except KeyboardInterrupt: self.__del__() raise @@ -549,11 +551,10 @@ def sync(self, path, upload_path, sync_time, time_out, chunk_size, retry, first= self._print.print_info( 'Do you really want to synchronize the root? This operation may delete all your files.', error=True) input('\nEnter to continue.') - first = False path = AliyunpanPath(path) relative_path = AliyunpanPath(path.name) if str(relative_path) == '.': - return self.sync(path.absolute(), upload_path, sync_time, time_out, chunk_size, retry, first=first) + return self.sync(path.absolute(), upload_path, sync_time, time_out, chunk_size, retry, first=False) upload_path = AliyunpanPath(upload_path) p = upload_path / relative_path self._path_list.update_path_list(p, is_fid=False) @@ -567,14 +568,17 @@ def sync(self, path, upload_path, sync_time, time_out, chunk_size, retry, first= 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) + if not self.upload(path_, upload_path / relative_path.parent, force=True, timeout=time_out, + chunk_size=chunk_size, retry=retry, ignore=True): + if first: + self._print.upload_info(path_, status=False) + self._print.print_line() else: self.rm(upload_path / relative_path) 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) + self.sync(path, upload_path, sync_time, time_out, chunk_size, retry, first=False) def share_link(self, path_list, file_id_list=None, expiration=None): t = '' if expiration is None else time.time() + expiration