Skip to content

Handle item replacement directories in FoundationEssentials - #2219

Closed
Hokila wants to merge 1 commit into
swiftlang:release/6.4.xfrom
Hokila:codex/fix-item-replacement-directory-991-release
Closed

Handle item replacement directories in FoundationEssentials#2219
Hokila wants to merge 1 commit into
swiftlang:release/6.4.xfrom
Hokila:codex/fix-item-replacement-directory-991-release

Conversation

@Hokila

@Hokila Hokila commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Motivation

Resolves #991.

FoundationEssentials currently falls through to normal search path lookup for .itemReplacementDirectory. That lookup returns no URL, so FileManager.url(for:in:appropriateFor:create:) throws on Linux when callers ask for a replacement directory.

Modifications

Add a FoundationEssentials path for .itemReplacementDirectory when the domain is .userDomainMask and appropriateFor is supplied. It creates a TemporaryItems container under the process temporary directory when that directory is on the same volume as the reference URL. Otherwise it falls back to a writable directory based on the reference URL, matching the older corelibs behavior.

The replacement directory itself is always created, including for create: false, so callers get a unique directory and avoid races.

Add a regression test that covers create: false and create: true, verifies the returned directories exist, and checks that repeated calls return distinct directories.

Validation

  • git diff --check
  • swiftc -parse Sources/FoundationEssentials/FileManager/FileManager+Directories.swift Tests/FoundationEssentialsTests/FileManager/FileManagerTests.swift

I could not run swift test --filter FileManager/itemReplacementDirectory locally with Xcode Swift 6.2.3. The package starts building on the release/6.4.x base, but fails in existing source that requires a newer compiler (@specialized and @_lifetime diagnostics in String+Internals.swift) before it reaches this test.

@Hokila
Hokila requested a review from a team as a code owner August 31, 2026 06:10
@Hokila Hokila closed this Aug 31, 2026
@Hokila
Hokila deleted the codex/fix-item-replacement-directory-991-release branch August 31, 2026 06:15
@Hokila

Hokila commented Aug 31, 2026

Copy link
Copy Markdown
Contributor Author

Reopened as #2220 after renaming the fork branch to remove the codex prefix.

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.

1 participant