Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Sources/XCDocsBridge/DocumentationAssetLocator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package struct DocumentationAssetLocator {
let contents = try assetRootContents()

let candidates = try contents.filter { $0.pathExtension == "asset" }.filter { try hasReadableIndex(at: $0) }
.sorted { lhs, rhs in modificationDate(for: lhs) > modificationDate(for: rhs) }
.sorted { lhs, rhs in try modificationDate(for: lhs) > modificationDate(for: rhs) }

guard let assetURL = candidates.first else {
throw BridgeError(
Expand Down Expand Up @@ -98,8 +98,8 @@ package struct DocumentationAssetLocator {
return nsError.code == NSFileNoSuchFileError || nsError.code == NSFileReadNoSuchFileError
}

private func modificationDate(for url: URL) -> Date {
let resourceValues = try? url.resourceValues(forKeys: [.contentModificationDateKey])
return resourceValues?.contentModificationDate ?? .distantPast
package func modificationDate(for url: URL) throws -> Date {
let resourceValues = try url.resourceValues(forKeys: [.contentModificationDateKey])
return resourceValues.contentModificationDate ?? .distantPast
}
}
8 changes: 8 additions & 0 deletions Tests/XCDocsTests/DocumentationAssetLocatorTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,14 @@ struct DocumentationAssetLocatorTests {
#expect(error.code == .assetNotFound)
}

@Test
func propagatesErrorWhenModificationDateLookupFails() throws {
let nonexistentURL = URL(fileURLWithPath: "/tmp/nonexistent-\(UUID().uuidString).asset")
let locator = DocumentationAssetLocator()

#expect(throws: (any Error).self) { try locator.modificationDate(for: nonexistentURL) }
}

@Test
func selectsTheNewestValidAsset() throws {
let rootURL = try makeTemporaryDirectory()
Expand Down
Loading