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 path separator constants and utility function. #6

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

Conversation

aznashwan
Copy link

Includes separate commit with minor docstring formatting changes

Define constants for `path_separator_{unix,windows}` and add
`path_separator()` utility function getting the right one
for the platform currently being run on.
@aznashwan aznashwan force-pushed the add-path-separator branch from 1c590a6 to 3cc0bf0 Compare April 1, 2024 17:26
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.

Hello! What's the motivator for this change? Thank you.

@aznashwan
Copy link
Author

It's useful for people who find themselves needing to join paths for a different system (e.g. if you're on Unix and want to compose a Windows UNC share path to send to a remote Windows system).

It's also useful to know what path separator the current system you're running on is using if you need to manipulate paths directly.

Go has one FWIW: https://pkg.go.dev/path/filepath#pkg-constants
Go's is also defined separately on Windows and Unix systems.

@lpil
Copy link
Owner

lpil commented Apr 1, 2024

In Gleam we don't like to have multiple ways to do the same thing. Given we have functions for both splitting and joining paths wouldn't this be duplication?

@aznashwan
Copy link
Author

There is currently no way to join a Windows path with this package without relying on something else transparently translating the slashes into backslashes for you (which most Windows syscalls fortunately transparenty do, but it's better to be safe than sorry).

This package should at the very least be changed so that:

  • it exposes separate join_windows() and join_unix() functions
  • join() is switched to using the correct version of the above (currently, it only ever joins with slashes)

Both of the above points were beyond the scope of my original patch (#5) and I intended on adding them later with the help of these constants/function, but I got side-tracked with the issues with split() and is_absolute() on Windows and here we are...

I can make these separator constants/function private and convert this PR to include the above changes if you wish.

@lpil
Copy link
Owner

lpil commented Apr 3, 2024

Duplicate APIs are not an option so it sounds like the solution is to make the join function use \ on Windows.

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