Skip to content

[SR-14823] macOS and Linux file length requirements differ for Data's write(to:options) method #3954

@swift-ci

Description

@swift-ci
Previous ID SR-14823
Radar rdar://problem/80384586
Original Reporter amigi (JIRA User)
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Foundation
Labels Bug
Assignee @millenomi
Priority Medium

md5: 6df37eef7bfa36cca485fbbe01e38053

Issue Description:

On macOS the max filename length to pass to `Data`'s `write(to:options🙂` method is 255 bytes. However, the limit on Linux currently is 244 bytes.

Looking at https://github.com/apple/swift-corelibs-foundation/blob/main/Sources/Foundation/NSPathUtilities.swift#L738, we create the template temporary file name like so:

```swift
let template = filePath + ".tmp.XXXXXX"
```

Instead of using `filePath` directly, we should check to see if extends past a certain length, then truncate the length of the string by enough characters to fit inside the 255 byte limit. This will allow the input path be up to 255 bytes, while the temporary file is also under the 255 byte limit.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions