Log accessed files

This commit is contained in:
Christoph Hagen 2022-08-25 00:11:53 +02:00
parent 2e6542225f
commit 5b4db424b5
2 changed files with 28 additions and 1 deletions

View File

@ -27,6 +27,8 @@ final class FileAccess {
private var changedFiles: Set<String> = []
private var accessedFiles: Set<String> = []
init(in root: URL, errorOutput: ErrorOutput) {
self.sourceFolder = root
self.errorOutput = errorOutput
@ -63,6 +65,7 @@ final class FileAccess {
}
private func didAccess(inputPath: String, modified lastModified: Date, source: String) {
accessedFiles.insert(inputPath)
guard let previousDate = sourceLastModifiedTimes[inputPath] else {
// File not processed before, so mark as changed
changedFiles.insert(inputPath)
@ -143,4 +146,28 @@ final class FileAccess {
print(" ...")
}
}
func printAccessedFilesOverview() {
let count = accessedFiles.count
guard count > 0 else {
print("No files accessed")
return
}
print("\(count) files accessed:")
accessedFiles.prefix(10).forEach { print(" " + $0) }
if count > 10 {
print(" ...")
}
}
func printAllTouchedFiles() {
print("\(accessedFiles.count) files accessed:")
accessedFiles.sorted().forEach { file in
if changedFiles.contains(file) {
print(" \(file) (changed)")
} else {
print(" " + file)
}
}
}
}

View File

@ -17,7 +17,7 @@ do {
}
siteData.printTree()
context.fileSystem.printChangedFilesOverview()
context.fileSystem.printAllTouchedFiles()
context.fileSystem.didGenerateAllFiles()
exit(0)