Skip to content

Use SystemPath for ContainerResource.Filesystem.#1523

Merged
jglogan merged 2 commits into
apple:mainfrom
full-chaos:feat/chaos-1452-filesystem-absolute-path
May 12, 2026
Merged

Use SystemPath for ContainerResource.Filesystem.#1523
jglogan merged 2 commits into
apple:mainfrom
full-chaos:feat/chaos-1452-filesystem-absolute-path

Conversation

@chrisgeo
Copy link
Copy Markdown
Contributor

@chrisgeo chrisgeo commented May 8, 2026

Type of Change

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

Motivation and Context

Continues the URL → FilePath migration discussed in #1481. Tiny diff (7 lines, 1 file).

-source: URL(fileURLWithPath: source).absolutePath(),
+source: FilePath(source).string,

Affects the three Filesystem factory methods: block, volume, virtiofs.

The original URL(fileURLWithPath: source).absolutePath() was a no-op round-trip on absolute inputs (which is what every caller passes today — Parser.swift, Utility.swift, SnapshotStore.swift, and RuntimeConfigurationTests). FilePath(source).string preserves the same separator normalization without the URL detour.

Testing

  • Tested locally (swift test --filter ContainerResourceTests passes — no regressions)
  • Added/updated tests (no behavior change; existing tests cover the contract)
  • Added/updated docs

Replaces URL-based path normalization with SystemPackage.FilePath in
the three Filesystem factory methods (block, volume, virtiofs):

- source: URL(fileURLWithPath: source).absolutePath() → FilePath(source).string

All existing callers (Parser, Utility, SnapshotStore, RuntimeConfigurationTests)
already pass absolute paths; the URL round-trip was a no-op in practice.
FilePath preserves separator normalization equivalent to the URL form.

Following the migration pattern from apple#1480 (HostDNSResolver),
apple#1518 (PacketFilter), and discussion apple#1481.
@chrisgeo chrisgeo force-pushed the feat/chaos-1452-filesystem-absolute-path branch from d6c355d to 2bfc155 Compare May 8, 2026 22:13
) -> Filesystem {
.init(
type: .block(format: format, cache: cache, sync: sync),
source: URL(fileURLWithPath: source).absolutePath(),
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.

For this if we want to be functionally equivalent, we'd need something like this:

func absoluteFilePath(for source: String) -> FilePath {
    let path = FilePath(source)
    guard path.isRelative else { return path.lexicallyNormalized() }
    return FilePath(FileManager.default.currentDirectoryPath)
        .pushing(path)
        .lexicallyNormalized()
}

Copy link
Copy Markdown
Contributor Author

@chrisgeo chrisgeo May 12, 2026

Choose a reason for hiding this comment

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

I went the private function route to keep the functionality centered on this changeset.

Please let me know if you'd prefer that be adjusted. Thanks again for the feedback!

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 11, 2026

Code Coverage

Tier Line Coverage
Unit 33.24%
Integration 20.41%
Combined 53.07%

Restores functional equivalence with the prior URL(fileURLWithPath:).absolutePath()
behavior, which resolved relative paths against the current working directory.
Plain FilePath(source).string left relative inputs unresolved — a silent
regression for any future caller. Per review feedback on apple#1523.
@jglogan
Copy link
Copy Markdown
Contributor

jglogan commented May 12, 2026

@chrisgeo A little discussion on this one as well. At first I was thinking, why doesn't the PR use FilePath for the source and destination path properties?

For the source it needs to stay string because, possibly among other things, the source could be a network location.

I think that in a follow-on we could consider changing the destination path to a FilePath, but what you have in this PR is a good first step toward that.

Can you think of any possible instance where the destination path would be something else? Pretty sure any mount(2) destination on any Unix-like system is a filesystem path.

@jglogan jglogan merged commit 940fefb into apple:main May 12, 2026
3 checks passed
@jglogan
Copy link
Copy Markdown
Contributor

jglogan commented May 12, 2026

See discussion above, but the PR is fine as is, merged and thank you!

@jglogan
Copy link
Copy Markdown
Contributor

jglogan commented May 12, 2026

Can you think of any possible instance where the destination path would be something else? Pretty sure any mount(2) destination on any Unix-like system is a filesystem path.

We shouldn't rush such a change. Leaving it as String allows us to have the flexibility to define other meanings, such as for cases where the receiver of a Filesystem needs to compute the eventual destination path.

@chrisgeo
Copy link
Copy Markdown
Contributor Author

We shouldn't rush such a change. Leaving it as String allows us to have the flexibility to define other meanings, such as for cases where the receiver of a Filesystem needs to compute the eventual destination path.

@jglogan Sorry - I missed this before you merged. I took a look couldn't come up with anything we'd miss with with mount(2) options since I recall all unix-based system fstypes are paths.

Happy to dive into options for a follow-up when I can

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.

[Request]: TECH DEBT - Convert ContainerResource.Filesystem to use FilePath instead of URL.

3 participants