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:
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user