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

Refactor System.IO.Path #91

Merged
merged 12 commits into from
Nov 16, 2023
Merged

Refactor System.IO.Path #91

merged 12 commits into from
Nov 16, 2023

Conversation

CoryCharlton
Copy link
Member

Description

  • Bring code in line with .NET full implementation
  • Modernize code structure
  • Add unit test coverage
  • Optimize performance

Motivation and Context

The System.IO.FileSystem library hasn't got love in a while so this was another opportunity to clean up the code and confirm we are following the implementations in .NET full

How Has This Been Tested?

  • Unit tests
  • On device

Screenshots

Types of changes

  • Improvement (non-breaking change that improves a feature, code or algorithm)
  • Bug fix (non-breaking change which fixes an issue with code or algorithm)
  • New feature (non-breaking change which adds functionality to code)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Config and build (change in the configuration and build system, has no impact on code or features)
  • Dependencies (update dependencies and changes associated, has no impact on code or features)
  • Unit Tests (add new Unit Test(s) or improved existing one(s), has no impact on code or features)
  • Documentation (changes or updates in the documentation, has no impact on code or features)

Checklist:

  • My code follows the code style of this project (only if there are changes in source code).
  • My changes require an update to the documentation (there are changes that require the docs website to be updated).
  • I have updated the documentation accordingly (the changes require an update on the docs in this repo).
  • I have read the CONTRIBUTING document.
  • I have tested everything locally and all new and existing tests passed (only if there are changes in source code).
  • I have added new tests to cover my changes.

@nfbot nfbot added Type: Bug Something isn't working Type: enhancement New feature or request Type: Unit Tests labels Nov 10, 2023
Copy link
Member

@josesimoes josesimoes left a comment

Choose a reason for hiding this comment

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

Wow! That's a lot of improvements.
Wondering if we really need support for UNC paths... 🤔
I can't think of a use case in nano that can use it...

In order to keep libraries and firmware as small as possible, we heigth the cost/benefit/usage before adding new stuff. Just because we can, we don't rush into adding it.

Please don't get me wrong, I'm not picking on your work here.
That's why we hav on the contribution guideline the suggestion to first discuss changes and new code before actually start active work on it. In order to save time (and frustration) 😉

Open for discussion.

@CoryCharlton
Copy link
Member Author

CoryCharlton commented Nov 13, 2023

Wow! That's a lot of improvements. Wondering if we really need support for UNC paths... 🤔 I can't think of a use case in nano that can use it...

In order to keep libraries and firmware as small as possible, we heigth the cost/benefit/usage before adding new stuff. Just because we can, we don't rush into adding it.

Please don't get me wrong, I'm not picking on your work here. That's why we hav on the contribution guideline the suggestion to first discuss changes and new code before actually start active work on it. In order to save time (and frustration) 😉

Open for discussion.

Makes perfect sense and I actually questioned the UNC support while I was copying it over.

Speaking of copying it over the majority of this work came directly from the .NET Core implementation and so from that aspect it was easier for me to copy as is and trim stuff out from there. This allowed me to implement the unit tests in a .NET Core project, from a known set of behaviors, and confirm they ran the same in the nanoFramework implementation.

My motivation for starting down this Path (😉) was that the old implementation did not support the alternative directory separator ('/') so combining relative URLs with filesystem paths did not work like I expected. Then when I started digging into the code I saw room to remove unnecessary overhead (ex: checking for invalid filesystem characters which shouldn't be a concern of this class).

Happy to trim out things we don't need and will start with the UNC support.

@CoryCharlton
Copy link
Member Author

CoryCharlton commented Nov 14, 2023

I started looking at the UNC handling and it looks like the old code had, at least partial, support:

// Handles UNC names and directories off current drive's root.

bool rootedPath = false;

Additionally at first glance even though the new code is ~50 lines more (a poor metric I know) it appears to be much smaller (top is the latest NuGet and bottom is this branch build in release mode):

image

I'll investigate this a little further but it appears this gets things in line with the .NET Full behavior and doesn't add anything additional space wise.

@CoryCharlton
Copy link
Member Author

CoryCharlton commented Nov 14, 2023

Character wise (I know, not a real metric) if I remove comments the old implementation is 14,263 characters and the new one is 14,154 (manual removal so some margin of error ;)). Long story short the only thing added was correct handling of all expected cases and I think we're good to go unless I missed something.

PS: The SonarCloud bug is not actually a bug since our string doesn't implement GetEnumerator() I had to use ToCharArray(). I could switch to a for ... i I suppose.

@Ellerbach
Copy link
Member

PS: The SonarCloud bug is not actually a bug since our string doesn't implement GetEnumerator() I had to use ToCharArray(). I could switch to a for ... i I suppose

I marked it in Sonar, should be good for the next time you'll push anything

Copy link
Member

@Ellerbach Ellerbach left a comment

Choose a reason for hiding this comment

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

couple of comments and bonus point for the tests!

@josesimoes
Copy link
Member

@CoryCharlton not arguing that it wasn't there before. 😄 Rather if we need it.
If there is code, there is flash/RAM space taken. No matter if it's C# only, has native code backing it or not. 😉

@josesimoes
Copy link
Member

For the record: internal discussion started to gather thoughts on this UNC matter).

Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 3 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

Copy link
Member

@josesimoes josesimoes left a comment

Choose a reason for hiding this comment

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

LGTM! Thanks 👍🏻

@josesimoes josesimoes merged commit 7655369 into nanoframework:main Nov 16, 2023
@CoryCharlton CoryCharlton deleted the refactor_path branch November 16, 2023 02:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working Type: enhancement New feature or request Type: Unit Tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants