Skip to content

Commit 885d481

Browse files
committed
Add test for is_timestamped_name.
1 parent ac56230 commit 885d481

File tree

2 files changed

+52
-7
lines changed

2 files changed

+52
-7
lines changed

tiledb/sm/filesystem/test/unit_uri.cc

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,32 @@ TEST_CASE("URI: Test REST components, invalid", "[uri]") {
311311
}
312312
}
313313

314+
TEST_CASE("URI: Test is_timestamped_name", "[uri][is_timestamped_name]") {
315+
std::vector<std::pair<std::string, bool>> test_uris = {
316+
{"__1764100213547_1764100213550_035477e475b011ac8c2f01a13532ccad.vac",
317+
true},
318+
{"__1764100213547_1764100213550_035477e475b011ac8c2f01a13532ccad", true},
319+
{"__1_1_035477e475b011ac8c2f01a13532ccad", true},
320+
{"__1_1_035477e475b011ac8c2f01a13532ccad_22", true},
321+
{"__1_1_035477e475b011ac8c2f01a13532ccad_22.vac", true},
322+
{"__1_1_035477e475b011ac8c2f01a13532ccad_22.tmp", false},
323+
{"__1_1_035477e475b011ac8c2f01a13532ccad.tmp", false},
324+
{"__1_1_035477e475b011ac8c2f01a13532cca", false},
325+
{"___1_035477e475b011ac8c2f01a13532cca", false},
326+
{"_1_1_035477e475b011ac8c2f01a13532ccad", false},
327+
{"__1_1_035477e475b011ac8c2f01a13532ccad.", false},
328+
{"__1_1_035477e475b011a_c8c2f01a13532ccad.", false},
329+
{"", false},
330+
{"______", false},
331+
{"__1_2_3", false},
332+
};
333+
for (const auto& test : test_uris) {
334+
URI uri(test.first);
335+
CHECK(uri.is_timestamped_name() == test.second);
336+
INFO(test.first);
337+
}
338+
}
339+
314340
TEST_CASE("URI: Test get_fragment_name", "[uri][get_fragment_name]") {
315341
std::vector<std::pair<URI, std::optional<URI>>> cases = {
316342
{URI("a randomish string"), std::nullopt},

tiledb/sm/filesystem/uri.cc

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,21 +216,40 @@ bool URI::is_timestamped_name() const {
216216
return false;
217217
}
218218
}
219+
auto get_suffix = [](const std::string& p) -> std::string {
220+
size_t suffix_separator = p.find('.');
221+
if (suffix_separator == std::string::npos) {
222+
return "";
223+
}
224+
return p.substr(suffix_separator);
225+
};
219226

220227
// Separator between uuid[_v].
221228
size_t uuid_separator = part.find('_', t2_separator + 1);
222-
std::string uuid = part.substr(t2_separator + 1, uuid_separator);
229+
std::string uuid =
230+
part.substr(t2_separator + 1, uuid_separator - t2_separator - 1);
231+
std::string suffix;
232+
if (uuid_separator == std::string::npos) {
233+
// There is no version; Check the UUID for the final suffix.
234+
suffix = get_suffix(uuid);
235+
uuid = uuid.substr(0, uuid.size() - suffix.size());
236+
} else {
237+
std::string version = part.substr(uuid_separator + 1);
238+
// Check the version for the final suffix.
239+
suffix = get_suffix(version);
240+
version = version.substr(0, version.size() - suffix.size());
241+
if (version.size() > std::to_string(constants::format_version).size()) {
242+
return false;
243+
}
244+
}
245+
223246
// UUIDs generated for timestamped names are 32 characters long.
224247
if (uuid.size() != 32) {
225248
return false;
226249
}
227250

228-
// Version is optional and may not appear in files using a timestamped name.
229-
if (uuid_separator != std::string::npos) {
230-
std::string version = part.substr(uuid_separator + 1);
231-
if (version.size() > std::to_string(constants::format_version).size()) {
232-
return false;
233-
}
251+
if (!suffix.empty() && suffix != constants::vacuum_file_suffix) {
252+
return false;
234253
}
235254

236255
return true;

0 commit comments

Comments
 (0)