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

Add split_windows_volume_prefix() function and tests. #7

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

aznashwan
Copy link

WARN: this code may NOT run correctly on OTP because of this compiler bug: gleam-lang/gleam#2733

"HKLM:",
"SOFTWARE/Microsoft/Windows/CurrentVersion",
)),
#("//./Volume{b75e2c83-0000-0000-0000-602f00000000}/Test/Foo.txt", #(
Copy link
Author

Choose a reason for hiding this comment

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

I just wanna say I really personally find what gleam format did with these nested tuples a bit less readable that the original version...

Copy link
Owner

@lpil lpil left a comment

Choose a reason for hiding this comment

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

Thank you.

What's the motivation for this addition? I've not come across a function like this before- what are some scenarios in which I would use it?

@aznashwan
Copy link
Author

It's generally useful to be able to split the drive of a path you're dealing with on Windows for a variety of reasons like determining if it's a local drive, remote UNC path, registry hive path, etc..., or processing/reusing later if it's a UNC share (like extracting the hostname/IP from it).

Python's stdlib has one FWIW: https://docs.python.org/3/library/os.path.html#os.path.splitdrive

Even if you don't want to have this function be public, it's still useful as an internal function to be reused in split() and is_absolute() as seen in #5, as currently both of those do NOT work correctly on Windows.

Copy link
Owner

@lpil lpil left a comment

Choose a reason for hiding this comment

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

Makes sense! Thank you. I've left some notes inline

@aznashwan aznashwan force-pushed the windows-split-volume-prefix branch from 266b537 to d599b27 Compare April 1, 2024 20:38
@aznashwan
Copy link
Author

@lpil changes done, I've even squashed the commit into one (minus the version bump and changelog update which is still a separate commit)

Thanks for you patience, and please re-review at your leisure!

PS: considering it's important to test with both /, and \, there's about 90 individual tests now 🤣

This patch adds a new public function for splitting Windows paths
into its volume prefix and rest of the path.
@aznashwan aznashwan force-pushed the windows-split-volume-prefix branch from d599b27 to 248ed76 Compare April 4, 2024 15:30
@aznashwan
Copy link
Author

@lpil just pushed the latest iteration on it with the added edge case you suggested.

Note that after more consideration of split_windows_volume_prefix's integration into is_absolute() it became apparent to me that drive-relative paths (e.g. C:Users\Administrator, which is interpreted as C:\$CWD\Users\Administrator) will need some form of differentiation from drive-absolute paths (C:\Users\Administrator), so I have elected to make the change of having the separator between the drive and the rest of the path remain in included in the path.

This will allow the later update of is_absolute() to work correctly in both cases, whereas without the included separator it would have potentially been ambiguous.

Signed-off-by: Nashwan Azhari <aznashwan@icloud.com>
Signed-off-by: Nashwan Azhari <aznashwan@icloud.com>
@aznashwan
Copy link
Author

Hey there @lpil, glad to have some time for Gleaming again.

Following the Erlang pattern matching fix reaching GA in Gleam 1.2, I have went ahead an updated this PR, PTAL whenever you can! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants