Skip to content

Commit 3a139d9

Browse files
committed
Merge pull request #267 from mxcl/fix-xfs
Fix `walk()` on XFS
2 parents f76978b + 036def4 commit 3a139d9

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

Sources/Utility/misc.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ public func rmtree(_ components: String...) throws {
3232
do {
3333
try POSIX.rmdir(dir)
3434
} catch .rmdir(let errno, _) as SystemError where errno == ENOENT {
35-
// Ignore ENOENT.
35+
// if the directory is not there then proceed
36+
// this could happen if it was in fact symlinked
37+
// from another part of the tree etc.
3638
}
3739
}
3840
try POSIX.rmdir(path)

Sources/Utility/walk.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import struct libc.dirent
1313
import func libc.readdir_r
1414
import func libc.closedir
1515
import func libc.opendir
16-
import var libc.DT_DIR
1716

1817

1918
/**
@@ -84,10 +83,10 @@ private class DirectoryContentsGenerator: IteratorProtocol {
8483
guard readdir_r(validdir, &entry, &result) == 0 else { continue }
8584
guard result != nil else { return nil }
8685

87-
switch (Int32(entry.d_type), entry.d_name.0, entry.d_name.1, entry.d_name.2) {
88-
case (Int32(DT_DIR), 46, 0, _): // "."
86+
switch (entry.d_name.0, entry.d_name.1, entry.d_name.2) {
87+
case (46, 0, _): // "."
8988
continue
90-
case (Int32(DT_DIR), 46, 46, 0): // ".."
89+
case (46, 46, 0): // ".."
9190
continue
9291
default:
9392
return entry
@@ -124,8 +123,9 @@ public class RecursibleDirectoryContentsGenerator: IteratorProtocol, Sequence {
124123
let name = withUnsafePointer(&dirName) { (ptr) -> String in
125124
return String(validatingUTF8: UnsafePointer<CChar>(ptr)) ?? ""
126125
}
127-
if Int32(entry.d_type) == Int32(DT_DIR) {
128-
towalk.append(Path.join(current.path, name))
126+
let path = Path.join(current.path, name)
127+
if path.isDirectory && !path.isSymlink {
128+
towalk.append(path)
129129
}
130130
return Path.join(current.path, name)
131131
}

0 commit comments

Comments
 (0)