Centralize utilities for configuration loading and path parsing#1448
Centralize utilities for configuration loading and path parsing#1448noah-thor wants to merge 2 commits intoapple:mainfrom
Conversation
|
Mainly looking for API feedback, changes will not be mergable until TOML PR is merged |
| if let envPath = ProcessInfo.processInfo.environment["CONTAINER_APP_ROOT"], !envPath.isEmpty { | ||
| return FilePath(envPath) | ||
| } | ||
| let appSupportURL = FileManager.default.urls( | ||
| for: .applicationSupportDirectory, | ||
| in: .userDomainMask | ||
| ).first!.appendingPathComponent("com.apple.container") | ||
| return FilePath(appSupportURL.path(percentEncoded: false)) |
There was a problem hiding this comment.
Could we dedup this with ApplicationRoot?
There was a problem hiding this comment.
You mean completely remove the ApplicationRoot and/or just have a single definition? I think that makes sense I was just hesitant to touch that code
9da3975 to
83d58aa
Compare
Separates path resolution (PathUtils) from TOML loading (ConfigurationLoader) in ContainerPersistence. - PathUtils: resolves base paths for .home (XDG priority) and .appRoot - ConfigurationLoader: load() reads from appRoot, copyConfigToAppRoot() syncs user config with non-throwing error logging - ContainerSystemConfig: now non-final with Initable conformance - All ~17 callsites simplified to ConfigurationLoader.load()
83d58aa to
30566ee
Compare
Changes: * Remove duplicated UserConfiguration in favor of PathUtils * Remove stray logger in ConfigurationLoader
jglogan
left a comment
There was a problem hiding this comment.
lgtm, see follow-up notes
| let containerSystemConfig: ContainerSystemConfig = try ConfigurationLoader.load() | ||
| let appRootPath = FilePath(appRoot.path(percentEncoded: false)) | ||
| try ConfigurationLoader.copyConfigurationToReadOnly(to: appRootPath) | ||
| let containerSystemConfig: ContainerSystemConfig = try ConfigurationLoader.load( |
There was a problem hiding this comment.
nit for the next commit: we can use type inference here and shorten the line
| case .home: | ||
| let configHome: String | ||
| if let xdg = ProcessInfo.processInfo.environment["XDG_CONFIG_HOME"], !xdg.isEmpty { | ||
| if let xdg = env["XDG_CONFIG_HOME"], !xdg.isEmpty { |
There was a problem hiding this comment.
Need a follow up PR to scrub ContainerPersistence for string and URL path manipulation. I took care of this for the entity store type.
e.g. we could start here with something like:
let configHome = env["XDG_CONFIG_HOME"]
.map { FilePath($0) }
?? FilePath(NSHomeDirectory()).appending("/.config")
Type of Change
Motivation and Context
This attempts to create a more centralized utility to find and load configuration files, as a follow up to (pr: #1425).
This would make the file apis look something like:
Testing