-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Use std::filesystem as standard #11564
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we have passing tests about this? I added mroe comments.
Thank you so much for your feedback! I'm reviewing it now. I don't think there's passing tests yet but will check as soon as I can. |
Sorry for late update, no passing tests and there are quite a few things that are failing / not building. Going to spend some time refactoring code to align with filesystem. |
Result of foundationdb-pr-clang-arm on Linux CentOS 7
|
Result of foundationdb-pr on Linux CentOS 7
|
Result of foundationdb-pr-cluster-tests on Linux CentOS 7
|
Result of foundationdb-pr-clang on Linux CentOS 7
|
Result of foundationdb-pr-clang-ide on Linux CentOS 7
|
Result of foundationdb-pr-macos on macOS Ventura 13.x
|
Result of foundationdb-pr-macos-m1 on macOS Ventura 13.x
|
e723c46
to
c43012d
Compare
@@ -2324,7 +2318,7 @@ void atomicReplace(std::filesystem::path const& path, std::string const& content | |||
INJECT_FAULT(io_error, "atomicReplace"); // atomic rename failed | |||
|
|||
std::string tempfilename = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which version is set, if we support C++20 upwards this is a good case for std::format. Since we're creating at least 2 tmp strings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe this is for C++17 but if maintainers can verify this that can be helpful, std::format
would be the better way to go about this
@@ -2648,7 +2641,7 @@ ACTOR Future<std::vector<std::string>> findFiles(std::string directory, | |||
} | |||
std::string name(dit->d_name); | |||
struct stat buf; | |||
if (stat(joinPath(directory, name).c_str(), &buf)) { | |||
if (stat(directory / name, &buf)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
beautiful simplicity....great.
flow/Platform.actor.cpp
Outdated
@@ -4104,53 +4097,53 @@ void platformSpecificDirectoryOpsTests(const std::string& cwd, int& errors) { | |||
ASSERT(symlink("../backups/four", "simfdb/backups/five") == 0); | |||
|
|||
errors += testPathFunction2( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is complex, same function with differente params, better put the params in an approriate data structure and iterate, doing append but it is out of scope for this pr.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, I think that this would be best. I was hoping to correct the std::filesystem
but there's still a lot to go through then go back to refactor this as a separate PR. Thank you for the heads up, I'll note this down for future PR to refactor this
flow/Platform.actor.cpp
Outdated
errors += testPathFunction2("abspath", abspath, "simfdb/backups/five/../three", true, true, platform_error()); | ||
errors += testPathFunction2( | ||
"abspath", abspath, "simfdb/backups/five/../three", true, false, joinPath(cwd, "simfdb/backups/one/three")); | ||
"abspath", abspath, "simfdb/backups/five/../three", true, false, cwd / "simfdb/backups/one/three"); | ||
errors += testPathFunction2("abspath", | ||
abspath, | ||
"simfdb/backups/five/../three/../four", | ||
true, | ||
false, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep. you just a vector of tuples. and you write the test before and iterate over the fectory and call testPath2Function and collect errors. But it is out of scope for this pr i guess.
Given complexity of this PR and refactor, not sure if it's a better idea to split this apart. If so, then I'm not sure how building it would be possible since most of |
Noting that your change are not triggering CI/CD (it is because you are not in the FDB team yet), I would suggest if you can do a |
Result of foundationdb-pr-clang-arm on Linux CentOS 7
|
9640f6a
to
6fda281
Compare
Result of foundationdb-pr-clang-arm on Linux CentOS 7
|
Result of foundationdb-pr-clang-ide on Linux CentOS 7
|
Result of foundationdb-pr on Linux CentOS 7
|
Result of foundationdb-pr-cluster-tests on Linux CentOS 7
|
Result of foundationdb-pr-clang on Linux CentOS 7
|
Result of foundationdb-pr-macos on macOS Ventura 13.x
|
Result of foundationdb-pr-macos-m1 on macOS Ventura 13.x
|
FYI:
|
Strange.. I ran |
flow/include/flow/Traceable.h
Outdated
static std::string toString(type value) { \ | ||
return format(fmt, value); \ | ||
} \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suspect these lines caused the formatting problem. Can you please revert?
flow/include/flow/Traceable.h
Outdated
template <class Str> | ||
static std::string toString(std::filesystem::path& value) { | ||
return value.string(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see you are trying to "overload" the toString
method. However, contrary to intuition, C++ function templates do not overload. So there is no reason you add the template
here. Herb Sutter has a very comprehensive explanation on this topic: http://www.gotw.ca/gotw/049.htm. Plus you are trying to capture value
using a non-const reference. This causes all r-value calls fail, e.g. toString(std::filesystem::path())
will not compile. Usually a better choice is to use const std::filesystem::path&
if std::filesystem::path::string()
is const-constrainted. The other choice is to use rvalue-reference, which could be more flexible, yet more subtle and difficult to understand (sorry I do not know your level of knowledge of C++, if you understand rvalue-reference please ignore what i said.) In this particular situation, I would suggest you implement the template struct TraceableString<std::system::path>
rather than this "overload". Another choice is to use
if constexpr (std::is_same<Str, std::filesystem::path>::value) {
return value.string()
} else {
// old code
}
but of course this is not recommended.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you so much for providing the in-depth explanation... This is super helpful! Let me add this change here and revert suggestion above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, had a few concerns; I think that this issue may be beyond my capabilities. I'd like to still work on it but this would take a considerably a lot more time for me. At this point I'm considering to go back on previous commits to test out smaller changes instead of what is here since it's a bit too much to trace what's breaking what.
Curious to hear your thoughts on this :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do whatever you want as you are not paid to work on this project.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I help if it is needed but at the end of week, what are your concern? Avoid complexity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I help if it is needed but at the end of week, what are your concern? Avoid complexity.
Remove this function and implement template specialization TraceableString<std::system::path>
a291264
to
f7c1a55
Compare
Result of foundationdb-pr-clang-arm on Linux CentOS 7
|
Result of foundationdb-pr-clang on Linux CentOS 7
|
Result of foundationdb-pr on Linux CentOS 7
|
Result of foundationdb-pr-clang-ide on Linux CentOS 7
|
Result of foundationdb-pr-cluster-tests on Linux CentOS 7
|
Result of foundationdb-pr-macos on macOS Ventura 13.x
|
Result of foundationdb-pr-macos-m1 on macOS Ventura 13.x
|
Deprecate path manipulations and use
std::filesystem
as this is introduced in C++17In reference: #11443
Code-Reviewer Section
The general pull request guidelines can be found here.
Please check each of the following things and check all boxes before accepting a PR.
For Release-Branches
If this PR is made against a release-branch, please also check the following:
release-branch
ormain
if this is the youngest branch)