func constructDirectoryContents()

in Sources/TSFCASFileTree/FileTreeImport.swift [1139:1169]


        func constructDirectoryContents(_ subpaths: [(LLBDataID, LLBDirectoryEntry)?], wireFormat: LLBCASFileTree.WireFormat) throws -> (refs: [LLBDataID], dirData: LLBByteBuffer, aggregateSize: UInt64) {
        var refs = [LLBDataID]()
        let dirData: LLBByteBuffer
        var aggregateSize: UInt64 = 0

        switch wireFormat {
        case .binary, .compressed:
            /// We don't employ compression for directory entries yet,
            /// so both .binary and .compression just use the
            /// NamedDirectoryEntries encoded using the Protobuf encoding.
            var dirEntries = LLBDirectoryEntries()
            dirEntries.entries = subpaths.compactMap { args in
                guard let (id, info) = args else { return nil }
                refs.append(id)
                let (partial, overflow) = aggregateSize.addingReportingOverflow(info.size)
                aggregateSize = partial
                // Ignore overflow for now, otherwise.
                assert(!overflow)
                return info
            }

            var dirNode = LLBFileInfo()
            dirNode.type = .directory
            dirNode.size = aggregateSize
            dirNode.compression = .none
            dirNode.inlineChildren = dirEntries
            dirData = try dirNode.toBytes()
        }

        return (refs, dirData, aggregateSize)
    }