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
Added support for recursively resolving symlinks #1566
Conversation
Used by URL.resolvingSymlinksInPath()
@swift-ci please test |
I have set a recursion limit of 50, but I would like to know what Darwin Foundation does to maintain both implementations aligned. |
This feels like it would need a test. |
Added tests |
@swift-ci please test |
@swift-ci please test |
Please, can somebody initiate the @swift-ci tests? |
@swift-ci please test |
TestFoundation/TestFileManager.swift
Outdated
do { | ||
|
||
// Initialization | ||
var baseURL = FileManager.default.temporaryDirectory.appendingPathComponent("test_resolvingSymlinksInPath") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we have some of our other tests here stick a UUID in the path, so that if something gets stuck around from a previous run it doesn't hose the next test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, good idea. Added!
@swift-ci please test |
@@ -1033,16 +1033,39 @@ open class FileManager : NSObject { | |||
NSUnimplemented() | |||
} | |||
|
|||
internal func _tryToResolveTrailingSymlinkInPath(_ path: String) -> String? { | |||
internal func _tryToResolveTrailingSymlinkInPath(_ path: String, recursionLevel: Int = 0, initialPath: String? = nil) -> String? { | |||
guard _pathIsSymbolicLink(path) else { | |||
return nil | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The call to _pathIsSymbolicLink()
can be removed as destinationOfSymbolicLink()
should fail anyway if the path is not a symbolic link (according to readlink(2)
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The function _pathIsSymbolicLink()
was already there so I decided not to touch it. It was introduced as is with the initial URL.resolvingSymlinksInPath()
implementation.
@parkera / @millenomi Why |
That seems like an oversight; we should have only the one. Generally, we want to keep these implementations closer to URL and related types. |
Is this functionality the same as provided by |
Opened Swift Bug Report: SR-7857 |
Used by URL.resolvingSymlinksInPath().
The current Swift Foundation implementation only tries to solve the first symlink while Darwin Foundation tries to solve recursively all the symlinks.