Use SystemPath for DirectoryWatcher.#1522
Merged
jglogan merged 2 commits intoMay 11, 2026
Merged
Conversation
Replaces URL-based filesystem path handling with SystemPackage.FilePath, following the pattern from apple#1480 (HostDNSResolver) and apple#1518 (PacketFilter): - directoryURL → directoryPath: FilePath (public API) - startWatching handler signature changes from ([URL]) to ([FilePath]) - LocalhostDNSHandler caller updated; the URL(filePath: configPath.string) wrapping shim is no longer needed - FilePath.lastComponent (returns Optional<Component>) handled in LocalhostDNSHandler's filename filter
849d310 to
4c1477d
Compare
jglogan
reviewed
May 9, 2026
Contributor
jglogan
left a comment
There was a problem hiding this comment.
Building now! One comment, just a nit.
| let ipv4 = (match[1].substring.flatMap { try? IPv4Address(String($0)) }) | ||
| { | ||
| let name = String(file.lastPathComponent.dropFirst(HostDNSResolver.containerizationPrefix.count)) | ||
| let lastName = file.lastComponent?.string ?? "" |
Contributor
There was a problem hiding this comment.
nit: instead of nil to empty string here, perhaps this?
let dnsName = file.lastComponent?.string
.map { $0.dropFirst(HostDNSResolver.containerizationPrefix.count) }
.map { try? DNSName($0) }
guard let dnsName else {
continue
}
Contributor
Author
There was a problem hiding this comment.
Great catch, thank you! I'm still learning some idioms in Swift. I switched to using the guard from your example and tests pass locally.
guard let lastName = file.lastComponent?.string else {
continue
}
Contributor
There was a problem hiding this comment.
That is also idiomatic and easy to read, thanks!
9e19473 to
4c1477d
Compare
jglogan
approved these changes
May 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type of Change
Motivation and Context
Continues the URL → FilePath migration discussed in #1481.
Changes in this PR:
directoryURL: URL→directoryPath: FilePath(public API)init(directoryURL:, log:)→init(directoryPath:, log:)startWatchinghandler signature:([URL]) throws -> Void→([FilePath]) throws -> VoidSources/APIServer/LocalhostDNSHandler.swiftupdated to call the new init directly (the previousURL(filePath: configPath.string)wrapping shim is no longer needed)Behavioral note:
URL.lastPathComponentreturnsString;FilePath.lastComponentreturnsFilePath.Component?. The filename filter inLocalhostDNSHandlerhandles the optional via$0.lastComponent?.string.starts(with: ...) == true, preserving the prior "skip malformed entries" behavior.Testing
swift test --filter DirectoryWatcherTestand--filter ContainerOSTestsboth pass)DirectoryWatcherwithFilePath)