Skip to content

Switch NetworksService, VolumesService, EntityStore to FilePath.#1493

Merged
jglogan merged 2 commits intoapple:mainfrom
jglogan:filepath-networks
May 1, 2026
Merged

Switch NetworksService, VolumesService, EntityStore to FilePath.#1493
jglogan merged 2 commits intoapple:mainfrom
jglogan:filepath-networks

Conversation

@jglogan
Copy link
Copy Markdown
Contributor

@jglogan jglogan commented Apr 30, 2026

Type of Change

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

Motivation and Context

URL for filesystem paths is tech debt.

Testing

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

Comment on lines +177 to +184
private static func withTempDir<T: Sendable>(
_ body: @Sendable (FilePath) async throws -> T
) async throws -> T {
let url = FileManager.default.temporaryDirectory.appendingPathComponent(UUID().uuidString)
try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true)
defer { try? FileManager.default.removeItem(at: url) }
return try await body(FilePath(url.path))
}
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.

Nice, might be a good utility to pull out into a public test utils

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.

Done


let resourceRoot = appRoot.appendingPathComponent("volumes")
// TODO: This goes away when we convert our roots to FilePath
let appPath = FilePath(appRoot.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.

Where does .absolutePath() come from? Can't seem to find it on the swift documentation https://developer.apple.com/documentation/foundation/url

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.

It actually comes from ContainerizationOCI URL+Extensions.swift.

Comment thread Sources/APIServer/APIServer+Start.swift Outdated
let resourceRoot = appRoot.appendingPathComponent("volumes")
// TODO: This goes away when we convert our roots to FilePath
let appPath = FilePath(appRoot.absolutePath())
let resourceRoot = appPath.appending("networks")
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.

Why is this changing from "volumes" to "networks"

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.

Has to be a copy/paste error. Apparently our tests are okay with volumes and networks being placed in the same directory...

try FileManager.default.createDirectory(atPath: entityPath.string, withIntermediateDirectories: true)
let data = try encoder.encode(entity)
try data.write(to: metadataUrl)
try data.write(to: URL(filePath: metadataPath.string))
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 later: If we convert everything to FilePath it might be nice to introduce some extensions to FilePath such as func asURL() to make the api a bit nicer.

public func upsert(_ entity: T) async throws {
let metadataUrl: URL = metadataUrl(entity.id)
let entityPath = try entityPath(entity.id)
try FileManager.default.createDirectory(atPath: entityPath.string, withIntermediateDirectories: true)
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.

Why do we need to create the directory now?

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.

I would say it's because no code calls it today, and previously no unit tests existed.

@jglogan jglogan merged commit 9f4e779 into apple:main May 1, 2026
3 checks passed
@jglogan jglogan deleted the filepath-networks branch May 1, 2026 21:39
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: URL to FilePath for networks.

3 participants