Skip to content

Centralize utilities for configuration loading and path parsing#1448

Open
noah-thor wants to merge 2 commits intoapple:mainfrom
noah-thor:user-config-utility-no-toml
Open

Centralize utilities for configuration loading and path parsing#1448
noah-thor wants to merge 2 commits intoapple:mainfrom
noah-thor:user-config-utility-no-toml

Conversation

@noah-thor
Copy link
Copy Markdown
Contributor

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation update

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:

let configPath = UserConfiguration.basePath(for: .appRoot).appending("config/config.toml")

Testing

  • Tested locally
  • Added/updated tests
  • Added/updated docs

@noah-thor
Copy link
Copy Markdown
Contributor Author

Mainly looking for API feedback, changes will not be mergable until TOML PR is merged

Comment thread Sources/ContainerPersistence/ConfigurationLoader.swift Outdated
Comment thread Sources/ContainerPersistence/ConfigurationLoader.swift Outdated
Comment on lines +37 to +44
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))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we dedup this with ApplicationRoot?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@noah-thor noah-thor force-pushed the user-config-utility-no-toml branch from 9da3975 to 83d58aa Compare May 6, 2026 18:06
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()
@noah-thor noah-thor force-pushed the user-config-utility-no-toml branch from 83d58aa to 30566ee Compare May 6, 2026 18:24
Changes:
* Remove duplicated UserConfiguration in favor of PathUtils
* Remove stray logger in ConfigurationLoader
Copy link
Copy Markdown
Contributor

@jglogan jglogan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants