Skip to content

Implement QuicFileUtils#6375

Merged
alyssawilk merged 6 commits intoenvoyproxy:masterfrom
danzh2010:filesystem
Mar 27, 2019
Merged

Implement QuicFileUtils#6375
alyssawilk merged 6 commits intoenvoyproxy:masterfrom
danzh2010:filesystem

Conversation

@danzh2010
Copy link
Copy Markdown
Contributor

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

Signed-off-by: Dan Zhang <danzh@google.com>
Signed-off-by: Dan Zhang <danzh@google.com>
Signed-off-by: Dan Zhang <danzh@google.com>
@danzh2010
Copy link
Copy Markdown
Contributor Author

/assign @wu-bin

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",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here and below, please keep lists in BUILD file sorted alphabetically. quic_file_utils should appear before quic_hostname_utils.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

] + envoy_select_quiche(
["quiche/quic/platform/api/quic_hostname_utils.h"],
[
"quiche/quic/platform/api/quic_hostname_utils.h",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

srcs = ["quic_cert_utils_impl.cc"] + envoy_select_quiche([
"quic_hostname_utils_impl.cc",
"quic_test_output_impl.cc",
"quic_file_utils_impl.cc",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


namespace quic {

void DFTraverseDirectory(const std::string& dirname, std::vector<std::string>& files) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it work if "dirname" already ends with '/'?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 '/'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Include "entry.type_" in the error message?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

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());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line 505 to 508: You can use EXPECT_THAT(files, UnorderedElementsAre(expected))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point!

Signed-off-by: Dan Zhang <danzh@google.com>
wu-bin
wu-bin previously approved these changes Mar 26, 2019
Copy link
Copy Markdown
Contributor

@wu-bin wu-bin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

break;
case Envoy::Filesystem::FileType::Directory:
if (entry.name_ != "." && entry.name_ != "..") {
DFTraverseDirectory(absl::StrCat(dirname, "/", entry.name_), files);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SG given how infrequent this is used. In general, I'd prefer ReadFileContentsImpl to remove the trailing '/' if needed.

@danzh2010
Copy link
Copy Markdown
Contributor Author

/assign @alyssawilk

Copy link
Copy Markdown
Contributor

@alyssawilk alyssawilk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM modulo one naming nit!

namespace quic {
namespace {

void DFTraverseDirectory(const std::string& dirname, std::vector<std::string>& files) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naming? I'm not entirely sure what DF stands for here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
Signed-off-by: Dan Zhang <danzh@google.com>
@alyssawilk alyssawilk merged commit a450777 into envoyproxy:master Mar 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants