-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
added os.nativeToUnixPath, os.absolutePrefix #13265
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
Conversation
b924c4a
to
07e38a3
Compare
PTAL |
07e38a3
to
c1c4e49
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see any tests for these new procedures, other than the examples.
I'm also unsure about the behavior of discarding the drive when converting from Windows to Posix. While this is the most popular interpretation, one could also keep the drive and use it as the first path segment (the way WSL and Cygwin translate paths).
Additionally, I don't really feel that these procedures have enough benefit to be included in the standard library. Hardly anyone uses classic MacOS anymore, and the Windows API accepts paths with both forward and backward slashes. In the case where a path variable differs between operating systems, I think I would prefer to just explicitly place the separate paths in when
blocks.
changelog.md
Outdated
@@ -1,4 +1,90 @@ | |||
# v1.4.0 - yyyy-mm-dd | |||
# 1.2 - xxxx-xx-xx |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the change log showing these changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's a consequence of merging #14098 without #14025; my plan was to merge #14025 first, then update #14098 accordingly, and merge it next. That would've prevented this, but unfortunately #14025 got closed.
I've fixed the changelog here, but this could/will happen to other old PR's (pre-1.2) that rebase against devel. We should really re-open #14025 (and address whatever comments need to be addressed) or at least for time being git move changelog.md changelogs/changelog_1_4.md
(but my PR was more careful about that and did other fixes)
c1c4e49
to
4d46d9b
Compare
indeed, there were only runnableExamples; i will add to tos.nim; and update references to
i'll change to
stdlib still has lots of bugs related to path handling on windows, see #13986 and in particular #13986 (comment) in fact this PR helps fixing #13986, as it allows extracting the drive and check whether the drive is the same when computing relativePath + friends
not everything in windows supports |
I'm not unsure ... it's disastrous. The idea of "unixToNative" and "nativeToUnix" (which are obviously misnamed) for absolute paths is misconceived, unless you do like cygwin and have a well-defined round-trip mapping. You could actually get away with nativeToUnixPath mapping from X:\foo to /cygdrive/x/foo and unixToNativePath mapping from /cygdrive/x/foo to X:\foo ... it would provide a round-trip mapping, would make cygwin users happy, and wouldn't hurt other users. If you don't like a mapping that uses a convention from an environment Nim doesn't even support, you could make it /windowsDrive/X/foo and cygwin users could mount (which is just a text mapping) /windowsDrive onto /cygdrive and again would be happy. (Even more happiness would come from unixToNativePath recognizing /cygdrive, /windowsDrive, and any other convention used by POSIX-on-Windows systems). Simply throwing away the drive name would make them and all other Windows users very unhappy.
absolutePrefix (not a good name; maybe getPathRoot) is useful and other path functions in the library can use it. Adding an API that maps Windows paths to "Unix" paths by throwing away the drive is a really bad idea.
Throwing away the drive would add another. Speaking of such bugs, the library generally thinks that Windows doesn't support symlinks, which is false and then some. (Just as one example, for users who installed Nim via scoop, the libraries live in scoop\apps\Nim\current, which is a symlink (actually a junction point, but they do the same thing) to scoop\apps\Nim<version number>). At the very least, expandFilename (what an awful name ... the compiler at least calls it canonicalizePath; why not just realPath, like the POSIX function?) on Windows should call getFinalPathNameByHandle, which is comparable to the POSIX realpath, rather than getFullPathName, which isn't. I understand why it uses the latter: because the former didn't exist when the code was written. So I suppose it should be conditionalized on the Windows version.
The API does. Apps have random restrictions because people (including those working at MS) don't read the docs before coding. (And the fact that DOS commandline apps use / as the switch indicator strongly works against / in path names.) Nim does better than most, but that's a low bar. |
Just want to add a link to this comment, as it outlines the current uses of nativeToUnixPath, and why they can (mostly) be replaced with some rewriting to be more robust, and only use unixToNativePath. |
4d46d9b
to
6830083
Compare
This pull request has been automatically marked as stale because it has not had recent activity. If you think it is still a valid PR, please rebase it on the latest devel; otherwise it will be closed. Thank you for your contributions. |
note: another sensible choice would've been firstPathPart (analog to lastPathPart), instead of absolutePrefix, which would also return 1st path component for relative paths, eg
doAssert firstPathPart("foo/bar") == "foo"