Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
WFT opened this issue Oct 18, 2024 · 0 comments

Comments

@WFT
Copy link

WFT commented Oct 18, 2024

This call has differing behavior when importing Foundation vs when importing FoundationEssentials on Linux:

try FileManager.default.url(for: .itemReplacementDirectory, in: .userDomainMask, appropriateFor: documents, create: true)

Reproduction

The following snippet exits successfully when importing Foundation (macOS or Linux), but if you instead import FoundationEssentials it throws an error when creating temp.

import Foundation // Comment this line and uncomment the next to see the issue
// import FoundationEssentials

print("Creating documents...")
let documents = try FileManager.default.url(
    for: .documentDirectory,
    in: .userDomainMask,
    appropriateFor: nil,
    create: true
)
print("Creating temporary...")
// Raises FoundationEssentials.CocoaError(code: FoundationEssentials.CocoaError.Code(rawValue: 256), userInfo: [:])
let temp = try FileManager.default.url(
    for: .itemReplacementDirectory,
    in: .userDomainMask,
    appropriateFor: documents,
    create: true
)

print("Results")

print(temp)
print(FileManager.default.fileExists(atPath: temp.path(percentEncoded: false)))

You can run this with the swift:6.0.1 Docker image to see the issue.

Expected behavior

I think temp should be a temporary directory which has been created, probably somewhere like /tmp/abc123/NSIRD_test.swift_xyz456/. I feel that’s the best approximation of what happens on macOS (where we get something like /var/folders/q0/abc123/T/TemporaryItems/NSIRD_test.swift_xyz456/). The particular format isn’t particularly important — I’m basically just looking for a portable form of mkdtemp.

Or at the very least the behavior shouldn’t change when the imported module changes.

Actual behavior

An error is raised from the indicated line (FoundationEssentials only).

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

No branches or pull requests

1 participant