func cacheLogs()

in Sources/XCMetricsClient/Log Management/LogManager.swift [128:156]


    func cacheLogs(_ xcodeLogs: Set<URL>, cachedLogs: Set<URL>, retries: Int) throws -> Set<URL> {
        var logsToBeCopied = Array(computeLogsToBeCopied(xcodeLogs: xcodeLogs, cachedLogs: cachedLogs))

        var copiedLogs: [URL] = []
        var attemptsLeft = retries + 1
        while attemptsLeft > 0 && !logsToBeCopied.isEmpty {
            logsToBeCopied = try logsToBeCopied.filter { logURL in
                let logsDirectoryURL = try retrieveOrCreateCachedLogsURL()
                let newLocation = logsDirectoryURL.appendingPathComponent(logURL.lastPathComponent)
                do {
                    try logCopier.copyLog(from: logURL, to: newLocation)
                } catch LogCopierError.invalidLog {
                    log("Couldn't copy log because it is invalid")
                    return true
                }
                log("Cached log to location: \(newLocation.path)")
                copiedLogs.append(newLocation)
                return false
            }
            attemptsLeft -= 1
            if logsToBeCopied.isEmpty || attemptsLeft <= 0 {
                break
            }
            // For big log files, Xcode will take a while to finish writing the log to the file.
            // This is a best-effort logic to try `retries` times and wait up until all logs to copy are valid logs.
            _ = sleepFunction(1)
        }
        return Set(copiedLogs)
    }