in Sources/TSFCASFileTree/Internal/FileTreeParser.swift [129:160]
func parseDirectory(id: LLBDataID, path: AbsolutePath, casObject: LLBCASObject) throws -> (LLBFilesystemObject, [AnnotatedCASTreeChunk]) {
let posixDetails: LLBPosixFileDetails?
let dirContents: [LLBDirectoryEntry]
let dirInfo = try LLBFileInfo.deserialize(from: casObject.data)
guard dirInfo.type == .directory else {
throw LLBCASFileTreeFormatError.formatError(reason: "\(id): object is not a directory")
}
guard case let .inlineChildren(children) = dirInfo.payload else {
throw LLBCASFileTreeFormatError.formatError(reason: "\(id): directory doesn't specify children")
}
dirContents = children.entries
posixDetails = LLBPosixFileDetails(from: dirInfo)
if casObject.refs.count < dirContents.count {
throw LLBCASFileTreeFormatError.unexpectedDirectoryData(id)
}
let fsObject = LLBFilesystemObject(path, .directory, posixDetails: posixDetails)
let others: [AnnotatedCASTreeChunk]
others = try zip(casObject.refs, dirContents).map { args in
let (id, info) = args
guard info.name != "" && info.name != "." && info.name != ".." && !info.name.contains("/") else {
throw LLBCASFileTreeFormatError.formatError(reason: "\(String(reflecting: info.name)): unexpected directory entry")
}
let kind = AnnotatedCASTreeChunk.ItemKind(type: info.type, posixDetails: LLBPosixFileDetails(from: info), overestimatedSize: info.size)
return AnnotatedCASTreeChunk(id, path.appending(component: info.name), kind: kind)
}
return (fsObject, others)
}