System.IO.Abstractions icon indicating copy to clipboard operation
System.IO.Abstractions copied to clipboard

fix: GetDirectories returns relative paths if applicable

Open tuan-tu-tran opened this issue 3 years ago • 2 comments

This should fix #815

If the path orginally given is relative, we return relative paths as well. For instance in a folder structure like:

.
./foo
./foo/bar

where current directory is /foobar

Initially, the underlying method returns absolute paths i.e. calling GetFilesInternal("/foobar/foo") returns /foobar/foo/bar. We then compute the last component of the full path i.e. bar, which we combine with the path originally requested:

  • foo -> foo/bar
  • ./foo -> ./foo/bar
  • ../foobar/foo -> ../foobar/foo/bar

This works better than trying to get the absolute path relative to the current directory

Also, we add a new relevant test and adapt an existing incorrect test: It verifies that the returned paths are absolute, even though the path given is relative: MockDirectory_GetDirectories_RelativeDirectory_WithChildren_ShouldReturnChildDirectories(string relativeDirPath) That test was added by #258 for #169

tuan-tu-tran avatar Feb 24 '22 01:02 tuan-tu-tran

Sorry @tuan-tu-tran, I forgot about this PR. Will have a look by next week!

fgreinacher avatar Mar 11 '22 15:03 fgreinacher

Sure! No worries!

On Fri, 11 Mar 2022 at 16:58, Florian Greinacher @.***> wrote:

Sorry @tuan-tu-tran https://github.com/tuan-tu-tran, I forgot about this PR. Will have a look by next week!

— Reply to this email directly, view it on GitHub https://github.com/TestableIO/System.IO.Abstractions/pull/816#issuecomment-1065245085, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAQKIHD4MTCQOH6GQPNJOOTU7NUSNANCNFSM5PGAJL4Q . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

You are receiving this because you were mentioned.Message ID: @.***>

tuan-tu-tran avatar Mar 11 '22 19:03 tuan-tu-tran

https://github.com/TestableIO/System.IO.Abstractions/issues/815 has been resolved, so I assume we can close this. Feel free to reopen if needed.

fgreinacher avatar Jan 17 '24 14:01 fgreinacher