Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Sources/NIOFileSystem/Internal/System Calls/Errno.swift
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,24 @@ public func valueOrErrno<R>(
}
}
}

/// As `valueOrErrno` but returns `Errno` if result is nil.
@_spi(Testing)
public func unwrapValueOrErrno<R>(
retryOnInterrupt: Bool = true,
_ fn: () -> R?
) -> Result<R, Errno> {
while true {
Errno.clear()
if let result = fn() {
return .success(result)
} else {
let errno = Errno._current
if errno == .interrupted, retryOnInterrupt {
continue
} else {
return .failure(errno)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ extension FileDescriptor {
/// caller should not modify the descriptor or close the descriptor via `close()`. Once
/// directory iteration has been completed then `Libc.closdir(_:)` must be called.
internal func opendir() -> Result<CInterop.DirPointer, Errno> {
valueOrErrno(retryOnInterrupt: false) {
unwrapValueOrErrno(retryOnInterrupt: false) {
libc_fdopendir(self.rawValue)
}
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/NIOFileSystem/Internal/System Calls/Syscalls.swift
Original file line number Diff line number Diff line change
Expand Up @@ -368,8 +368,8 @@ internal func system_futimens(
/// fdopendir(3): Opens a directory stream for the file descriptor
internal func libc_fdopendir(
_ fd: FileDescriptor.RawValue
) -> CInterop.DirPointer {
fdopendir(fd)!
) -> CInterop.DirPointer? {
fdopendir(fd)
}

/// readdir(3): Returns a pointer to the next directory entry
Expand Down
Loading