Skip to content
Open
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
12 changes: 10 additions & 2 deletions Sources/System/FileOperations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ extension FileDescriptor {
/// - mode: The read and write access to use.
/// - options: The behavior for opening the file.
/// - permissions: The file permissions to use for created files.
/// This value must not be `nil` when `options` contains `.create`;
/// passing `nil` in that case is a programmer error and traps at runtime.
/// - retryOnInterrupt: Whether to retry the open operation
/// if it throws ``Errno/interrupted``.
/// The default is `true`.
Expand Down Expand Up @@ -55,6 +57,8 @@ extension FileDescriptor {
/// - mode: The read and write access to use.
/// - options: The behavior for opening the file.
/// - permissions: The file permissions to use for created files.
/// This value must not be `nil` when `options` contains `.create`;
/// passing `nil` in that case is a programmer error and traps at runtime.
/// - retryOnInterrupt: Whether to retry the open operation
/// if it throws ``Errno/interrupted``.
/// The default is `true`.
Expand Down Expand Up @@ -88,8 +92,10 @@ extension FileDescriptor {
if let permissions = permissions {
return system_open(path, oFlag, permissions.rawValue)
}
precondition(!options.contains(.create),
"Create must be given permissions")
if options.contains(.create) {
fatalError(
"FileDescriptor.open: 'permissions' must not be nil when 'options' contains '.create'")
}
return system_open(path, oFlag)
}
return descOrError.map { FileDescriptor(rawValue: $0) }
Expand All @@ -102,6 +108,8 @@ extension FileDescriptor {
/// - mode: The read and write access to use.
/// - options: The behavior for opening the file.
/// - permissions: The file permissions to use for created files.
/// This value must not be `nil` when `options` contains `.create`;
/// passing `nil` in that case is a programmer error and traps at runtime.
/// - retryOnInterrupt: Whether to retry the open operation
/// if it throws ``Errno/interrupted``.
/// The default is `true`.
Expand Down