Skip to content

Handle item replacement directories in FoundationEssentials - #2220

Merged
jmschonfeld merged 3 commits into
swiftlang:mainfrom
Hokila:fix-item-replacement-directory-991-release
Sep 4, 2026
Merged

Handle item replacement directories in FoundationEssentials#2220
jmschonfeld merged 3 commits into
swiftlang:mainfrom
Hokila:fix-item-replacement-directory-991-release

Conversation

@Hokila

@Hokila Hokila commented Aug 31, 2026

Copy link
Copy Markdown
Contributor

Motivation

Resolves #991.

FoundationEssentials did not handle .itemReplacementDirectory in FileManager.url(for:in:appropriateFor:create:). It fell through to normal search-path lookup, which could fail to return a replacement directory.

Modifications

  • Add FoundationEssentials handling for .itemReplacementDirectory with a user-domain reference URL.
  • Select the replacement container based on the reference volume, using TemporaryItems when appropriate and a writable reference location otherwise.
  • Always create a unique replacement directory, including when create is false, matching corelibs Foundation behavior and avoiding races.
  • Use the existing FoundationEssentials .systemNumber file attribute for volume comparison.
  • Add regression coverage for both create: true and create: false, including existence and uniqueness checks.

Validation

Using 6.4.x-snapshot-2026-08-28 (Apple Swift 6.4-dev):

swift test --filter itemReplacementDirectory

Test itemReplacementDirectory(create:) with 2 test cases passed.

Both create: true and create: false cases pass.

@Hokila
Hokila requested a review from a team as a code owner August 31, 2026 06:15
@Hokila
Hokila marked this pull request as draft August 31, 2026 06:19
@Hokila
Hokila marked this pull request as ready for review August 31, 2026 07:21
Comment thread Sources/FoundationEssentials/FileManager/FileManager+Directories.swift Outdated
Comment thread Sources/FoundationEssentials/FileManager/FileManager+Directories.swift Outdated
Comment thread Sources/FoundationEssentials/FileManager/FileManager+Directories.swift Outdated
Comment thread Tests/FoundationEssentialsTests/FileManager/FileManagerTests.swift Outdated
@Hokila
Hokila force-pushed the fix-item-replacement-directory-991-release branch 2 times, most recently from bec3093 to 0357512 Compare September 2, 2026 06:36
@Hokila
Hokila force-pushed the fix-item-replacement-directory-991-release branch from 0357512 to bb5bd64 Compare September 2, 2026 06:37
@Hokila
Hokila marked this pull request as draft September 2, 2026 06:38
@Hokila
Hokila changed the base branch from release/6.4.x to main September 2, 2026 06:39
@Hokila
Hokila marked this pull request as ready for review September 2, 2026 06:39
Comment thread Sources/FoundationEssentials/FileManager/FileManager+Directories.swift Outdated
try? fileManager.removeItem(at: secondReplacementDirectory)
}

var isDirectory = 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.

There's a discrepancy here between the type of this value in FoundationEssentials and what's available in Foundation, so this test fails to compile in FOUNDATION_FRAMEWORK mode. Could you please update this test to follow the convention set by fileExistsAtPath for handling this difference?

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.

Updated the test to follow the existing fileExistsAtPath convention, using ObjCBool for FOUNDATION_FRAMEWORK and Bool for FoundationEssentials.

Match file existence test declaration
@Hokila
Hokila force-pushed the fix-item-replacement-directory-991-release branch from 9bdd55e to ede2cf2 Compare September 4, 2026 02:46
@jmschonfeld
jmschonfeld merged commit d6d56d0 into swiftlang:main Sep 4, 2026
22 checks passed
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.

FileManager creating temporary directory has differing behavior between FoundationEssentials/Foundation (Linux)

2 participants