Skip to content

Conversation

@Arzaghi
Copy link
Contributor

@Arzaghi Arzaghi commented Oct 5, 2020

Fixes #232

I've tried to follow [fs.dir.entry.cons] of the Standard document. I think there were some test cases against the Standard definition in the tests, so I have modified them. Besides the original issue, I thought the functions under [fs.dir.entry.mods] need the same fix as well.

@Arzaghi Arzaghi marked this pull request as ready for review October 5, 2020 21:33
@Arzaghi Arzaghi requested a review from a team as a code owner October 5, 2020 21:33
@Arzaghi Arzaghi marked this pull request as draft October 6, 2020 05:47
@Arzaghi Arzaghi marked this pull request as ready for review October 6, 2020 05:48
@StephanTLavavej StephanTLavavej added the bug Something isn't working label Oct 6, 2020
@StephanTLavavej

This comment has been minimized.

@azure-pipelines

This comment has been minimized.

@StephanTLavavej

This comment has been minimized.

@Arzaghi

This comment has been minimized.

@StephanTLavavej

This comment has been minimized.

@cbezault cbezault closed this Oct 6, 2020
@cbezault cbezault reopened this Oct 6, 2020
@StephanTLavavej StephanTLavavej removed their assignment Dec 12, 2020
@Arzaghi
Copy link
Contributor Author

Arzaghi commented Dec 19, 2020

@StephanTLavavej

Specifically, it is strange that the non-error_code construction can succeed, while the error_code construction fails and produces a different state. The general behavior of should be that the exception interface and error_code interface behave identically, except for how they report errors.

I definitely agree with you. So, Because we have several tests here, here and here that expect constructing a directory_entry using nonexistent path not to fail. Then the error_code constructor should behave identically(i.e: set error code = 0)
All these tests mean constructors should not fail for nonexistent paths.

Then the standard document explicitly says [fs.dir.entry.cons]:

explicit directory_entry(const filesystem::path& p);
directory_entry(const filesystem::path& p, error_code& ec);

1 Effects: Calls refresh() or refresh(ec), respectively.
2 Postconditions: path() == p if no error occurs, otherwise path() == filesystem::path()

So we can deduce that both refresh() and refresh(ec) should not fail for nonexistent paths too. However, this test line was against the deduction. So I remove it!
My last commit applies the above deduction.

This behavior appears to be correct. However, both Clang and GCC implementations do not follow this deduction!
Also, this commit of my PR behaves as libc++.

Base automatically changed from master to main January 28, 2021 00:35
@StephanTLavavej

This comment was marked as resolved.

@StephanTLavavej StephanTLavavej added the filesystem C++17 filesystem label May 6, 2022
Copy link
Contributor

@strega-nil-ms strega-nil-ms left a comment

Choose a reason for hiding this comment

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

Other than those minor nits, I'm in favor of this change; the discussion in #232 implies to me that this is the correct way to go; having refresh() and directory_entry(const filesystem::path&) having different behavior is a bug.

The choice to make refresh() on a non-existent file succeed is, imo, the correct behavior, especially given that LLVM's libc++ makes exactly the same choice here:

  _LIBCPP_INLINE_VISIBILITY
  void __refresh(error_code* __ec = nullptr) {
    __handle_error("in directory_entry::refresh", __ec, __do_refresh(),
                   /*allow_dne*/ true);
  }

@BillyONeal
Copy link
Member

The choice to make refresh() on a non-existent file succeed is, imo, the correct behavior

That seems reasonable to me.

especially given that LLVM's libc++ makes exactly the same choice here:

FWIW I don't think "what libc++ does" is an arbiter of correct behavior. Not only is caching behavior intentionally not specified in the standard, what we cache is substantially different. The attributes they cache aren't different in character for existing files vs. nonexisting files which is not true for us.

=================================

Don't forget to consider the other effect this does: it makes directory_entry(const path&) fail for things that are not file-not-found, where previously it was non failing. (That is, after all, what #232 is talking about) You may want to specifically consider cases like broken symlinks or symlinks of the wrong directory-ness.

(I'm intentionally not making further statements on whether to take the change or not given that I'm no longer a maintainer and haven't been looking at this closely for a long time, only pointing out things to consider :) )

Arzaghi and others added 2 commits June 2, 2022 11:59
Co-authored-by: nicole mazzuca <83086508+strega-nil-ms@users.noreply.github.com>
@StephanTLavavej

This comment was marked as resolved.

@StephanTLavavej
Copy link
Member

After catching up on all of the discussion here and in #232, checking the Standard, and checking this PR's behavior, I believe that this change is correct and avoids regressing any previous fixes. I pushed a very small addition to the test coverage.

Apologies for my exceptionally long review delay here! I've moved this to Final Review so Nicole can check the commits after her previous review - then we should be able to merge this next week.

@strega-nil-ms strega-nil-ms removed their assignment Jun 17, 2022
@StephanTLavavej StephanTLavavej self-assigned this Jun 19, 2022
@StephanTLavavej
Copy link
Member

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej StephanTLavavej merged commit ca977f0 into microsoft:main Jun 19, 2022
@StephanTLavavej
Copy link
Member

Thanks again for investigating and fixing this bug in the C++17 filesystem library! 📂 🐞 😻

@Arzaghi Arzaghi deleted the Fix_Issue232 branch June 20, 2022 01:30
@e4lam
Copy link

e4lam commented Jun 22, 2022

Thank you all!

fsb4000 pushed a commit to fsb4000/STL that referenced this pull request Aug 13, 2022
…rn error code (microsoft#1343)

Co-authored-by: Stephan T. Lavavej <stl@microsoft.com>
Co-authored-by: nicole mazzuca <83086508+strega-nil-ms@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working filesystem C++17 filesystem

Projects

None yet

Development

Successfully merging this pull request may close these issues.

<filesystem>: directory_entry(const path& p, error_code& ec) does not return error code

8 participants