-
Notifications
You must be signed in to change notification settings - Fork 23
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
New path handling module that uses Nim's type system, using Path instead of string #54
Comments
Here is just a suggestion: Start with the |
vanilla strings of folders, files, etc. spliced against the |
The "real" reason to use a path type instead of "just strings" is that it makes it somewhat easier to round-trip uint16_t paths (like on windows). The design options here are:
In any event, supporting this for the filesystem isn't needed for nim, if you have a narrow string we should just not touch it.
I think (2) and (4) are the best options, as for if it's literal string types or some path object I don't think it really matters, except that I think the obvious data representation is either an array of uint8 or an array of uint16 (little endian, always, except it doesn't really matter because only windows does wide paths and windows has never supported any big endian architecture, and probably never will (windows does not support big-endian mode on arm, or arm64, or even itanium). I think representing things as some array of path components is a crummy idea, just store offsets to where they are. Basically I think it matters much more that we can guide users down a path (heh) that never modifies their paths than it is that we use any particular fancy object-based API. Especially important is that if you read a directory and store the result somewhere, then later (without calling any APIs to modify the path) open that file to do operations on it that open call should both complete successfully (assuming nobody deleted that file out from under you) and open the same file the OS returned. You would think this would be easy but it's not, and on windows a huge quantity of software gets this wrong, try making a file with the name "U+D800" and running some common tools on it :). If you use such an API for security sensitive things it can even cause vulnerabilities, although, to be honest, it's really window's fault for not having an "openat" system call, despite NT supporting that construct. |
@Araq in https://github.com/nim-lang/Nim/issues/8268#issuecomment-405817765 suggested:
let me expand on this a bit with other ideas to open a discussion
example usage
related work
benefits
==
overloaded to be platform specific path comparisoncons
see arguments from Walter Bright here: https://forum.dlang.org/post/[email protected]
question
design decisions
type Path = distinct string
ortype Path = object ...
? the latter allows more efficient operations potentially$path
bepath.internal
orpath.canonical
?alias this
to have that; what about Nim?if it doesn't implicitly convert to string, a ton of code will break. => SUGGESTION: should implicitly convert
let path ="/tmp/foo.txt".Path
let path =r"C:\tmp\foo.txt".Path
links
Relevant: https://irclogs.nim-lang.org/06-09-2018.html#14:17:36
@mratsim
The text was updated successfully, but these errors were encountered: