-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
File path support for Foundation #5094
Comments
FilePath from System is arguably very close to what's needed except it's in the wrong module, System, not Foundation where the platform neutral functions can live. As mentioned in the description there are some dependencies on POSIX Errnos that are throwable. Also, some Windows-specific issues with encodings / codable. Perhaps this can serve as the starting point for a common API? |
Thanks for the detailed bug report @cmcgee1024 |
This is what System's
See https://gist.github.com/milseman/294bd494d6911c65b80fccff5873b295, which includes rationale and can be an easier way to view the API in whole than browsing documentation.
We have the implementation machinery to support cross-platform paths, so it's just an API design question. I think it would be good to add explicit
A separate question is what kinds of API we should have for interacting with the file system, and what that would look like for a low-level platform-specific layer and a higher level platform-agnostic layer.
What are your issues? Interpreting the content of a file path can be file system specific. Windows paths are UCS2 and allows unpaired surrogates. Linux are bag-of-bytes, and Darwin is typically UTF-8 (often canonicalized in NFD) FilePath on Linux/Darwin is a nul-terminated bag of UInt8 and on Windows is a nul-termianted bag of UInt16. When converting to a String (e.g. for printing out), it will replace invalid encoded contents with That is,
We can talk about having |
IMO the ideal place for FilePath's (and Windows/Unix variants) syntactic operations would be the stdlib. It's within the stdlib's mandate and would make it the common API. (Also, no need for Foundation to re-export it and no need to pull in all of System just for it). |
I think this might be a reference to the Putative |
It's common for languages to have as part of their standard library a way to construct file path data structures that can then be used to perform certain queries (e.g. isAbsolute(). fileExt(), baseName(), dirName()) on them, and perform certain path arithmetic operations, such as appending paths and/or files to the end, or resolving relative paths against absolute ones. With some care an app writer can craft something that runs without much modification on a variety of platforms, including Linux, macOS, and Windows.
For example, Python has pathlib, Go has filepath, and Java has Path. Some of these take different stances on certain issues like being able to use paths from a platform other than the current host platform. But, for the most part these are the cornerstone of many libraries, and apps written in those languages. It also helps the standard app to be more platform independent, again, with some care from developers.
In the Swift world there are at least these independent file path API's that are available to developer:
file:///
URI's, and only construct this typeOn top of this, various Swift libraries and apps are writing their own Path structs, wrappers, and extensions to these different API's, which also perpetuates this even more because of mismatches between libraries. One uses Foundation URI, another uses FilePath, String, or some custom Path. A number of projects are hitting problems when trying to port things to Windows. Also, they are re-learning from some of the mistakes that a common API could shield them.
This enhancement would help to unify much of Swift under a single file path API for the benefit of everyone. Hopefully, porting efforts will become easier, same with integration.
The text was updated successfully, but these errors were encountered: