5 Commits
Author SHA1 Message Date
MOHAMMED WASIM KHAN 3777a70115 Fallback to non-positional read/write on ENXIO (#3671)
This PR addresses **#3613** where writing to `/dev/stdout` fails with
`ENXIO (6) Device not configured` when running in a terminal environment
instead of a pipe.

Currently, `SystemFileHandle` checks for `errno == .illegalSeek`
(ESPIPE) when deciding whether to fall back from positional
`pwrite`/`pread` to non-positional `write`/`read` for unseekable files
like pipes. However, macOS/Darwin returns `ENXIO`
(`Errno.noSuchDeviceOrAddress`) instead of `ESPIPE` when attempting a
positional write/read on a terminal device.

**Changes:**
- Added `.noSuchDeviceOrAddress` to the fallback conditions in
`SystemFileHandle.swift` for both `readChunk` and `write`.
- Updated `FileSystemError+Syscall.swift` to map
`.noSuchDeviceOrAddress` to `.unsupported` alongside `.illegalSeek`.
- Replicated these changes across both the `_NIOFileSystem` and `NIOFS`
modules.

This allows `FileSystem.shared.withFileHandle` and other APIs to work
transparently with terminal devices like `/dev/stdout`!
2026-07-22 17:55:38 +01:00
Alex TowellandClaude Opus 4.6 98f8824da0 Handle EPERM as permissionDenied in open syscall error mapping (#3560)
## Summary
- NIOFileSystem's `open` syscall error mapping only handled `EACCES`
(`.permissionDenied`) but not `EPERM` (`.notPermitted`), causing EPERM
errors (e.g., on network volumes) to be classified as "unknown" instead
of `permissionDenied`
- Added `.notPermitted` alongside `.permissionDenied` in the `open()`
switch case in `FileSystemError+Syscall.swift` (both `NIOFS` and
`_NIOFileSystem` modules)
- Added corresponding test expectation for the new errno mapping

## Motivation
Other syscall handlers in the same file (`remove`, `symlink`, `unlink`,
`futimens`) already correctly handle both `.permissionDenied` and
`.notPermitted` as `permissionDenied`. The `open` handler was missing
this treatment.

Fixes #3559

## Test plan
- [x] Updated `testErrnoMapping_open` to verify `.notPermitted` maps to
`.permissionDenied`
- [ ] CI will validate on all supported Swift versions

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-25 15:59:06 +00: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
Karan LokchandaniandCory Benfield 608e511d7a Add homeDirectory accessor to FileSystem (#3471)
Add homeDirectory accessor to FileSystem

### Motivation:
Addresses #3381 by adding a `homeDirectory` property to FileSystem,
equivalent to `FileManager.default.homeDirectoryForCurrentUser`.

### Modifications:
- Added `homeDirectory` property to `FileSystemProtocol` and implemented
in `FileSystem`
- Implementation checks `HOME` environment variable first, falls back to
`USERPROFILE` on Windows, or uses `getpwuid_r(3)` on POSIX systems
- Added system call wrappers (`system_getuid`, `libc_getpwuid_r`) with
proper platform guards
- Added `FileSystemError.getpwuid_r()` error helper

### Result:
Users can now access the home directory via `FileSystem.homeDirectory`,
returning a `FilePath` asynchronously. Follows the same pattern as
`currentWorkingDirectory` and `temporaryDirectory`.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2026-01-12 15:10:25 +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