提交 5db4fbe3 编写于 作者: A Alexey Surkov 提交者: TensorFlower Gardener

Make GetMachingPaths also return directory names.

This is now consistent with what other file systems have.
Change: 137892031
上级 0b142e0d
......@@ -118,6 +118,26 @@ string JoinGcsPath(const string& path, const string& subpath) {
return strings::StrCat(MaybeAppendSlash(path), subpath);
}
/// \brief Returns the given paths appending all their subfolders.
///
/// For every path X in the list, every subfolder in X is added to the
/// resulting list.
/// For example:
/// - for 'a/b/c/d' it will append 'a', 'a/b' and 'a/b/c'
/// - for 'a/b/c/' it will append 'a', 'a/b' and 'a/b/c'
std::set<string> AddAllSubpaths(const std::vector<string>& paths) {
std::set<string> result;
result.insert(paths.begin(), paths.end());
for (const string& path : paths) {
StringPiece subpath = io::Dirname(path);
while (!subpath.empty()) {
result.emplace(subpath.ToString());
subpath = io::Dirname(subpath);
}
}
return result;
}
Status ParseJson(StringPiece json, Json::Value* result) {
Json::Reader reader;
if (!reader.parse(json.ToString(), *result)) {
......@@ -784,9 +804,11 @@ Status GcsFileSystem::GetMatchingPaths(const string& pattern,
GetChildrenBounded(dir, UINT64_MAX, &all_files, true /* recursively */,
false /* include_self_directory_marker */));
// Match all obtained files to the input pattern.
for (const auto& f : all_files) {
const string& full_path = io::JoinPath(dir, f);
const auto& files_and_folders = AddAllSubpaths(all_files);
// Match all obtained paths to the input pattern.
for (const auto& path : files_and_folders) {
const string& full_path = io::JoinPath(dir, path);
if (Env::Default()->MatchPath(full_path, pattern)) {
results->push_back(full_path);
}
......
......@@ -767,8 +767,9 @@ TEST(GcsFileSystemTest, GetMatchingPaths_BucketAndWildcard) {
std::vector<string> result;
TF_EXPECT_OK(fs.GetMatchingPaths("gs://bucket/*/*", &result));
EXPECT_EQ(std::vector<string>(
{"gs://bucket/path/file1.txt", "gs://bucket/path/file3.txt"}),
EXPECT_EQ(std::vector<string>({"gs://bucket/path/file1.txt",
"gs://bucket/path/file3.txt",
"gs://bucket/path/subpath"}),
result);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册