Skip to content

Commit d59f47d

Browse files
committed
fix copy
1 parent c0aa969 commit d59f47d

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

qcloud_cos/cos_client.py

+13-5
Original file line numberDiff line numberDiff line change
@@ -2340,7 +2340,10 @@ def _inner_head_object(self, CopySource):
23402340
auth=CosS3Auth(self._conf, path, params=params),
23412341
headers={},
23422342
params=params)
2343-
return int(rt.headers['Content-Length'])
2343+
storage_class = 'standard'
2344+
if 'x-cos-storage-class' in rt.headers:
2345+
storage_class = rt.headers['x-cos-storage-class'].lower()
2346+
return int(rt.headers['Content-Length']), storage_class
23442347

23452348
def _upload_part_copy(self, bucket, key, part_number, upload_id, copy_source, copy_source_range, md5_lst):
23462349
"""拷贝指定文件至分块上传,记录结果到lst中去
@@ -2389,13 +2392,18 @@ def copy(self, Bucket, Key, CopySource, CopyStatus='Copy', PartSize=10, MAXThrea
23892392
MAXThread=10
23902393
)
23912394
"""
2392-
# 同园区直接走copy_object
2393-
if self._check_same_region(self._conf._endpoint, CopySource) and 'StorageClass' not in kwargs:
2395+
# 先查询下拷贝源object的content-length
2396+
file_size, src_storage_class = self._inner_head_object(CopySource)
2397+
2398+
dst_storage_class = 'standard'
2399+
if 'StorageClass' in kwargs:
2400+
dst_storage_class = kwargs['StorageClass'].lower()
2401+
2402+
# 同园区且不改存储类型的情况下直接走copy_object
2403+
if self._check_same_region(self._conf._endpoint, CopySource) and src_storage_class == dst_storage_class:
23942404
response = self.copy_object(Bucket=Bucket, Key=Key, CopySource=CopySource, CopyStatus=CopyStatus, **kwargs)
23952405
return response
23962406

2397-
# 不同园区查询拷贝源object的content-length
2398-
file_size = self._inner_head_object(CopySource)
23992407
# 如果源文件大小小于5G,则直接调用copy_object接口
24002408
if file_size < SINGLE_UPLOAD_LENGTH:
24012409
response = self.copy_object(Bucket=Bucket, Key=Key, CopySource=CopySource, CopyStatus=CopyStatus, **kwargs)

0 commit comments

Comments
 (0)