diff --git a/coscmd/cos_client.py b/coscmd/cos_client.py index 790b261..c995e34 100644 --- a/coscmd/cos_client.py +++ b/coscmd/cos_client.py @@ -498,6 +498,7 @@ def copy_folder(self, source_path, cos_path, _type='Standard'): _cos_path = cos_path + _tmp[len(source_path):] _cos_path = to_unicode(_cos_path) _source_path = to_unicode(_source_path) + if _cos_path.endswith('/'): continue _file_num += 1 @@ -527,7 +528,7 @@ def single_copy(): try: http_header = dict() http_header['x-cos-storage-class'] = self._type - http_header['x-cos-copy-source'] = source_path + http_header['x-cos-copy-source'] = to_printable_str(source_path) rt = self._session.put(url=url, auth=CosS3Auth(self._conf._secret_id, self._conf._secret_key), headers=http_header) if rt.status_code == 200: @@ -542,7 +543,8 @@ def single_copy(): continue if j+1 == self._retry: return False - except Exception: + except Exception,e: + logger.warn(e) logger.warn("copy file failed") return False @@ -584,7 +586,7 @@ def source_path_parser(): logger.warn("Source path format error") return source_bucket, source_appid, source_region, source_cospath - def copy_parts_data(local_path, offset, length, parts_size, idx): + def copy_parts_data(source_path, offset, length, parts_size, idx): url = self._conf.uri(path=cos_path)+"?partNumber={partnum}&uploadId={uploadid}".format(partnum=idx, uploadid=self._upload_id) http_header = dict() http_header['x-cos-copy-source'] = source_path @@ -790,7 +792,6 @@ def download_file(self, cos_path, local_path, _force=False): dir_path = os.path.dirname(local_path) if os.path.isdir(dir_path) is False and dir_path != '': try: - print dir_path os.makedirs(dir_path) except Exception as e: logger.warn("unable to create the corresponding folder") diff --git a/coscmd/test.py b/coscmd/test.py index 542f5da..97e95da 100644 --- a/coscmd/test.py +++ b/coscmd/test.py @@ -114,6 +114,19 @@ def test_objectacl(): op_int.put_object_acl("3210232098/327874225", "anyone", "", file_name) rt = op_int.get_object_acl(file_name) assert rt + +def test_copy(): + """test copy""" + if os.path.isdir('testfolder') is False: + os.mkdir('testfolder') + gen_file('testfolder/1中文', 1.1) + gen_file('testfolder/2中文', 2.1) + gen_file('testfolder/3中文', 3.1) + gen_file('testfolder/4中文', 4.1) + gen_file('testfolder/5中文', 5.1) + op_int.upload_folder('testfolder', 'testfolder') + op_int.copy_folder('lewzylu06-1252448703.cos.ap-beijing-1.myqcloud.com/testfolder', 'testfolder2') + shutil.rmtree('testfolder/') if __name__ == "__main__": tearDown()