Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
wip
  • Loading branch information
milseman committed Oct 13, 2022
commit d669abaad4c6f1649ad01ae56a63d20f6dd9c226
56 changes: 0 additions & 56 deletions Sources/System/FileControl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,59 +159,3 @@ extension FileDescriptor {
_ = try fcntl(.setOwner, id.rawValue)
}
}

// MARK: - Removed and should be replaced

// TODO: We don't want to highlight fcntl's highly inadvisable
// ("completely stupid" to quote the man page) locks. Instead, we'd want to provide
// `flock` on Darwin and some Linux equivalent.

#if false

// Record locking
extension FileDescriptor {
/// Get record locking information.
///
/// Get the first lock that blocks the lock description described by `lock`.
/// If no lock is found that would prevent this lock from being created, the
/// structure is left unchanged by this function call except for the lock type
/// which is set to F_UNLCK.
///
/// The corresponding C function is `fcntl` with `F_GETLK`.
@_alwaysEmitIntoClient
public func getLock(blocking lock: FileLock) throws -> FileLock {
var copy = lock
try _fcntlLock(.getLock, &copy, retryOnInterrupt: false).get()
return copy
}

/// Set record locking information.
///
/// Set or clear a file segment lock according to the lock description
/// `lock`.`setLock` is used to establish shared/read locks (`FileLock.read`)
/// or exclusive/write locks, (`FileLock.write`), as well as remove either
/// type of lock (`FileLock.unlock`). If a shared or exclusive lock cannot be
/// set, this throws `Errno.resourceTemporarilyUnavailable`.
///
/// If `waitIfBlocked` is set and a shared or exclusive lock is blocked by
/// other locks, the process waits until the request can be satisfied. If a
/// signal that is to be caught is received while this calls is waiting for a
/// region, the it will be interrupted if the signal handler has not
/// specified the SA_RESTART (see sigaction(2)).
///
/// The corresponding C function is `fcntl` with `F_SETLK`.
@_alwaysEmitIntoClient
public func setLock(
to lock: FileLock,
waitIfBlocked: Bool = false,
retryOnInterrupt: Bool = true
) throws {
let cmd: Command = waitIfBlocked ? .setLockWait : .setLock
var copy = lock
try _fcntlLock(cmd, &copy, retryOnInterrupt: retryOnInterrupt).get()
// TODO: Does `fcntl` update `copy`? Should we return it?
}
}

#endif

29 changes: 3 additions & 26 deletions Sources/System/FileControlRaw.swift
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@ extension FileDescriptor {
@_alwaysEmitIntoClient
public static var async: StatusFlags { StatusFlags(O_ASYNC) }
}


}

// Raw escape hatch
Expand Down Expand Up @@ -104,18 +102,6 @@ extension FileDescriptor {
}
}

//// @usableFromInline
// internal func _fcntlLock(
// _ cmd: Command, _ lock: inout FileLock,
// retryOnInterrupt: Bool
// ) -> Result<(), Errno> {
// nothingOrErrno(retryOnInterrupt: retryOnInterrupt) {
// withUnsafeMutablePointer(to: &lock) {
// system_fcntl(self.rawValue, cmd.rawValue, $0)
// }
// }
// }

/// Commands (and various constants) to pass to `fcntl`.
@frozen
public struct Command: RawRepresentable, Hashable {
Expand Down Expand Up @@ -185,39 +171,33 @@ extension FileDescriptor {
///
/// Note: A Swiftier wrapper is `FileDescriptor.setOwner(_:)`.
///
/// TODO: `setOwner` is pending the `PIDOrPGID` type decision
///
/// The corresponding C constant is `F_SETOWN`.
@_alwaysEmitIntoClient
public static var setOwner: Command { Command(F_SETOWN) }

/// Get record locking information.
///
/// Note: A Swiftier wrapper is `FileDescriptor.getLock(_:_:)`.
///
/// The corresponding C constant is `F_GETLK`.
@_alwaysEmitIntoClient
public static var getLock: Command { Command(F_GETLK) }

/// Set record locking information.
///
/// Note: A Swiftier wrapper is `FileDescriptor.setLock(_:_:)`.
///
/// The corresponding C constant is `F_SETLK`.
@_alwaysEmitIntoClient
public static var setLock: Command { Command(F_SETLK) }

/// Wait if blocked.
///
/// Note: A Swiftier wrapper is `FileDescriptor.setLock(_:_:)`.
///
/// The corresponding C constant is `F_SETLKW`.
@_alwaysEmitIntoClient
public static var setLockWait: Command { Command(F_SETLKW) }

#if !os(Linux)
/// Wait if blocked, return on timeout.
///
/// TODO: A Swiftier wrapper
///
/// The corresponding C constant is `F_SETLKWTIMEOUT`.
@_alwaysEmitIntoClient
public static var setLockWaitTimout: Command {
Expand Down Expand Up @@ -593,10 +573,7 @@ extension FileDescriptor {
Command(F_ALLOCATEALL)
}

/// Make it past all of the SEEK pos modes so that.
///
/// TODO: The above is a direct quote from the header, figure out what it
/// means
/// Allocate from the physical end of file.
///
/// The corresponding C constant is `F_PEOFPOSMODE`.
@_alwaysEmitIntoClient
Expand Down