Skip to content

Commit

Permalink
fs: Fix GetZenFSChildrenNoLock to return relative children paths.
Browse files Browse the repository at this point in the history
When calling `GetZenFSchildrenNoLock` with `include_grandchildren == true`,
the reported grandchilden need to contain the complete relative path
from the given `dir` on.

Signed-off-by: Dennis Maisenbacher <[email protected]>
  • Loading branch information
MaisenbacherD authored and yhr committed Apr 12, 2022
1 parent 9761656 commit 4a199b0
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion fs/fs_zenfs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,11 @@ void ZenFS::GetZenFSChildrenNoLock(const std::string& dir,
std::string dir_with_terminating_seperator =
path_as_string_with_separator_at_end(std::filesystem::path(dir));

auto relative_child_path =
[&dir_with_terminating_seperator](std::string const& full_path) {
return full_path.substr(dir_with_terminating_seperator.length());
};

for (auto const& it : files_) {
std::filesystem::path file_path(it.first);
assert(file_path.has_filename());
Expand All @@ -662,7 +667,7 @@ void ZenFS::GetZenFSChildrenNoLock(const std::string& dir,
if (string_starts_with(file_dir, dir_with_terminating_seperator)) {
if (include_grandchildren ||
file_dir.length() == dir_with_terminating_seperator.length()) {
result->push_back(file_path.filename().string());
result->push_back(relative_child_path(file_path));
}
}
}
Expand Down

0 comments on commit 4a199b0

Please sign in to comment.