Commit Graph
3 Commits
Author SHA1 Message Date
Mads Odgaard 77b84ac2cd [NIOFileSystem] Fallback to rename when renameat2 is not available (#3612)
We are running into some issues when doing:

```swift
        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`.
2026-06-03 14:33:41 +01:00
Stepan Ulyanin fff2515d6e Add symlinkat, renameatx_np, and unlinkat system call wrappers to the _NIOFileSystem module (#3524)
Ports the added system calls from `NIOFS` (from
https://github.com/apple/swift-nio/pull/3505) to `_NIOFileSystem`:

> Adds three new system call wrappers for the `symlinkat`,
`renameatx_np`, and `unlinkat` system calls.

### Motivation:

`_NIOFileSystem` module is around for backward compatibility - hence, we
are porting the new feature to it.

### Modifications:

Exactly same as in https://github.com/apple/swift-nio/pull/3505 but
applied to the `_NIOFileSystem`:

> Related to https://github.com/apple/swift-nio/issues/3403 and
https://github.com/apple/swift-nio/pull/3470. This PR adds syscall
wrappers needed to atomically overwrite existing files or symlinks at
the destination during copy operations. On Linux, atomic overwrites
require a "copy to temp file, then rename" strategy. We use the `*at`
family of syscalls (which operate relative to directory file
descriptors) to avoid TOCTOU race conditions.
2026-03-02 10:00:35 +00:00
George Barnett 66a85ba0e2 Add back _NIOFileSystem (#3367)
Motivation:

In #3363 we converted `_NIOFileSystem` to `NIOFileSystem` and removed
the (unreleased) overloads for FilePath/NIOFilePath. This change adds
back `_NIOFileSystem` such that it matches the API it had at 2.86.0.

Modifications:

- Add back `_NIOFileSystem` and `_NIOFileSystemFoundationCompat` such
that their API is at 2.86.0

Result:

- `NIOFileSystem` uses `NIOFilePath`
- `_NIOFileSystem` uses `FilePath`
2025-09-02 14:56:58 +01:00