Check for unused files in output folder

This commit is contained in:
Christoph Hagen
2025-02-16 14:53:00 +01:00
parent 2cad27b504
commit 6b6db702f1
9 changed files with 95 additions and 7 deletions

View File

@ -388,6 +388,36 @@ struct SecurityBookmark {
return operation(url)
}
func getAllFiles() -> Set<String> {
guard url.startAccessingSecurityScopedResource() else {
reportError("Failed to start security scope")
return []
}
guard let enumerator = FileManager.default.enumerator(at: url, includingPropertiesForKeys: nil, options: [.skipsHiddenFiles]) else {
reportError("Failed to get folder enumerator")
return []
}
var relativePaths = Set<String>()
let prefix = url.path().withTrailingSlash
for case let fileURL as URL in enumerator {
guard !fileURL.hasDirectoryPath else {
continue
}
let fullPath = fileURL.path()
guard fullPath.hasPrefix(prefix) else {
print("Expected prefix \(prefix) for \(fullPath)")
return []
}
let relativePath = fullPath.replacingOccurrences(of: prefix, with: "")
relativePaths.insert(relativePath)
}
url.stopAccessingSecurityScopedResource()
return relativePaths
}
// MARK: Unscoped helpers
private func create(folder: URL) -> Bool {