Skip to content

Commit 1fa595b

Browse files
author
Paweł Andruszkiewicz
committed
Fix OCI's manifest tests
Previously, it was not possible to create a file representation of a file which was missing in the manifest. With this change, this is now possible, error about non-existing file is delayed until the file is actually read. Change-Id: I6193bc3bd3e95898f1c97d574b9cf70fb1deb9d4 (cherry picked from commit 9978204ef84b99765b2355a26e37973ea3476a6b)
1 parent a829315 commit 1fa595b

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

modules/util/dump/dump_manifest.cc

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,20 @@ class Http_manifest_object : public mysqlshdk::storage::backend::Http_object {
225225
std::string m_full_name;
226226
};
227227

228+
mysqlshdk::Masked_string get_full_path(
229+
const std::shared_ptr<Manifest_reader> &reader,
230+
const Dump_manifest_read_config_ptr &config, const std::string &full_name) {
231+
return reader->has_object(full_name)
232+
? mysqlshdk::oci::anonymize_par(
233+
config->par().endpoint() +
234+
reader->get_object(full_name).name())
235+
: config->par().endpoint() + full_name;
236+
}
237+
228238
Http_manifest_object::Http_manifest_object(
229239
const std::shared_ptr<Manifest_reader> &reader,
230240
const Dump_manifest_read_config_ptr &config, const std::string &full_name)
231-
: Http_object(
232-
mysqlshdk::oci::anonymize_par(config->par().endpoint() +
233-
reader->get_object(full_name).name()),
234-
true),
241+
: Http_object(get_full_path(reader, config, full_name), true),
235242
m_reader(reader),
236243
m_config(config),
237244
m_full_name(full_name) {}
@@ -246,6 +253,13 @@ bool Http_manifest_object::exists() const {
246253
if (!exists && !m_reader->is_complete()) {
247254
m_reader->reload();
248255
exists = m_reader->has_object(m_full_name);
256+
257+
// exists() is called when opening the file, if this file didn't exist
258+
// before, we need to update its full path now
259+
if (exists) {
260+
const_cast<Http_manifest_object *>(this)->set_full_path(
261+
get_full_path(m_reader, m_config, m_full_name));
262+
}
249263
}
250264

251265
return exists;

mysqlshdk/libs/storage/backend/http.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,11 @@ std::optional<rest::Response_error> Http_object::fetch_file_size() const {
342342
return {};
343343
}
344344

345+
void Http_object::set_full_path(const Masked_string &full_path) {
346+
m_base = get_uri_base(full_path);
347+
m_path = get_uri_path(full_path);
348+
}
349+
345350
void Http_directory::init_rest(const Masked_string &url) { m_url = url; }
346351

347352
bool Http_directory::exists() const {

mysqlshdk/libs/storage/backend/http.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ class Http_object : public IFile {
117117

118118
std::optional<rest::Response_error> fetch_file_size() const;
119119

120+
void set_full_path(const Masked_string &full_path);
121+
120122
off64_t m_offset = 0;
121123
Masked_string m_base;
122124
std::string m_path;

unittest/modules/util/dump/dump_manifest_t.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,10 @@ TEST_F(Oci_os_tests, dump_manifest_read_mode) {
301301
"@.load.progress.json");
302302
const auto progress_file_uri =
303303
write_config->service_endpoint() + rw_par.access_uri;
304-
EXPECT_THROW_LIKE(read_manifest.file(progress_file_uri), shcore::Exception,
304+
const auto missing_file = read_manifest.file(progress_file_uri);
305+
EXPECT_FALSE(missing_file->exists());
306+
missing_file->open(mysqlshdk::storage::Mode::READ);
307+
EXPECT_THROW_LIKE(missing_file->read(buffer, 1), shcore::Exception,
305308
"Unknown object in manifest");
306309
}
307310

0 commit comments

Comments
 (0)