Skip to content

Commit

Permalink
Fix test (#125)
Browse files Browse the repository at this point in the history
* fix test

* fix copy
  • Loading branch information
lewzylu authored Apr 11, 2018
1 parent cc3fd1b commit 8a9bec6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
9 changes: 5 additions & 4 deletions coscmd/cos_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down
13 changes: 13 additions & 0 deletions coscmd/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 8a9bec6

Please sign in to comment.