Skip to content

fix: Directory.Move fails on Windows if destination has different case from source #1256

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

Conversation

oni-shiro
Copy link
Contributor

@oni-shiro oni-shiro commented Mar 24, 2025

This PR address the issue #1138:

On Windows, MockFileSystem.Directory.Move no longer throws a System.IO.IOException when source and destination path only differ in casing.

Copy link
Member

@vbreuss vbreuss left a comment

Choose a reason for hiding this comment

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

I don't understand why we would need this, as this method should only be a wrapper around the native Directory.Move. The idea of this library is to not change the behaviour of the underlying file system!

@oni-shiro
Copy link
Contributor Author

oni-shiro commented Mar 31, 2025

I added this check to handle this issue As it states, the wrapper class and the mock class differ in behaviour.
Another fix would be removing this checks from mock class instead of adding them in wrapper class. Let me know your thoughts.

@vbreuss
Copy link
Member

vbreuss commented Mar 31, 2025

@oni-shiro:
The goal of this library is to provide a wrapper and testing helper that behaves exactly the same as the native file system. The wrapper class should only wrap the native calls so that they can be tested.
When an issue describes a different behaviour between the native file system and the testing helpers, it is always the testing helpers that should be adapted.

I assigned #1138 to you.

@oni-shiro oni-shiro requested a review from vbreuss April 4, 2025 16:39
@oni-shiro oni-shiro force-pushed the fix/make-directory-move-throw-exception-if-file-is-moved-to-same-path branch from d6051d5 to f46f5d6 Compare April 4, 2025 16:42
Copy link
Member

@vbreuss vbreuss left a comment

Choose a reason for hiding this comment

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

Could you please add a test (see #1138) to verify the changed behavior?

@oni-shiro
Copy link
Contributor Author

Could you please add a test (see #1138) to verify the changed behavior?

Sure will do that.

@oni-shiro oni-shiro force-pushed the fix/make-directory-move-throw-exception-if-file-is-moved-to-same-path branch from f46f5d6 to bd19fcd Compare April 13, 2025 12:03
@oni-shiro
Copy link
Contributor Author

Added the test, removed two outdated tests that does not align with this change. @vbreuss

Copy link
Member

@vbreuss vbreuss left a comment

Choose a reason for hiding this comment

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

@oni-shiro I fear you misunderstood #1138. It mentions only the case that source and destination differ in casing and only on windows. You should not remove the existing test cases, as they verify the correct behavior in other cases that should not be changed.

@oni-shiro oni-shiro closed this Apr 15, 2025
@oni-shiro oni-shiro force-pushed the fix/make-directory-move-throw-exception-if-file-is-moved-to-same-path branch from d843e9d to 1778c08 Compare April 15, 2025 16:22
@oni-shiro oni-shiro reopened this Apr 15, 2025
@oni-shiro
Copy link
Contributor Author

Thank you @vbreuss for pointing my mistake 👍. I have made new changes, for this I had to add another StringOperation.Equals method that allows user to pass the String.Comparison behaviour. Currently when initializing the StringOperation we are passing the XFS.IsUnixPlatForm() as a flag to force the checks to be Ordinal or OrdinalIgnoreCase.
image
Thus I had to add another method that allows user to choose. I have updated the expected test cases alongside that also.

Let me know your thoughts.

@oni-shiro oni-shiro force-pushed the fix/make-directory-move-throw-exception-if-file-is-moved-to-same-path branch from 0863aad to b526929 Compare April 15, 2025 19:20
@vbreuss
Copy link
Member

vbreuss commented Apr 16, 2025

Let me know your thoughts.

I don't like this additional overload in the StringOperations, just use string.Equals(x, y, StringComparison) where needed (we should avoid bloating the public API surface).

@oni-shiro
Copy link
Contributor Author

Let me know your thoughts.

I don't like this additional overload in the StringOperations, just use string.Equals(x, y, StringComparison) where needed (we should avoid bloating the public API surface).

I was not keen on using Both StringOperations.Equals, and string.Equals simultaneously to avoid any confusion. But I understand your point, I will revert the change for that.

@oni-shiro
Copy link
Contributor Author

Reverted the public api related changes on 402f597

Copy link
Member

@vbreuss vbreuss left a comment

Choose a reason for hiding this comment

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

Thanks, @oni-shiro, I only have some minor suggestions.

@vbreuss vbreuss changed the title fix: Added the exception check in original code fix: Directory.Move fails on Windows if destination has different case from source Apr 18, 2025
Copy link
Member

@vbreuss vbreuss left a comment

Choose a reason for hiding this comment

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

I adjusted the title and description, as they were no longer up-to-date.

The PR looks good to me. Will release it shortly!

@vbreuss vbreuss merged commit 2c92589 into TestableIO:main Apr 18, 2025
9 checks passed
Copy link

This is addressed in release v22.0.14.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state: released Issues that are released
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MockFileSystem.Directory.Move fails on Windows if destination has different case from source
2 participants