restores Helder in all its glory
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
import Foundation
|
||||
|
||||
enum DirectoryListing {
|
||||
struct Entry {
|
||||
enum Kind { case file, directory }
|
||||
|
||||
let name: String
|
||||
let url: URL
|
||||
let kind: Kind
|
||||
}
|
||||
|
||||
/// Regular files and real folders of one folder in byte order of their names, dotfiles
|
||||
/// included. Symlinks are left out, as ripgrep without `--follow` leaves them out.
|
||||
static func entries(of directory: URL) -> [Entry] {
|
||||
let keys: [URLResourceKey] = [.isSymbolicLinkKey, .isRegularFileKey, .isDirectoryKey]
|
||||
guard let urls = try? FileManager.default.contentsOfDirectory(at: directory, includingPropertiesForKeys: keys) else {
|
||||
return []
|
||||
}
|
||||
return urls.compactMap { url -> Entry? in
|
||||
guard let values = try? url.resourceValues(forKeys: Set(keys)), values.isSymbolicLink != true else { return nil }
|
||||
if values.isDirectory == true { return Entry(name: url.lastPathComponent, url: url, kind: .directory) }
|
||||
if values.isRegularFile == true { return Entry(name: url.lastPathComponent, url: url, kind: .file) }
|
||||
return nil
|
||||
}
|
||||
.sorted { $0.name < $1.name }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user