Skip to content

Commit 3bdfaab

Browse files
committed
Use SystemPath for PluginConfig.
Convert PluginConfig.init from URL to FilePath, following the migration pattern from apple#1480 (HostDNSResolver), apple#1518 (PacketFilter), and discussion apple#1481. - PluginConfig.init?(configURL: URL) → init?(configPath: FilePath) - DefaultPluginFactory.findConfigURL → findConfigPath (returns FilePath?) - Both internal call sites (DefaultPluginFactory, AppBundlePluginFactory) updated; bridge from URL to FilePath stays at the directory boundary since broader PluginFactory conversion is tracked separately. - Tests updated to derive FilePath from temp URL.
1 parent caff1e9 commit 3bdfaab

3 files changed

Lines changed: 22 additions & 15 deletions

File tree

Sources/ContainerPlugin/PluginConfig.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
//
1818
import Foundation
19+
import SystemPackage
1920
import TOML
2021

2122
/// PluginConfig details all of the fields to describe and register a plugin.
@@ -109,17 +110,17 @@ extension PluginConfig {
109110
extension PluginConfig {
110111
/// Initialize from a config file, selecting the decoder based on file extension.
111112
/// Supports `.toml` (via TOMLDecoder) and `.json` (via JSONDecoder).
112-
public init?(configURL: URL) throws {
113+
public init?(configPath: FilePath) throws {
113114
let fm = FileManager.default
114-
if !fm.fileExists(atPath: configURL.path) {
115+
if !fm.fileExists(atPath: configPath.string) {
115116
return nil
116117
}
117118

118-
guard let data = fm.contents(atPath: configURL.path) else {
119+
guard let data = fm.contents(atPath: configPath.string) else {
119120
return nil
120121
}
121122

122-
switch configURL.pathExtension {
123+
switch configPath.extension {
123124
case "toml":
124125
guard let content = String(data: data, encoding: .utf8) else {
125126
return nil

Sources/ContainerPlugin/PluginFactory.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import Foundation
1818
import Logging
19+
import SystemPackage
1920

2021
/// Describes the configuration and binary file locations for a plugin.
2122
public protocol PluginFactory: Sendable {
@@ -35,8 +36,8 @@ public struct DefaultPluginFactory: PluginFactory {
3536
self.logger = logger
3637
}
3738

38-
/// Returns the URL of the first config file found in `directory`, preferring TOML over JSON.
39-
static func findConfigURL(in directory: URL, logger: Logger) -> URL? {
39+
/// Returns the path of the first config file found in `directory`, preferring TOML over JSON.
40+
static func findConfigPath(in directory: URL, logger: Logger) -> FilePath? {
4041
let fm = FileManager.default
4142
for filename in configFilenames {
4243
let url = directory.appending(path: filename)
@@ -47,7 +48,7 @@ public struct DefaultPluginFactory: PluginFactory {
4748
metadata: ["path": "\(url.path)"]
4849
)
4950
}
50-
return url
51+
return FilePath(url.path)
5152
}
5253
}
5354
return nil
@@ -56,11 +57,11 @@ public struct DefaultPluginFactory: PluginFactory {
5657
public func create(installURL: URL) throws -> Plugin? {
5758
let fm = FileManager.default
5859

59-
guard let configURL = Self.findConfigURL(in: installURL, logger: logger) else {
60+
guard let configPath = Self.findConfigPath(in: installURL, logger: logger) else {
6061
return nil
6162
}
6263

63-
guard let config = try PluginConfig(configURL: configURL) else {
64+
guard let config = try PluginConfig(configPath: configPath) else {
6465
return nil
6566
}
6667

@@ -99,11 +100,11 @@ public struct AppBundlePluginFactory: PluginFactory {
99100
.appending(path: "Contents")
100101
.appending(path: "Resources")
101102

102-
guard let configURL = DefaultPluginFactory.findConfigURL(in: contentResources, logger: logger) else {
103+
guard let configPath = DefaultPluginFactory.findConfigPath(in: contentResources, logger: logger) else {
103104
return nil
104105
}
105106

106-
guard let config = try PluginConfig(configURL: configURL) else {
107+
guard let config = try PluginConfig(configPath: configPath) else {
107108
return nil
108109
}
109110

Tests/ContainerPluginTests/PluginConfigTest.swift

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
//===----------------------------------------------------------------------===//
1616

1717
import Foundation
18+
import SystemPackage
1819
import Testing
1920

2021
@testable import ContainerPlugin
@@ -35,7 +36,8 @@ struct PluginConfigTest {
3536
author = "Apple"
3637
"""
3738
try configToml.write(to: configURL, atomically: true, encoding: .utf8)
38-
let config = try #require(try PluginConfig(configURL: configURL))
39+
let configPath = FilePath(configURL.path)
40+
let config = try #require(try PluginConfig(configPath: configPath))
3941

4042
#expect(config.isCLI)
4143
#expect(config.abstract == "Default network management service")
@@ -67,7 +69,8 @@ struct PluginConfigTest {
6769
description = "foo"
6870
"""
6971
try configToml.write(to: configURL, atomically: true, encoding: .utf8)
70-
let config = try #require(try PluginConfig(configURL: configURL))
72+
let configPath = FilePath(configURL.path)
73+
let config = try #require(try PluginConfig(configPath: configPath))
7174

7275
#expect(!config.isCLI)
7376
#expect(config.abstract == "Default network management service")
@@ -97,8 +100,9 @@ struct PluginConfigTest {
97100
[invalid
98101
"""
99102
try malformedToml.write(to: configURL, atomically: true, encoding: .utf8)
103+
let configPath = FilePath(configURL.path)
100104
#expect(throws: (any Error).self) {
101-
try PluginConfig(configURL: configURL)
105+
try PluginConfig(configPath: configPath)
102106
}
103107
}
104108

@@ -117,7 +121,8 @@ struct PluginConfigTest {
117121
author: "Apple"
118122
"""
119123
try content.write(to: configURL, atomically: true, encoding: .utf8)
120-
let config = try PluginConfig(configURL: configURL)
124+
let configPath = FilePath(configURL.path)
125+
let config = try PluginConfig(configPath: configPath)
121126
#expect(config == nil)
122127
}
123128
}

0 commit comments

Comments
 (0)