Skip to content

[NIOFileSystem] Fallback to rename when renameat2 is not available - #3612

Merged
glbrntt merged 1 commit into
apple:mainfrom
madsodgaard:main
Jun 3, 2026
Merged

glbrntt merged 1 commit into
apple:mainfrom
madsodgaard:main

Conversation

@madsodgaard

Copy link
Copy Markdown
Contributor

We are running into some issues when doing:

        let writeOptions: OpenOptions.Write =
            byteOffset > 0 ? .modifyFile(createIfNecessary: true) : .newFile(replaceExisting: true)

        try await FileSystem.shared.withFileHandle(
            forWritingAt: FilePath(outputFilePath),
            options: writeOptions
        ) { fileHandle in

which results in crashes on some Android devices where renameat2 is not available:

('renameat2' system call failed with '(38) Function not implemented'.)

This PR adds functionality similar to what is already done for EINVAL on Linux, such that both lead to the same recovery: stat the destination, then plain rename() if absent.

And for non-exclusive renames where it also fails to function not implemented, it falls back to plain rename.

@glbrntt glbrntt left a comment

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.

LGTM, thank you!

@glbrntt glbrntt added the πŸ”¨ semver/patch No public API change. label Jun 3, 2026
@glbrntt

glbrntt commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

The API breakage check is a false positive on SPI. We can merge over it.

@glbrntt
glbrntt merged commit 77b84ac into apple:main Jun 3, 2026
52 of 55 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

πŸ”¨ semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants