Implement QuicFileUtils#6375
Conversation
Signed-off-by: Dan Zhang <danzh@google.com>
Signed-off-by: Dan Zhang <danzh@google.com>
|
/assign @wu-bin |
bazel/external/quiche.BUILD
Outdated
| srcs = ["quiche/quic/platform/api/quic_mutex.cc"] + envoy_select_quiche( | ||
| ["quiche/quic/platform/api/quic_hostname_utils.cc"], | ||
| [ | ||
| "quiche/quic/platform/api/quic_hostname_utils.cc", |
There was a problem hiding this comment.
Here and below, please keep lists in BUILD file sorted alphabetically. quic_file_utils should appear before quic_hostname_utils.
bazel/external/quiche.BUILD
Outdated
| ] + envoy_select_quiche( | ||
| ["quiche/quic/platform/api/quic_hostname_utils.h"], | ||
| [ | ||
| "quiche/quic/platform/api/quic_hostname_utils.h", |
| srcs = ["quic_cert_utils_impl.cc"] + envoy_select_quiche([ | ||
| "quic_hostname_utils_impl.cc", | ||
| "quic_test_output_impl.cc", | ||
| "quic_file_utils_impl.cc", |
|
|
||
| namespace quic { | ||
|
|
||
| void DFTraverseDirectory(const std::string& dirname, std::vector<std::string>& files) { |
There was a problem hiding this comment.
Please move this function to anonymous namespace, since it is only used in this file.
The second parameter, "files", should be a pointer instead of a mutable reference. (Envoy uses Google's C++ style guide for the most part)
There was a problem hiding this comment.
Please move this function to anonymous namespace, since it is only used in this file.
done
The second parameter, "files", should be a pointer instead of a mutable reference. (Envoy uses Google's C++ style guide for the most part)
Envoy also prefers non-const reference if the pass-in argument is not supposed to be null.
| break; | ||
| case Envoy::Filesystem::FileType::Directory: | ||
| if (entry.name_ != "." && entry.name_ != "..") { | ||
| DFTraverseDirectory(absl::StrCat(dirname, "/", entry.name_), files); |
There was a problem hiding this comment.
Does it work if "dirname" already ends with '/'?
There was a problem hiding this comment.
Yes, but the file name returned also contains double "/". The only place used in quic gives path with no-trailing '/'. I added comment that it takes path without trailing '/'
There was a problem hiding this comment.
SG given how infrequent this is used. In general, I'd prefer ReadFileContentsImpl to remove the trailing '/' if needed.
| } | ||
| break; | ||
| default: | ||
| ASSERT(false, "Unknow file entry under directory " + dirname); |
There was a problem hiding this comment.
Include "entry.type_" in the error message?
| dir_path_ + "/file", dir_path_ + "/sub_dir1/sub_file1", | ||
| dir_path_ + "/sub_dir1/sub_dir1_1/sub_file1_1", dir_path_ + "/sub_dir2/sub_file2"}; | ||
| std::vector<std::string> files = ReadFileContents(dir_path_); | ||
| EXPECT_EQ(expected.size(), files.size()); |
There was a problem hiding this comment.
Line 505 to 508: You can use EXPECT_THAT(files, UnorderedElementsAre(expected))
Signed-off-by: Dan Zhang <danzh@google.com>
| break; | ||
| case Envoy::Filesystem::FileType::Directory: | ||
| if (entry.name_ != "." && entry.name_ != "..") { | ||
| DFTraverseDirectory(absl::StrCat(dirname, "/", entry.name_), files); |
There was a problem hiding this comment.
SG given how infrequent this is used. In general, I'd prefer ReadFileContentsImpl to remove the trailing '/' if needed.
|
/assign @alyssawilk |
alyssawilk
left a comment
There was a problem hiding this comment.
LGTM modulo one naming nit!
| namespace quic { | ||
| namespace { | ||
|
|
||
| void DFTraverseDirectory(const std::string& dirname, std::vector<std::string>& files) { |
There was a problem hiding this comment.
Naming? I'm not entirely sure what DF stands for here.
There was a problem hiding this comment.
Rename to depthFirstTraverseDirectory
| } // namespace | ||
|
|
||
| // Traverses the directory |dirname| and returns all of the files it contains. | ||
| std::vector<std::string> ReadFileContentsImpl(const std::string& dirname) { |
There was a problem hiding this comment.
Comment for "upstream", I think this is badly named as it's not reading the file contents.
I don't think you can fix that here though :-/
Signed-off-by: Dan Zhang <danzh@google.com>
Add QuicFileUtilsImpl using Envoy::FileSystem.
Risk Level: low
Testing: Added tests in test/extensions/quic_listeners/quiche/platform/quic_platform_test.cc and tested with --define quiche=enabled
Part of #2557