-
Notifications
You must be signed in to change notification settings - Fork 265
Expand file tree
/
Copy pathDerivedDataManager.swift
More file actions
35 lines (27 loc) · 1.31 KB
/
DerivedDataManager.swift
File metadata and controls
35 lines (27 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//
// DerivedDataManager.swift
// BuildTimeAnalyzer
//
import Foundation
class DerivedDataManager {
static func derivedData() -> [File] {
let url = URL(fileURLWithPath: UserSettings.derivedDataLocation)
let folders: [URL] = DerivedDataManager.listFolders(at: url)
let fileManager: FileManager = FileManager.default
return folders.compactMap{ (url) -> File? in
if url.lastPathComponent != "ModuleCache",
let properties = try? fileManager.attributesOfItem(atPath: url.path),
let modificationDate = properties[FileAttributeKey.modificationDate] as? Date {
return File(date: modificationDate, url: url)
}
return nil
}.sorted{ $0.date > $1.date }
}
static func listFolders(at url: URL) -> [URL] {
let fileManager = FileManager.default
let keys = [URLResourceKey.nameKey, URLResourceKey.isDirectoryKey]
let options: FileManager.DirectoryEnumerationOptions = [.skipsHiddenFiles, .skipsPackageDescendants, .skipsSubdirectoryDescendants]
guard let enumerator = fileManager.enumerator(at: url, includingPropertiesForKeys: keys, options: options, errorHandler: nil) else { return [] }
return enumerator.map{ $0 as! URL }
}
}