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

proposal: os: expose all possible path and pathlist separators #58678

Open
defaulterrr opened this issue Feb 24, 2023 · 1 comment
Open

proposal: os: expose all possible path and pathlist separators #58678

defaulterrr opened this issue Feb 24, 2023 · 1 comment
Labels
Milestone

Comments

@defaulterrr
Copy link

defaulterrr commented Feb 24, 2023

Description

As of right now, os (and by extension, filepath) package exports os.PathSeparator and os.PathListSeparator constants that are tied to the system the binary is built on (by //go:build constraints). So, for example, on unix systems, these would be / and :. The problem with this approach is that there is no way to reference a Windows separator from a unix-built binary, and vice versa. While this might be a rare occasion, sometimes there is a need for that (i.e. if some unix-style binary requires unix-style separators even when executed in Windows environment, or if you need to render a help docstring for the user).

Of course, you can always get around this and just declare your own separators but that just feels hacky when there is an exposed const in the standard package.

I'd be happy to submit a PR for this

Proposed changes

What i propose is adding new constants to the os package that would reference each style, and only typealiasing them in _<os>.go files. This will not break existing external API, only expose new constants (that are already present in the library, but just not exposed due to build constraints).

In os package:

// src/os/path_unix.go

const (
	PathSeparator     = UnixPathSeparator // OS-specific path separator
	PathListSeparator = UnixPathListSeparator // OS-specific path list separator
)
// src/os/path_windows.go

const (
	PathSeparator     = WindowsPathSeparator // OS-specific path separator
	PathListSeparator = WindowsPathListSeparator // OS-specific path list separator
)
// path.go

const (
	UnixPathSeparator     = '/' // unix-specific path separator
	UnixPathListSeparator = ':' // unix-specific path list separator
        WindowsPathSeparator     = '\\' // windows-specific path separator
	WindowsPathListSeparator = ';'  // windows-specific path list separator
)
@gopherbot gopherbot added this to the Proposal milestone Feb 24, 2023
@seankhliao seankhliao changed the title proposal: expose all possible path and pathlist separators in os package proposal: os: expose all possible path and pathlist separators Feb 24, 2023
@ianlancetaylor ianlancetaylor moved this to Incoming in Proposals Feb 24, 2023
@willfaught
Copy link
Contributor

It seems unusual to expose info about non-native platforms in the stdlib. Perhaps these should be in x/sys/{unix,windows} instead?

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

No branches or pull requests

3 participants