Adds kind fixes deleting broken symlinks

`delete()` and other functions would check `exists` to do certain behaviors, but `exists` will validate a symlink if the entry is a symlink, thus instead we check if the path is an actual entry now instead.
This commit is contained in:
Max Howell
2019-03-18 09:09:06 -04:00
parent 7e774b6cf5
commit 0e061f9cc8
6 changed files with 97 additions and 27 deletions

View File

@@ -83,4 +83,22 @@ public extension Path {
#endif
return self
}
enum Kind {
case file, symlink, directory
}
var kind: Kind? {
var buf = stat()
guard lstat(string, &buf) == 0 else {
return nil
}
if buf.st_mode & S_IFMT == S_IFLNK {
return .symlink
} else if buf.st_mode & S_IFMT == S_IFDIR {
return .directory
} else {
return .file
}
}
}