API Request: Splitting `POSIXPath` and `WindowsPath` out of `FilePath`
- Dominant language
- Swift
- Stars
- 1.4k
- Forks
- 154
- PR merge metrics
- No merged PRs in 30d
Description
`FilePath` is good, but we sometimes need to process POSIX paths or Windows paths specifically, regardless of the current platform. eg. when we create our own file system, we may want it to stick to POSIX paths for various reasons: cross-platform consistency, simplicity, tool compatibility, etc.
The biggest problem appears to be, `FilePath` is implemented as a whole and the Windows and POSIX parts of implementation are highly coupled. Here is the ideal layout:
```swift
/// Unify `FilePath` APIs
public protocol FilePathProtocol { … }
/// Default implementation
extension FilePathProtocol { … }
/// POSIX path struct
public struct POSIXPath: FilePathProtocol { … }
/// Windows path struct
public struct WindowsPath: FilePathProtocol { … }
/// The current `FilePath`
#if os(Windows)
public typealias FilePath = WindowsPath
#else
public typealias FilePath = POSIXPath
#endif
```
However, these two new types do need to rely on the same set of `Root` and `Component`, then we may also need:
```swift
public protocol FilePathRootProtocol { … }
public extension FilePathRootProtocol { … }
public extension POSIXPath {
public struct Root: FilePathRootProtocol { … }
}
public extension WindowsPath {
public struct Root: FilePathRootProtocol { … }
}
public protocol FilePathComponentProtocol { … }
public extension FilePathComponentProtocol { … }
public extension POSIXPath {
public struct Component: FilePathComponentProtocol { … }
}
public extension WindowsPath {
public struct Component: FilePathComponentProtocol { … }
}
public protocol FilePathProtocol {
associatedtype Root: FilePathRootProtocol
associatedtype Component: FilePathComponentProtocol
}
```
I’d like to collect some feedback for this change & ideas on how to implement this in the correct way.
Contributor guide
Research direction
No source file or test entry point is named. Start by locating the current FilePath implementation and its platform-specific code, then determine the scope of the proposed protocols and POSIXPath/WindowsPath types; done would require an agreed design and corresponding implementation plan.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- operating-systems
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100