Skip to content

Commit

Permalink
[docs] walk does not follow or resolve symlinks
Browse files Browse the repository at this point in the history
Added test to verify behavior
  • Loading branch information
mxcl committed Dec 3, 2015
1 parent 257fe0a commit 664763b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
6 changes: 2 additions & 4 deletions Sources/sys/walk.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ import libc
be empty. It is up to you to check `path` is valid before using this
function.

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

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

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

- Note: returning `false` from `recursing` still produces that directory
from the generator; just not its contents.
Expand Down
26 changes: 26 additions & 0 deletions Tests/sys/PathTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,32 @@ class WalkTests: XCTestCase {

XCTAssertEqual(expected.count, 0)
}

func testSymlinksNotWalked() {
do {
try mkdtemp("foo") { root in
let root = try realpath(root)

try mkdir(root, "foo")
try mkdir(root, "bar")
try mkdir(root, "bar/baz")
try mkdir(root, "bar/baz/goo")
try symlink(create: "\(root)/foo/symlink", pointingAt: "\(root)/bar", relativeTo: root)

XCTAssertTrue("\(root)/foo/symlink".isSymlink)
XCTAssertEqual(try! realpath("\(root)/foo/symlink"), "\(root)/bar")
XCTAssertTrue(try! realpath("\(root)/foo/symlink/baz").isDirectory)


let results = walk(root, "foo").map{$0}

XCTAssertEqual(results, ["\(root)/foo/symlink"])
}
} catch {
XCTFail("\(error)")
}
}

}

class StatTests: XCTestCase {
Expand Down

0 comments on commit 664763b

Please sign in to comment.