Don't recurse into directories that start with '.' when listing resources

This commit is contained in:
Greg Neagle
2024-11-29 10:53:01 -08:00
parent dcc3259c35
commit ceaf504413

View File

@@ -197,14 +197,22 @@ class FileRepo: Repo {
var fileList = [String]()
let searchPath = (root as NSString).appendingPathComponent(kind)
let filemanager = FileManager.default
let dirEnum = filemanager.enumerator(atPath: searchPath)
while let file = dirEnum?.nextObject() as? String {
guard let dirEnum = filemanager.enumerator(atPath: searchPath) else {
return [String]()
}
while let file = dirEnum.nextObject() as? String {
let fullpath = (searchPath as NSString).appendingPathComponent(file)
let basename = (file as NSString).lastPathComponent
if !pathIsDirectory(fullpath) {
let basename = (file as NSString).lastPathComponent
if !basename.hasPrefix(".") {
fileList.append(file)
}
} else {
// path is directory
if basename.hasPrefix(".") {
// skip this directory
dirEnum.skipDescendants()
}
}
}
return fileList