Skip to content

File path support for Foundation #5094

Open
@cmcgee1024

Description

@cmcgee1024

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:

  • Foundation URI
    • It's a bit too general, which causes headaches
    • Code often need to take care to ensure that they check for file:/// URI's, and only construct this type
    • Certain functions aren't available for certain types of URI's
    • Getting the right kind of platform-specific absolute paths for platforms like Windows doesn't work well, encouraging extensions and unsafe calls to get them right
  • System FilePath
    • Tied to the current platform, which may or may not be POSIX
    • Difficult to code in a platform-neutral way (see the Errnos)
    • Issues around encoding
  • Foundation String
    • Some of the foundation API's in FileManager will accept arbitrary string paths
    • No API's for doing path arithmetic operations on the strings

On 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.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions