Skip to content

Commit 664763b

Browse files
committed
[docs] walk does not follow or resolve symlinks
Added test to verify behavior
1 parent 257fe0a commit 664763b

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

Sources/sys/walk.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ import libc
2222
be empty. It is up to you to check `path` is valid before using this
2323
function.
2424

25-
- Warning: Symbolic links are *resolved*. Don’t expect to get the path of
26-
the link: you get the path of the file at which it points.
25+
- Warning: Symbolic links that point to directories are *not* followed.
2726

2827
- Note: setting recursively to `false` still causes the generator to feed
2928
you the directory; just not its contents.
@@ -44,8 +43,7 @@ public func walk(paths: String..., recursively: Bool = true) -> RecursibleDirect
4443
be empty. It is up to you to check `path` is valid before using this
4544
function.
4645

47-
- Warning: Symbolic links are *resolved*. Don’t expect to get the path of
48-
the link: you get the path of the file at which it points.
46+
- Warning: Symbolic links that point to directories are *not* followed.
4947

5048
- Note: returning `false` from `recursing` still produces that directory
5149
from the generator; just not its contents.

Tests/sys/PathTests.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,32 @@ class WalkTests: XCTestCase {
126126

127127
XCTAssertEqual(expected.count, 0)
128128
}
129+
130+
func testSymlinksNotWalked() {
131+
do {
132+
try mkdtemp("foo") { root in
133+
let root = try realpath(root)
134+
135+
try mkdir(root, "foo")
136+
try mkdir(root, "bar")
137+
try mkdir(root, "bar/baz")
138+
try mkdir(root, "bar/baz/goo")
139+
try symlink(create: "\(root)/foo/symlink", pointingAt: "\(root)/bar", relativeTo: root)
140+
141+
XCTAssertTrue("\(root)/foo/symlink".isSymlink)
142+
XCTAssertEqual(try! realpath("\(root)/foo/symlink"), "\(root)/bar")
143+
XCTAssertTrue(try! realpath("\(root)/foo/symlink/baz").isDirectory)
144+
145+
146+
let results = walk(root, "foo").map{$0}
147+
148+
XCTAssertEqual(results, ["\(root)/foo/symlink"])
149+
}
150+
} catch {
151+
XCTFail("\(error)")
152+
}
153+
}
154+
129155
}
130156

131157
class StatTests: XCTestCase {

0 commit comments

Comments
 (0)