Open
Conversation
apolyakov
requested changes
Apr 3, 2026
| #include <type_traits> | ||
| #include <utility> | ||
|
|
||
| #include <sys/stat.h> |
Contributor
There was a problem hiding this comment.
System headers should be placed in a single block
|
|
||
| return k2::fstat(m_descriptor, std::addressof(stat_buf)).and_then([&stat_buf, this] noexcept -> std::expected<string, int32_t> { | ||
| if (!S_ISREG(stat_buf.st_mode)) { | ||
| kphp::log::warning("regular file expected"); |
Contributor
There was a problem hiding this comment.
The return type of your lambda already contains error type: int32_t. I think it's better to remove these warnings and return proper errno instead
| } | ||
|
|
||
| string file_content{static_cast<string::size_type>(size), false}; | ||
| return read({reinterpret_cast<std::byte*>(file_content.buffer()), file_content.size()}) |
Contributor
There was a problem hiding this comment.
- nit:
std::as_writable_bytescan be cleaner here - Isn't
mmapa better choice here?
| return std::unexpected{m_descriptor != k2::INVALID_PLATFORM_DESCRIPTOR ? k2::errno_efault : k2::errno_enodev}; | ||
| struct stat stat_buf {}; | ||
|
|
||
| return k2::fstat(m_descriptor, std::addressof(stat_buf)).and_then([&stat_buf, this] noexcept -> std::expected<string, int32_t> { |
Contributor
There was a problem hiding this comment.
What's the point of wrapping everything inside lambdas? I doubt it makes this code more readable
| inline Optional<array<string>> f$file(const string& name) noexcept { | ||
| struct stat stat_buf {}; | ||
|
|
||
| auto expected_file{kphp::fs::file::open(name.c_str(), "r")}; |
Contributor
There was a problem hiding this comment.
nit: let's add explicit std::string_view creation here so we can pass name.size() to avoid call to std::strlen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR implements
file::get_contentsmethod. Implementation was got fromfilekphp function.