Skip to content
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

Closed
wants to merge 9 commits into from

Conversation

ghost
Copy link

@ghost ghost commented Aug 8, 2024

Deprecate path manipulations and use std::filesystem as this is introduced in C++17

In 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.

  • The PR has a description, explaining both the problem and the solution.
  • The description mentions which forms of testing were done and the testing seems reasonable.
  • Every function/class/actor that was touched is reasonably well documented.

For Release-Branches

If this PR is made against a release-branch, please also check the following:

  • This change/bugfix is a cherry-pick from the next younger branch (younger release-branch or main if this is the youngest branch)
  • There is a good reason why this PR needs to go into a release branch and this reason is documented (either in the description above or in a linked GitHub issue)

Copy link

@giorgiozoppi giorgiozoppi left a 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.

@ghost
Copy link
Author

ghost commented Aug 9, 2024

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.

@ghost
Copy link
Author

ghost commented Aug 12, 2024

do we have passing tests about this? I added mroe comments.

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.

@jzhou77 jzhou77 closed this Aug 12, 2024
@jzhou77 jzhou77 reopened this Aug 12, 2024
@foundationdb-ci
Copy link
Contributor

Result of foundationdb-pr-clang-arm on Linux CentOS 7

  • Commit ID: e723c46
  • Duration 0:03:47
  • Result: ❌ FAILED
  • Error: Error while executing command: if [[ $(git diff --shortstat 2> /dev/null | tail -n1) == "" ]]; then echo "CODE FORMAT CLEAN"; else echo "CODE FORMAT NOT CLEAN"; echo; echo "THE FOLLOWING FILES NEED TO BE FORMATTED"; echo; git ls-files -m; echo; exit 1; fi. Reason: exit status 1
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci
Copy link
Contributor

Result of foundationdb-pr on Linux CentOS 7

  • Commit ID: e723c46
  • Duration 0:04:16
  • Result: ❌ FAILED
  • Error: Error while executing command: if [[ $(git diff --shortstat 2> /dev/null | tail -n1) == "" ]]; then echo "CODE FORMAT CLEAN"; else echo "CODE FORMAT NOT CLEAN"; echo; echo "THE FOLLOWING FILES NEED TO BE FORMATTED"; echo; git ls-files -m; echo; exit 1; fi. Reason: exit status 1
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci
Copy link
Contributor

Result of foundationdb-pr-cluster-tests on Linux CentOS 7

  • Commit ID: e723c46
  • Duration 0:04:17
  • Result: ❌ FAILED
  • Error: Error while executing command: if [[ $(git diff --shortstat 2> /dev/null | tail -n1) == "" ]]; then echo "CODE FORMAT CLEAN"; else echo "CODE FORMAT NOT CLEAN"; echo; echo "THE FOLLOWING FILES NEED TO BE FORMATTED"; echo; git ls-files -m; echo; exit 1; fi. Reason: exit status 1
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)
  • Cluster Test Logs zip file of the test logs (available for 30 days)

@foundationdb-ci
Copy link
Contributor

Result of foundationdb-pr-clang on Linux CentOS 7

  • Commit ID: e723c46
  • Duration 0:04:16
  • Result: ❌ FAILED
  • Error: Error while executing command: if [[ $(git diff --shortstat 2> /dev/null | tail -n1) == "" ]]; then echo "CODE FORMAT CLEAN"; else echo "CODE FORMAT NOT CLEAN"; echo; echo "THE FOLLOWING FILES NEED TO BE FORMATTED"; echo; git ls-files -m; echo; exit 1; fi. Reason: exit status 1
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci
Copy link
Contributor

Result of foundationdb-pr-clang-ide on Linux CentOS 7

  • Commit ID: e723c46
  • Duration 0:04:20
  • Result: ❌ FAILED
  • Error: Error while executing command: if [[ $(git diff --shortstat 2> /dev/null | tail -n1) == "" ]]; then echo "CODE FORMAT CLEAN"; else echo "CODE FORMAT NOT CLEAN"; echo; echo "THE FOLLOWING FILES NEED TO BE FORMATTED"; echo; git ls-files -m; echo; exit 1; fi. Reason: exit status 1
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci
Copy link
Contributor

Result of foundationdb-pr-macos on macOS Ventura 13.x

  • Commit ID: e723c46
  • Duration 0:05:11
  • Result: ❌ FAILED
  • Error: Error while executing command: if [[ $(git diff --shortstat 2> /dev/null | tail -n1) == "" ]]; then echo "CODE FORMAT CLEAN"; else echo "CODE FORMAT NOT CLEAN"; echo; echo "THE FOLLOWING FILES NEED TO BE FORMATTED"; echo; git ls-files -m; echo; exit 1; fi. Reason: exit status 1
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci
Copy link
Contributor

Result of foundationdb-pr-macos-m1 on macOS Ventura 13.x

  • Commit ID: e723c46
  • Duration 0:05:52
  • Result: ❌ FAILED
  • Error: Error while executing command: if [[ $(git diff --shortstat 2> /dev/null | tail -n1) == "" ]]; then echo "CODE FORMAT CLEAN"; else echo "CODE FORMAT NOT CLEAN"; echo; echo "THE FOLLOWING FILES NEED TO BE FORMATTED"; echo; git ls-files -m; echo; exit 1; fi. Reason: exit status 1
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@ghost ghost force-pushed the patch-use-standard-filesystem-paths branch from e723c46 to c43012d Compare August 14, 2024 00:32
@@ -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 =

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.

Copy link
Author

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)) {

Choose a reason for hiding this comment

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

beautiful simplicity....great.

@@ -4104,53 +4097,53 @@ void platformSpecificDirectoryOpsTests(const std::string& cwd, int& errors) {
ASSERT(symlink("../backups/four", "simfdb/backups/five") == 0);

errors += testPathFunction2(
Copy link

@giorgiozoppi giorgiozoppi Aug 14, 2024

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.

Copy link
Author

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

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,

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.

@ghost
Copy link
Author

ghost commented Aug 15, 2024

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 Platform.h is referenced elsewhere. I'm also new to project so would appreciate any best practice suggestions / If the current approach is encouraged.

@xis19
Copy link
Collaborator

xis19 commented Aug 15, 2024

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 Platform.h is referenced elsewhere. I'm also new to project so would appreciate any best practice suggestions / If the current approach is encouraged.

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 clang-format on your code, fix the possible format issue, and let me trigger the CI pipeline to see what happens right now.

@xis19 xis19 closed this Aug 15, 2024
@xis19 xis19 reopened this Aug 15, 2024
@foundationdb-ci
Copy link
Contributor

Result of foundationdb-pr-clang-arm on Linux CentOS 7

  • Commit ID: b635a2a
  • Duration 0:04:39
  • Result: ❌ FAILED
  • Error: Error while executing command: ninja -v -C build_output -j ${NPROC} all packages strip_targets. Reason: exit status 1
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@ghost ghost force-pushed the patch-use-standard-filesystem-paths branch from 9640f6a to 6fda281 Compare August 19, 2024 17:40
@xis19 xis19 closed this Aug 19, 2024
@xis19 xis19 reopened this Aug 19, 2024
@foundationdb-ci
Copy link
Contributor

Result of foundationdb-pr-clang-arm on Linux CentOS 7

  • Commit ID: 6fda281
  • Duration 0:03:51
  • Result: ❌ FAILED
  • Error: Error while executing command: if [[ $(git diff --shortstat 2> /dev/null | tail -n1) == "" ]]; then echo "CODE FORMAT CLEAN"; else echo "CODE FORMAT NOT CLEAN"; echo; echo "THE FOLLOWING FILES NEED TO BE FORMATTED"; echo; git ls-files -m; echo; exit 1; fi. Reason: exit status 1
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci
Copy link
Contributor

Result of foundationdb-pr-clang-ide on Linux CentOS 7

  • Commit ID: 6fda281
  • Duration 0:04:47
  • Result: ❌ FAILED
  • Error: Error while executing command: if [[ $(git diff --shortstat 2> /dev/null | tail -n1) == "" ]]; then echo "CODE FORMAT CLEAN"; else echo "CODE FORMAT NOT CLEAN"; echo; echo "THE FOLLOWING FILES NEED TO BE FORMATTED"; echo; git ls-files -m; echo; exit 1; fi. Reason: exit status 1
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci
Copy link
Contributor

Result of foundationdb-pr on Linux CentOS 7

  • Commit ID: 6fda281
  • Duration 0:04:44
  • Result: ❌ FAILED
  • Error: Error while executing command: if [[ $(git diff --shortstat 2> /dev/null | tail -n1) == "" ]]; then echo "CODE FORMAT CLEAN"; else echo "CODE FORMAT NOT CLEAN"; echo; echo "THE FOLLOWING FILES NEED TO BE FORMATTED"; echo; git ls-files -m; echo; exit 1; fi. Reason: exit status 1
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci
Copy link
Contributor

Result of foundationdb-pr-cluster-tests on Linux CentOS 7

  • Commit ID: 6fda281
  • Duration 0:04:49
  • Result: ❌ FAILED
  • Error: Error while executing command: if [[ $(git diff --shortstat 2> /dev/null | tail -n1) == "" ]]; then echo "CODE FORMAT CLEAN"; else echo "CODE FORMAT NOT CLEAN"; echo; echo "THE FOLLOWING FILES NEED TO BE FORMATTED"; echo; git ls-files -m; echo; exit 1; fi. Reason: exit status 1
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)
  • Cluster Test Logs zip file of the test logs (available for 30 days)

@foundationdb-ci
Copy link
Contributor

Result of foundationdb-pr-clang on Linux CentOS 7

  • Commit ID: 6fda281
  • Duration 0:04:50
  • Result: ❌ FAILED
  • Error: Error while executing command: if [[ $(git diff --shortstat 2> /dev/null | tail -n1) == "" ]]; then echo "CODE FORMAT CLEAN"; else echo "CODE FORMAT NOT CLEAN"; echo; echo "THE FOLLOWING FILES NEED TO BE FORMATTED"; echo; git ls-files -m; echo; exit 1; fi. Reason: exit status 1
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci
Copy link
Contributor

Result of foundationdb-pr-macos on macOS Ventura 13.x

  • Commit ID: 6fda281
  • Duration 0:05:43
  • Result: ❌ FAILED
  • Error: Error while executing command: if [[ $(git diff --shortstat 2> /dev/null | tail -n1) == "" ]]; then echo "CODE FORMAT CLEAN"; else echo "CODE FORMAT NOT CLEAN"; echo; echo "THE FOLLOWING FILES NEED TO BE FORMATTED"; echo; git ls-files -m; echo; exit 1; fi. Reason: exit status 1
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci
Copy link
Contributor

Result of foundationdb-pr-macos-m1 on macOS Ventura 13.x

  • Commit ID: 6fda281
  • Duration 0:06:37
  • Result: ❌ FAILED
  • Error: Error while executing command: if [[ $(git diff --shortstat 2> /dev/null | tail -n1) == "" ]]; then echo "CODE FORMAT CLEAN"; else echo "CODE FORMAT NOT CLEAN"; echo; echo "THE FOLLOWING FILES NEED TO BE FORMATTED"; echo; git ls-files -m; echo; exit 1; fi. Reason: exit status 1
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@xis19
Copy link
Collaborator

xis19 commented Aug 19, 2024

Okay, it seems there are some compile errors. One of them is that you need to let TraceEvent system support std::filesystem::path. Perhaps I could give a patch for this.

FYI:

THE FOLLOWING FILES NEED TO BE FORMATTED

flow/include/flow/Traceable.h

@ghost
Copy link
Author

ghost commented Aug 20, 2024

Okay, it seems there are some compile errors. One of them is that you need to let TraceEvent system support std::filesystem::path. Perhaps I could give a patch for this.

FYI:

THE FOLLOWING FILES NEED TO BE FORMATTED

flow/include/flow/Traceable.h

Strange.. I ran clang-format locally and it doesn't seem to be complaining about it. Will take a closer look, thank you for this info!

Comment on lines 86 to 88
static std::string toString(type value) { \
return format(fmt, value); \
} \
Copy link
Collaborator

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?

Comment on lines 182 to 186
template <class Str>
static std::string toString(std::filesystem::path& value) {
return value.string();
}

Copy link
Collaborator

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.

Copy link
Author

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

Copy link
Author

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 :)

Copy link
Collaborator

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.

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.

Copy link
Collaborator

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>

@ghost ghost force-pushed the patch-use-standard-filesystem-paths branch from a291264 to f7c1a55 Compare August 21, 2024 01:13
@xis19 xis19 closed this Aug 22, 2024
@xis19 xis19 reopened this Aug 22, 2024
@foundationdb-ci
Copy link
Contributor

Result of foundationdb-pr-clang-arm on Linux CentOS 7

  • Commit ID: f7c1a55
  • Duration 0:03:37
  • Result: ❌ FAILED
  • Error: Error while executing command: if [[ $(git diff --shortstat 2> /dev/null | tail -n1) == "" ]]; then echo "CODE FORMAT CLEAN"; else echo "CODE FORMAT NOT CLEAN"; echo; echo "THE FOLLOWING FILES NEED TO BE FORMATTED"; echo; git ls-files -m; echo; exit 1; fi. Reason: exit status 1
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci
Copy link
Contributor

Result of foundationdb-pr-clang on Linux CentOS 7

  • Commit ID: f7c1a55
  • Duration 0:04:34
  • Result: ❌ FAILED
  • Error: Error while executing command: if [[ $(git diff --shortstat 2> /dev/null | tail -n1) == "" ]]; then echo "CODE FORMAT CLEAN"; else echo "CODE FORMAT NOT CLEAN"; echo; echo "THE FOLLOWING FILES NEED TO BE FORMATTED"; echo; git ls-files -m; echo; exit 1; fi. Reason: exit status 1
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci
Copy link
Contributor

Result of foundationdb-pr on Linux CentOS 7

  • Commit ID: f7c1a55
  • Duration 0:04:35
  • Result: ❌ FAILED
  • Error: Error while executing command: if [[ $(git diff --shortstat 2> /dev/null | tail -n1) == "" ]]; then echo "CODE FORMAT CLEAN"; else echo "CODE FORMAT NOT CLEAN"; echo; echo "THE FOLLOWING FILES NEED TO BE FORMATTED"; echo; git ls-files -m; echo; exit 1; fi. Reason: exit status 1
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci
Copy link
Contributor

Result of foundationdb-pr-clang-ide on Linux CentOS 7

  • Commit ID: f7c1a55
  • Duration 0:04:40
  • Result: ❌ FAILED
  • Error: Error while executing command: if [[ $(git diff --shortstat 2> /dev/null | tail -n1) == "" ]]; then echo "CODE FORMAT CLEAN"; else echo "CODE FORMAT NOT CLEAN"; echo; echo "THE FOLLOWING FILES NEED TO BE FORMATTED"; echo; git ls-files -m; echo; exit 1; fi. Reason: exit status 1
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci
Copy link
Contributor

Result of foundationdb-pr-cluster-tests on Linux CentOS 7

  • Commit ID: f7c1a55
  • Duration 0:04:46
  • Result: ❌ FAILED
  • Error: Error while executing command: if [[ $(git diff --shortstat 2> /dev/null | tail -n1) == "" ]]; then echo "CODE FORMAT CLEAN"; else echo "CODE FORMAT NOT CLEAN"; echo; echo "THE FOLLOWING FILES NEED TO BE FORMATTED"; echo; git ls-files -m; echo; exit 1; fi. Reason: exit status 1
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)
  • Cluster Test Logs zip file of the test logs (available for 30 days)

@foundationdb-ci
Copy link
Contributor

Result of foundationdb-pr-macos on macOS Ventura 13.x

  • Commit ID: f7c1a55
  • Duration 0:06:22
  • Result: ❌ FAILED
  • Error: Error while executing command: if [[ $(git diff --shortstat 2> /dev/null | tail -n1) == "" ]]; then echo "CODE FORMAT CLEAN"; else echo "CODE FORMAT NOT CLEAN"; echo; echo "THE FOLLOWING FILES NEED TO BE FORMATTED"; echo; git ls-files -m; echo; exit 1; fi. Reason: exit status 1
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@foundationdb-ci
Copy link
Contributor

Result of foundationdb-pr-macos-m1 on macOS Ventura 13.x

  • Commit ID: f7c1a55
  • Duration 0:06:22
  • Result: ❌ FAILED
  • Error: Error while executing command: if [[ $(git diff --shortstat 2> /dev/null | tail -n1) == "" ]]; then echo "CODE FORMAT CLEAN"; else echo "CODE FORMAT NOT CLEAN"; echo; echo "THE FOLLOWING FILES NEED TO BE FORMATTED"; echo; git ls-files -m; echo; exit 1; fi. Reason: exit status 1
  • Build Log terminal output (available for 30 days)
  • Build Workspace zip file of the working directory (available for 30 days)

@ghost ghost closed this by deleting the head repository Jan 4, 2025
This pull request was closed.
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