Check for unused files in output folder
This commit is contained in:
@ -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 {
|
||||
|
@ -45,6 +45,8 @@ final class Storage: ObservableObject {
|
||||
|
||||
var errorNotification: StorageErrorCallback?
|
||||
|
||||
var writeNotification: ((String) -> Void)?
|
||||
|
||||
/**
|
||||
Create the storage.
|
||||
*/
|
||||
@ -319,6 +321,7 @@ final class Storage: ObservableObject {
|
||||
*/
|
||||
func copy(file fileId: String, to relativeOutputPath: String) -> Bool {
|
||||
guard let contentScope, let outputScope else { return false }
|
||||
didWrite(outputFile: relativeOutputPath)
|
||||
return contentScope.transfer(
|
||||
file: filePath(file: fileId),
|
||||
to: relativeOutputPath, of: outputScope)
|
||||
@ -460,6 +463,7 @@ final class Storage: ObservableObject {
|
||||
@discardableResult
|
||||
func write(_ content: String, to relativeOutputPath: String) -> Bool {
|
||||
guard let outputScope else { return false }
|
||||
didWrite(outputFile: relativeOutputPath)
|
||||
return outputScope.write(content, to: relativeOutputPath)
|
||||
}
|
||||
|
||||
@ -468,6 +472,7 @@ final class Storage: ObservableObject {
|
||||
*/
|
||||
func write(_ data: Data, to relativeOutputPath: String) -> Bool {
|
||||
guard let outputScope else { return false }
|
||||
didWrite(outputFile: relativeOutputPath)
|
||||
return outputScope.write(data, to: relativeOutputPath)
|
||||
}
|
||||
|
||||
@ -584,4 +589,15 @@ final class Storage: ObservableObject {
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// MARK: Output notifications
|
||||
|
||||
func didWrite(outputFile: String) {
|
||||
writeNotification?(outputFile)
|
||||
}
|
||||
|
||||
func getAllOutputFiles() -> Set<String> {
|
||||
guard let outputScope else { return [] }
|
||||
return outputScope.getAllFiles()
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user