Move the event mask into a platform-neutral product
`InotifyEventMask` took its bits from the C header, so nothing that imported it could build outside Linux. The new `InotifyMask` product spells out the kernel constants instead; a Linux test compares each of them with the header. `Inotify` re-exports the module, so existing code is unaffected.
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
// The mask lives in its own module so that it is usable off Linux; users
|
||||
// of `Inotify` keep seeing it as before.
|
||||
@_exported import InotifyMask
|
||||
@@ -1,47 +0,0 @@
|
||||
import CInotify
|
||||
|
||||
public struct InotifyEventMask: OptionSet, Sendable, Hashable {
|
||||
public let rawValue: CUnsignedInt
|
||||
|
||||
public init(rawValue: UInt32) {
|
||||
self.rawValue = rawValue
|
||||
}
|
||||
|
||||
// MARK: - Watchable Events
|
||||
|
||||
public static let access = InotifyEventMask(rawValue: CUnsignedInt(IN_ACCESS))
|
||||
public static let attrib = InotifyEventMask(rawValue: CUnsignedInt(IN_ATTRIB))
|
||||
public static let closeWrite = InotifyEventMask(rawValue: CUnsignedInt(IN_CLOSE_WRITE))
|
||||
public static let closeNoWrite = InotifyEventMask(rawValue: CUnsignedInt(IN_CLOSE_NOWRITE))
|
||||
public static let create = InotifyEventMask(rawValue: CUnsignedInt(IN_CREATE))
|
||||
public static let delete = InotifyEventMask(rawValue: CUnsignedInt(IN_DELETE))
|
||||
public static let deleteSelf = InotifyEventMask(rawValue: CUnsignedInt(IN_DELETE_SELF))
|
||||
public static let modify = InotifyEventMask(rawValue: CUnsignedInt(IN_MODIFY))
|
||||
public static let moveSelf = InotifyEventMask(rawValue: CUnsignedInt(IN_MOVE_SELF))
|
||||
public static let movedFrom = InotifyEventMask(rawValue: CUnsignedInt(IN_MOVED_FROM))
|
||||
public static let movedTo = InotifyEventMask(rawValue: CUnsignedInt(IN_MOVED_TO))
|
||||
public static let open = InotifyEventMask(rawValue: CUnsignedInt(IN_OPEN))
|
||||
|
||||
// MARK: - Combinations
|
||||
|
||||
public static let move: InotifyEventMask = [.movedFrom, .movedTo]
|
||||
public static let close: InotifyEventMask = [.closeWrite, .closeNoWrite]
|
||||
public static let allEvents: InotifyEventMask = [
|
||||
.access, .attrib, .closeWrite, .closeNoWrite,
|
||||
.create, .delete, .deleteSelf, .modify,
|
||||
.moveSelf, .movedFrom, .movedTo, .open
|
||||
]
|
||||
|
||||
// MARK: - Watch Flags
|
||||
|
||||
public static let dontFollow = InotifyEventMask(rawValue: CUnsignedInt(IN_DONT_FOLLOW))
|
||||
public static let onlyDir = InotifyEventMask(rawValue: CUnsignedInt(IN_ONLYDIR))
|
||||
public static let oneShot = InotifyEventMask(rawValue: CUnsignedInt(IN_ONESHOT))
|
||||
|
||||
// MARK: - Kernel-Only Flags
|
||||
|
||||
public static let isDir = InotifyEventMask(rawValue: CUnsignedInt(IN_ISDIR))
|
||||
public static let ignored = InotifyEventMask(rawValue: CUnsignedInt(IN_IGNORED))
|
||||
public static let queueOverflow = InotifyEventMask(rawValue: CUnsignedInt(IN_Q_OVERFLOW))
|
||||
public static let unmount = InotifyEventMask(rawValue: CUnsignedInt(IN_UNMOUNT))
|
||||
}
|
||||
Reference in New Issue
Block a user