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

[SR-12900] NSURL(fileURLWithPath:) Platform Inconsistency #4386

Open
swift-ci opened this issue May 29, 2020 · 3 comments
Open

[SR-12900] NSURL(fileURLWithPath:) Platform Inconsistency #4386

swift-ci opened this issue May 29, 2020 · 3 comments

Comments

@swift-ci
Copy link
Contributor

Previous ID SR-12900
Radar None
Original Reporter ValentinDebon (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee None
Priority Medium

md5: b52a603e5db1e76f792e334b231fe6f5

Issue Description:

The creation of a relative path using NSURL(fileURLWithPath: ) gives inconsistent behavior between Linux and macOS platforms, running the following:

import Foundation
let nsurl = NSURL(fileURLWithPath: "../etc")
print(nsurl)
print(nsurl.standardized?.path)

under macOS, running it under "/Users" gives:

../etc/ -- file:///Users/
Optional("/Users/etc")

Whereas under Linux, running under "/home" gives:

../etc/ -- file:///home/
Optional("/etc")

The /home doesn't get prepended as the /Users was in macOS

The Swift -version outputs gives under macOS:

Apple Swift version 5.2.4 (swiftlang-1103.0.32.9 clang-1103.0.32.53)
Target: x86_64-apple-darwin19.5.0

And under Linux (which is the package available here: https://swift.org/builds/swift-5.2.4-release/ubuntu1604/swift-5.2.4-RELEASE/swift-5.2.4-RELEASE-ubuntu16.04.tar.gz):

Swift version 5.2.4 (swift-5.2.4-RELEASE)
Target: x86_64-unknown-linux-gnu
@spevans
Copy link
Collaborator

spevans commented May 29, 2020

I cant reproduce this on Ubuntu18.04:

$ pwd
/home
$ ~/swift-5.2.4-RELEASE-ubuntu18.04/usr/bin/swift sr-12900.swift 
../bin/ -- file:///home/
Optional("/bin")

Do you perhaps have a symlink between /bin and /usr/bin ?

$ ls -ld /bin /usr/bin
drwxr-xr-x 2 root root  4096 May 14 10:12 /bin
drwxr-xr-x 2 root root 65536 May 29 06:11 /usr/bin

@swift-ci
Copy link
Contributor Author

Comment by Valentin Debon (JIRA)

@spevans Indeed, you're right, I wasn't aware of NSURL symlink resolutions. But it doesn't change the fact that there is a behavior mismatch. The /home should be prepended to the "relative" part of the path the way /Users is in macOS Foundation's

nb: I editted the description to specify this mismatch

@spevans
Copy link
Collaborator

spevans commented May 29, 2020

If the test is extended:

import Foundation
let nsurl1 = NSURL(fileURLWithPath: "../etc")
print(nsurl1)
print(nsurl1.standardized?.path as Any)

let nsurl2 = NSURL(fileURLWithPath: "etc")
print(nsurl2)
print(nsurl2.standardized?.path as Any) 

Then macOS gives:

../etc/ -- file:///Users/
Optional("/Users/etc")
etc -- file:///Users/
Optional("/Users/etc") 

Linux:

../etc/ -- file:///home/
Optional("/etc")
etc -- file:///home/
Optional("/home/etc") 

So macOS gives the same output for 2 different inputs and I think it's wrong. In effect we are resolving /Users/../etc which ls shows:

$ ls -ld /Users/../etc /etc
lrwxr-xr-x@ 1 root  wheel  11 30 Nov  2018 /Users/../etc -> private/etc
lrwxr-xr-x@ 1 root  wheel  11 30 Nov  2018 /etc -> private/etc 

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants