Repository: apple/swift-nio
File: Sources/NIOFileSystem/Internal/SystemFileHandle.swift (Swift)

Code before:
}

@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
extension SystemFileHandle {
    static func syncOpen(
        atPath path: FilePath,
        mode: FileDescriptor.AccessMode,
        options: FileDescriptor.OpenOptions,
        permissions: FilePermissions?,
        transactionalIfPossible transactional: Bool,
        executor: IOExecutor
    ) -> Result<SystemFileHandle, FileSystemError> {
        let isWritable = (mode == .writeOnly || mode == .readWrite)
        let exclusiveCreate = options.contains(.exclusiveCreate)
        let truncate = options.contains(.truncate)
        let delayMaterialization = transactional && isWritable && (exclusiveCreate || truncate)

        if delayMaterialization {
            // When opening in this mode we can more "atomically" create the file, that is, by not
            // leaving the user with a half written file should e.g. the system crash or throw an
            // error while writing. On non-Android Linux we do this by opening the directory for
            // the path with `O_TMPFILE` and creating a hard link when closing the file. On other
            // platforms we generate a dot file with a randomised suffix name and rename it to the
            // destination.
            #if os(Android)
            return Self.syncOpenWithMaterialization(
                atPath: path,
                mode: mode,
                options: options,
                permissions: permissions,
                executor: executor,
                useTemporaryFileIfPossible: false
            )
            #else
            return Self.syncOpenWithMaterialization(
                atPath: path,
                mode: mode,
                options: options,
                permissions: permissions,
                executor: executor
            )
            #endif
        } else {
            return Self.syncOpen(
                atPath: path,
                mode: mode,
                options: options,
                permissions: permissions,
                executor: executor
            )
        }

Review comment (suggestion):
Rather than duping the whole call, can we conditionalise just `useTemporaryFileIfPossible`? i.e.

```swift
#if os(Android)
let useTemporaryFileIfPossible = false
#else
let useTemporaryFileIfPossible = true
#endif

Makes it a little bit easier to see what the differences are.
```

Code after:
}

@available(macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0, *)
extension SystemFileHandle {
    static func syncOpen(
        atPath path: FilePath,
        mode: FileDescriptor.AccessMode,
        options: FileDescriptor.OpenOptions,
        permissions: FilePermissions?,
        transactionalIfPossible transactional: Bool,
        executor: IOExecutor
    ) -> Result<SystemFileHandle, FileSystemError> {
        let isWritable = (mode == .writeOnly || mode == .readWrite)
        let exclusiveCreate = options.contains(.exclusiveCreate)
        let truncate = options.contains(.truncate)
        let delayMaterialization = transactional && isWritable && (exclusiveCreate || truncate)

        if delayMaterialization {
            // When opening in this mode we can more "atomically" create the file, that is, by not
            // leaving the user with a half written file should e.g. the system crash or throw an
            // error while writing. On non-Android Linux we do this by opening the directory for
            // the path with `O_TMPFILE` and creating a hard link when closing the file. On other
            // platforms we generate a dot file with a randomised suffix name and rename it to the
            // destination.
            #if os(Android)
            let temporaryHardLink = false
            #else
            let temporaryHardLink = true
            #endif
            return Self.syncOpenWithMaterialization(
                atPath: path,
                mode: mode,
                options: options,
                permissions: permissions,
                executor: executor,
                useTemporaryFileIfPossible: temporaryHardLink
            )
        } else {
            return Self.syncOpen(
                atPath: path,
                mode: mode,
                options: options,
                permissions: permissions,
                executor: executor
            )
        }
    }

    static func syncOpen(
        atPath path: FilePath,
        mode: FileDescriptor.AccessMode,