mirror of
https://github.com/apple/swift-nio
synced 2026-11-28 05:14:23 +00:00
Use the new Android overlay and Bionic module from Swift 6 (#2784)
Motivation: Get this repo building again for Android with the new overlay Modifications: - Import the new module or overlay wherever `Glibc` is used - Keep this repo building with Swift 5 by duplicating some declarations Result: All the same tests keep passing on my Android CI, finagolfin/swift-android-sdk#158
This commit is contained in:
1 parent
284125791a
commit
4feff3c2f6
33 files changed
+164
-43
No files matched your search
@@ -26,6 +26,8 @@ import CNIOLinux
|
||||
#elseif canImport(Musl)
|
||||
import Musl
|
||||
import CNIOLinux
|
||||
#elseif canImport(Bionic)
|
||||
import Bionic
|
||||
#endif
|
||||
|
||||
/// An implementation of ``FileHandleProtocol`` which is backed by system calls and a file
|
||||
@@ -55,7 +57,7 @@ public final class SystemFileHandle {
|
||||
enum Mode {
|
||||
/// Rename the created file to become the desired file.
|
||||
case rename
|
||||
#if canImport(Glibc) || canImport(Musl)
|
||||
#if canImport(Glibc) || canImport(Musl) || canImport(Bionic)
|
||||
/// Link the unnamed file to the desired file using 'linkat(2)'.
|
||||
case link
|
||||
#endif
|
||||
@@ -289,7 +291,7 @@ extension SystemFileHandle: FileHandleProtocol {
|
||||
}
|
||||
|
||||
switch materialization.mode {
|
||||
#if canImport(Glibc) || canImport(Musl)
|
||||
#if canImport(Glibc) || canImport(Musl) || canImport(Bionic)
|
||||
case .link:
|
||||
let result = self.sendableView._materializeLink(
|
||||
descriptor: descriptor,
|
||||
@@ -695,7 +697,7 @@ extension SystemFileHandle.SendableView {
|
||||
}
|
||||
}
|
||||
|
||||
#if canImport(Glibc) || canImport(Musl)
|
||||
#if canImport(Glibc) || canImport(Musl) || canImport(Bionic)
|
||||
fileprivate func _materializeLink(
|
||||
descriptor: FileDescriptor,
|
||||
from createdPath: FilePath,
|
||||
@@ -806,7 +808,7 @@ extension SystemFileHandle.SendableView {
|
||||
|
||||
let result: Result<Void, FileSystemError>
|
||||
switch materialization.mode {
|
||||
#if canImport(Glibc) || canImport(Musl)
|
||||
#if canImport(Glibc) || canImport(Musl) || canImport(Bionic)
|
||||
case .link:
|
||||
if materialize {
|
||||
result = self._materializeLink(
|
||||
@@ -831,7 +833,7 @@ extension SystemFileHandle.SendableView {
|
||||
to: desiredPath,
|
||||
options: materialization.exclusive ? [.exclusive] : []
|
||||
)
|
||||
#elseif canImport(Glibc) || canImport(Musl)
|
||||
#elseif canImport(Glibc) || canImport(Musl) || canImport(Bionic)
|
||||
// The created and desired paths are absolute, so the relative descriptors are
|
||||
// ignored. However, they must still be provided to 'rename' in order to pass
|
||||
// flags.
|
||||
@@ -860,7 +862,7 @@ extension SystemFileHandle.SendableView {
|
||||
// If 'renameat2' failed on Linux with EINVAL then in all likelihood the
|
||||
// 'RENAME_NOREPLACE' option isn't supported. As we're doing an exclusive
|
||||
// create, check the desired path doesn't exist then do a regular rename.
|
||||
#if canImport(Glibc) || canImport(Musl)
|
||||
#if canImport(Glibc) || canImport(Musl) || canImport(Bionic)
|
||||
switch Syscall.stat(path: desiredPath) {
|
||||
case .failure(.noSuchFileOrDirectory):
|
||||
// File doesn't exist, do a 'regular' rename.
|
||||
@@ -1450,7 +1452,7 @@ extension SystemFileHandle {
|
||||
}
|
||||
|
||||
func makePath() -> FilePath {
|
||||
#if canImport(Glibc) || canImport(Musl)
|
||||
#if canImport(Glibc) || canImport(Musl) || canImport(Bionic)
|
||||
if useTemporaryFileIfPossible {
|
||||
return currentWorkingDirectory.appending(path.components.dropLast())
|
||||
}
|
||||
@@ -1463,7 +1465,7 @@ extension SystemFileHandle {
|
||||
desiredPath = currentWorkingDirectory.appending(path.components)
|
||||
} else {
|
||||
func makePath() -> FilePath {
|
||||
#if canImport(Glibc) || canImport(Musl)
|
||||
#if canImport(Glibc) || canImport(Musl) || canImport(Bionic)
|
||||
if useTemporaryFileIfPossible {
|
||||
return path.removingLastComponent()
|
||||
}
|
||||
@@ -1479,7 +1481,7 @@ extension SystemFileHandle {
|
||||
let materializationMode: Materialization.Mode
|
||||
let options: FileDescriptor.OpenOptions
|
||||
|
||||
#if canImport(Glibc) || canImport(Musl)
|
||||
#if canImport(Glibc) || canImport(Musl) || canImport(Bionic)
|
||||
if useTemporaryFileIfPossible {
|
||||
options = [.temporaryFile]
|
||||
materializationMode = .link
|
||||
@@ -1516,7 +1518,7 @@ extension SystemFileHandle {
|
||||
|
||||
return .success(handle)
|
||||
} catch {
|
||||
#if canImport(Glibc) || canImport(Musl)
|
||||
#if canImport(Glibc) || canImport(Musl) || canImport(Bionic)
|
||||
// 'O_TMPFILE' isn't supported for the current file system, try again but using
|
||||
// rename instead.
|
||||
if useTemporaryFileIfPossible, let errno = error as? Errno, errno == .notSupported {
|
||||
|
||||
Reference in new issue
Block a user