@@ -52,6 +52,25 @@ def setup_logging(level=None):
52
52
53
53
_VALID_FILE_MODES = {"r" , "w" , "a" , "rb" , "wb" , "ab" }
54
54
55
+ _PRESERVE_KWARGS = [
56
+ "CacheControl" ,
57
+ "ContentDisposition" ,
58
+ "ContentEncoding" ,
59
+ "ContentLanguage" ,
60
+ "ContentLength" ,
61
+ "ContentType" ,
62
+ "Expires" ,
63
+ "WebsiteRedirectLocation" ,
64
+ "ServerSideEncryption" ,
65
+ "SSECustomerAlgorithm" ,
66
+ "SSEKMSKeyId" ,
67
+ "BucketKeyEnabled" ,
68
+ "StorageClass" ,
69
+ "ObjectLockMode" ,
70
+ "ObjectLockRetainUntilDate" ,
71
+ "ObjectLockLegalHoldStatus" ,
72
+ "Metadata" ,
73
+ ]
55
74
56
75
key_acls = {
57
76
"private" ,
@@ -1047,7 +1066,7 @@ async def _info(self, path, bucket=None, key=None, refresh=False, version_id=Non
1047
1066
"size" : out ["ContentLength" ],
1048
1067
"name" : "/" .join ([bucket , key ]),
1049
1068
"type" : "file" ,
1050
- "StorageClass" : " STANDARD" ,
1069
+ "StorageClass" : out . get ( "StorageClass" , " STANDARD") ,
1051
1070
"VersionId" : out .get ("VersionId" ),
1052
1071
"ContentType" : out .get ("ContentType" ),
1053
1072
}
@@ -1817,14 +1836,38 @@ def __init__(
1817
1836
self .append_block = False
1818
1837
1819
1838
if "a" in mode and s3 .exists (path ):
1820
- loc = s3 .info (path )["size" ]
1839
+ # See:
1840
+ # put: https://boto3.amazonaws.com/v1/documentation/api/latest
1841
+ # /reference/services/s3.html#S3.Client.put_object
1842
+ #
1843
+ # head: https://boto3.amazonaws.com/v1/documentation/api/latest
1844
+ # /reference/services/s3.html#S3.Client.head_object
1845
+ head = self ._call_s3 (
1846
+ "head_object" ,
1847
+ self .kwargs ,
1848
+ Bucket = bucket ,
1849
+ Key = key ,
1850
+ ** version_id_kw (version_id ),
1851
+ ** self .req_kw ,
1852
+ )
1853
+
1854
+ head = {
1855
+ key : value
1856
+ for key , value in head .items ()
1857
+ if key in _PRESERVE_KWARGS and key not in self .s3_additional_kwargs
1858
+ }
1859
+
1860
+ loc = head .pop ("ContentLength" )
1821
1861
if loc < 5 * 2 ** 20 :
1822
1862
# existing file too small for multi-upload: download
1823
1863
self .write (self .fs .cat (self .path ))
1824
1864
else :
1825
1865
self .append_block = True
1826
1866
self .loc = loc
1827
1867
1868
+ # Reflect head
1869
+ self .s3_additional_kwargs .update (head )
1870
+
1828
1871
if "r" in mode and "ETag" in self .details :
1829
1872
self .req_kw ["IfMatch" ] = self .details ["ETag" ]
1830
1873
0 commit comments