TestableIO / System.IO.Abstractions.Extensions

Convenience functionality on top of System.IO.Abstractions
MIT License
20 stars 6 forks source link

Portable path specification for MockFileSystem #24

Closed rcdailey closed 1 year ago

rcdailey commented 2 years ago

This is a continuation of https://github.com/TestableIO/System.IO.Abstractions/issues/855. It was requested that the discussion continue here since it's no longer a candidate for the core filesystem package.

Please visit the issue linked above for context, if interested. I spent a lot of time writing up my use case and justifying it there, and I prefer not to repeat it here. I apologize for the inconvenience.

At the end of that issue, the following was recommended:

fs.CurrentDirectory().SubDirectory("app").SubDirectory("data").File("recyclarr.yml")

I think this is getting closer to what I want, but it's not quite there. Even something as simple as making a shorthand like Dir for SubDirectory would greatly improve this. This is the kind of compactness I'm looking for, personally:

fs.AddFile("app/data/recyclarr.yml")

I expect the implementation of this to equal the example above. That is, process / verbatim on Linux and conver them to \ on Windows.

Similarly, for operations that require a rooted path, it should know to add CurrentDirectory() to the front if the provided string does not begin with / (linux) or C:\ (windows).

I realize I'm probably not going to get 100% of what I'm asking for. But I'm humble and opening up a discussion. Thank you for providing an opportunity to share my thoughts and make this request.

gigi81 commented 1 year ago

hi @rcdailey sorry it has been a while but I did not have an answer at the time for this request. the current api with the extension methods in this library allows to write something like this:

fs.CurrentDirectory().SubDirectory("app", "data").File("recyclarr.yml")

I know it is not as compact as what you requested but it is progress. I will keep this open if you or anyone else has any suggestion for further improvements. The AddFile as you suggested is a good idea but I'm not totally convinced about the directory separator char...

gigi81 commented 1 year ago

I will close this as there was no more activity in 3 weeks after my comment and also because I think we got very close to the initial request.

rcdailey commented 1 year ago

Sorry I didn't respond to this one... slipped past my radar. I think your solution is pretty good. My only thought (and it's a very small one) is to maybe use Dir as the name instead of SubDirectory. Little more concise. But I'm nit-picking at this point. Thank you for the help.