Skip to content
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

Trying to get a String representation of a file URL to use on a subprocess command line is frustrating. #5129

Open
dabrahams opened this issue Nov 1, 2024 · 2 comments
Assignees

Comments

@dabrahams
Copy link

I know of two options that seem likely to do the right thing across platforms:

extension URL {
  var fileSystemRepresentation: String {
     self.withUnsafeFileSystemRepresentation { String(cString: $0!) }
   }
}
import System
extension URL {
  var fileSystemRepresentation: String { FilePath(self)!.string }
}

It's unclear which, if either of these, actually does the right thing on a platform like Windows, where the .path property of a URL is not in native format. Both are far too indirect.

@compnerd
Copy link
Member

compnerd commented Nov 4, 2024

IMO the first one is the one to prefer. The second one is going to re-parse the path string, whereas the first one only will do the URL representation conversion.

@dabrahams
Copy link
Author

dabrahams commented Nov 5, 2024

Thanks Saleem. To be 100% clear for Foundation maintainers, Saleem's answer does not solve the issue I'm reporting, which is about a missing API and documentation. It's especially concerning that the correct answer today has to involve the word "unsafe".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants