@@ -72,42 +72,56 @@ bool isNotFoundError(Aws::S3::S3Errors error)
7272 || error == Aws::S3::S3Errors::NO_SUCH_BUCKET;
7373}
7474
75+ ObjectInfo getObjectInfoIfExists (
76+ const S3::Client & client,
77+ const String & bucket,
78+ const String & key,
79+ const String & version_id,
80+ bool with_metadata)
81+ {
82+ Expect404ResponseScope scope; // 404 is not an error
83+
84+ auto [object_info, error] = tryGetObjectInfo (client, bucket, key, version_id, with_metadata);
85+ if (object_info)
86+ return *object_info;
87+
88+ if (isNotFoundError (error.GetErrorType ()))
89+ return {};
90+
91+ throw S3Exception (
92+ error.GetErrorType (),
93+ " Failed to get object info: {}. HTTP response code: {}" ,
94+ error.GetMessage (),
95+ static_cast <size_t >(error.GetResponseCode ()));
96+ }
97+
7598ObjectInfo getObjectInfo (
7699 const S3::Client & client,
77100 const String & bucket,
78101 const String & key,
79102 const String & version_id,
80- bool with_metadata,
81- bool throw_on_error)
103+ bool with_metadata)
82104{
83- std::optional<Expect404ResponseScope> scope; // 404 is not an error
84- if (!throw_on_error)
85- scope.emplace ();
105+ Expect404ResponseScope scope; // 404 is not an error
86106
87107 auto [object_info, error] = tryGetObjectInfo (client, bucket, key, version_id, with_metadata);
88108 if (object_info)
89- {
90109 return *object_info;
91- }
92- if (throw_on_error)
93- {
94- throw S3Exception (
95- error.GetErrorType (),
96- " Failed to get object info: {}. HTTP response code: {}" ,
97- error.GetMessage (),
98- static_cast <size_t >(error.GetResponseCode ()));
99- }
100- return {};
110+
111+ throw S3Exception (
112+ error.GetErrorType (),
113+ " Failed to get object info: {}. HTTP response code: {}" ,
114+ error.GetMessage (),
115+ static_cast <size_t >(error.GetResponseCode ()));
101116}
102117
103118size_t getObjectSize (
104119 const S3::Client & client,
105120 const String & bucket,
106121 const String & key,
107- const String & version_id,
108- bool throw_on_error)
122+ const String & version_id)
109123{
110- return getObjectInfo (client, bucket, key, version_id, {}, throw_on_error ).size ;
124+ return getObjectInfo (client, bucket, key, version_id, /* with_metadata= */ false ).size ;
111125}
112126
113127bool objectExists (
0 commit comments