on master help sign in
Use Bool instead of Switch
commit64aa13dfd612fe2a3e30a7522be46446726d1ab4 authorAdithya Kumar <adithya@composewell.com> dateTue 25 Oct 2022, 14:46 (4 years ago) parent106939a
6 files changed+151−176
src/Streamly/Internal/FileSystem/Event/Darwin.hs+48−55 src/Streamly/Internal/FileSystem/Event/Linux.hs+66−77 src/Streamly/Internal/FileSystem/Event/Windows.hs+32−39 test/Streamly/Test/FileSystem/Event/Darwin.hs+1−1 test/Streamly/Test/FileSystem/Event/Linux.hs+2−2 test/Streamly/Test/FileSystem/Event/Windows.hs+2−2
src/Streamly/Internal/FileSystem/Event/Darwin.hs+48−55
@@ -92,7 +92,6 @@ module Streamly.Internal.FileSystem.Event.Darwin
9292
9393 -- ** Default configuration
9494 Config (..)
95− , Switch (..)
9695 , defaultConfig
9796
9897 -- ** Watch Behavior
@@ -192,7 +191,7 @@ import qualified Streamly.Internal.Data.Array.Unboxed as A
192191-------------------------------------------------------------------------------
193192
194193-- XXX Add a recursive option to Config
195−-- Keep setRecursiveMode Off as undefined for now until we implement it.
194+-- Keep setRecursiveMode False as undefined for now until we implement it.
196195--
197196-- | Watch configuration, used to specify the events of interest and the
198197-- behavior of the watch.
@@ -233,28 +232,22 @@ setEventBatching :: BatchInfo -> Config -> Config
233232setEventBatching batchInfo cfg =
234233 let (t, status) =
235234 case batchInfo of
236− Throttle sec | sec < 0 -> (0, On)
237− Throttle sec -> (sec, On)
238− Batch sec | sec < 0 -> (0, Off)
239− Batch sec -> (sec, Off)
235+ Throttle sec | sec < 0 -> (0, True)
236+ Throttle sec -> (sec, True)
237+ Batch sec | sec < 0 -> (0, False)
238+ Batch sec -> (sec, False)
240239 in setFlag kFSEventStreamCreateFlagNoDefer status $ cfg {latency = t}
241240
242241-------------------------------------------------------------------------------
243242-- Boolean settings
244243-------------------------------------------------------------------------------
245244
246−-- | Whether a setting is 'On' or 'Off'.
247−--
248−-- /Pre-release/
249−--
250−data Switch = On | Off
251−
252−setFlag :: Word32 -> Switch -> Config -> Config
245+setFlag :: Word32 -> Bool -> Config -> Config
253246setFlag mask status cfg@Config{..} =
254247 let flags =
255− case status of
256− On -> createFlags .|. mask
257− Off -> createFlags .&. complement mask
248+ if status
249+ then createFlags .|. mask
250+ else createFlags .&. complement mask
258251 in cfg {createFlags = flags}
259252
260253foreign import ccall safe
@@ -267,26 +260,26 @@ foreign import ccall safe
267260-- | Any changes to the path (delete, rename, or create) of an object are
268261-- reported as events for its parent directory. Such events are not reported
269262-- for the watch root itself because its parent is not being watched. When
270−-- 'setRootPathEvents' is 'On', an 'isRootPathEvent' event is generated with an
263+-- 'setRootPathEvents' is 'True', an 'isRootPathEvent' event is generated with an
271264-- eventId 0 if the watch root is deleted, renamed or created.
272265--
273266-- Note: We have observed that an 'isDeleted' event occurs for the root path
274267-- (when it is a regular dir and not symlink) even when this option is off.
275268--
276−-- /default: Off/
269+-- /default: False/
277270--
278271-- /macOS 10.5+/
279272--
280273-- /Pre-release/
281274--
282−setRootPathEvents :: Switch -> Config -> Config
275+setRootPathEvents :: Bool -> Config -> Config
283276setRootPathEvents = setFlag kFSEventStreamCreateFlagWatchRoot
284277
285278foreign import ccall safe
286279 "FSEventStreamCreateFlagFileEvents"
287280 kFSEventStreamCreateFlagFileEvents :: Word32
288281
289−-- | When this is 'Off' only events for the watched directories are reported.
282+-- | When this is 'False' only events for the watched directories are reported.
290283-- For example, when a file is created inside a directory it is reported as an
291284-- event, the path name in the event is the path of the directory being watched
292285-- and not of the specific item for which the event occurred. Events cannot be
@@ -294,33 +287,33 @@ foreign import ccall safe
294287-- if an event is a "create" or "delete", we only know that some event ocurred
295288-- under the watched directory hierarchy.
296289--
297−-- When it is 'On' the path reported in the event is the path of the item and
290+-- When it is 'True' the path reported in the event is the path of the item and
298291-- not the of the directory in which it is contained. We can use the event
299292-- accessor functions to determine the event type and the path type etc.
300293--
301−-- /default: On/
294+-- /default: True/
302295--
303296-- /macOS 10.7+/
304297--
305298-- /Pre-release/
306299--
307−setFileEvents :: Switch -> Config -> Config
300+setFileEvents :: Bool -> Config -> Config
308301setFileEvents = setFlag kFSEventStreamCreateFlagFileEvents
309302
310303foreign import ccall safe
311304 "FSEventStreamCreateFlagIgnoreSelf"
312305 kFSEventStreamCreateFlagIgnoreSelf :: Word32
313306
314−-- | When this is 'On' events generated by the current process are not
307+-- | When this is 'True' events generated by the current process are not
315308-- reported.
316309--
317−-- /default: Off/
310+-- /default: False/
318311--
319312-- /macOS 10.6+/
320313--
321314-- /Pre-release/
322315--
323−setIgnoreSelf :: Switch -> Config -> Config
316+setIgnoreSelf :: Bool -> Config -> Config
324317setIgnoreSelf = setFlag kFSEventStreamCreateFlagIgnoreSelf
325318
326319#if HAVE_DECL_KFSEVENTSTREAMCREATEFLAGFULLHISTORY
@@ -328,26 +321,26 @@ foreign import ccall safe
328321 "FSEventStreamCreateFlagFullHistory"
329322 kFSEventStreamCreateFlagFullHistory :: Word32
330323
331−-- | When this is 'On' all events since the beginning of time are reported.
324+-- | When this is 'True' all events since the beginning of time are reported.
332325--
333−-- /default: Off/
326+-- /default: False/
334327--
335328-- /macOS 10.15+/
336329--
337330-- /Pre-release/
338331--
339−setFullHistory :: Switch -> Config -> Config
332+setFullHistory :: Bool -> Config -> Config
340333setFullHistory = setFlag kFSEventStreamCreateFlagFullHistory
341334#endif
342335
343−-- | Set all tunable events 'On' or 'Off'. Equivalent to setting:
336+-- | Set all tunable events 'True' or 'False'. Equivalent to setting:
344337--
345338-- * setRootPathEvents
346339-- * setFileEvents
347340--
348341-- /Pre-release/
349342--
350−setAllEvents :: Switch -> Config -> Config
343+setAllEvents :: Bool -> Config -> Config
351344setAllEvents s =
352345 setRootPathEvents s
353346 . setFileEvents s
@@ -359,17 +352,17 @@ setAllEvents s =
359352-- | The default settings are:
360353--
361354-- * 'setEventBatching' ('Batch' 0.0)
362−-- * 'setFileEvents' 'On'
363−-- * 'setRootPathEvents' 'Off'
364−-- * 'setIgnoreSelf' 'Off'
355+-- * 'setFileEvents' 'True'
356+-- * 'setRootPathEvents' 'False'
357+-- * 'setIgnoreSelf' 'False'
365358#if HAVE_DECL_KFSEVENTSTREAMCREATEFLAGFULLHISTORY
366−-- * 'setFullHistory' 'Off'
359+-- * 'setFullHistory' 'False'
367360#endif
368361--
369362-- /Pre-release/
370363--
371364defaultConfig :: Config
372−defaultConfig = setFileEvents On $ Config
365+defaultConfig = setFileEvents True $ Config
373366 { latency = 0.0
374367 , createFlags = 0
375368 }
@@ -559,7 +552,7 @@ watchToStream (Watch handle _ _) =
559552-- @
560553-- {-\# LANGUAGE MagicHash #-}
561554-- watchWith
562−-- ('setIgnoreSelf' 'On' . 'setRootPathEvents' 'On')
555+-- ('setIgnoreSelf' 'True' . 'setRootPathEvents' 'True')
563556-- [Array.fromList "path"]
564557-- @
565558--
@@ -719,7 +712,7 @@ foreign import ccall safe
719712-- object itself. Note that the object may become unreachable or deleted after
720713-- a change of path.
721714--
722−-- /Applicable only when 'setRootPathEvents' is 'On'/
715+-- /Applicable only when 'setRootPathEvents' is 'True'/
723716--
724717-- /Occurs only for the watched path/
725718--
@@ -763,7 +756,7 @@ isUnmounted :: Event -> Bool
763756isUnmounted = getFlag kFSEventStreamEventFlagUnmount
764757
765758-------------------------------------------------------------------------------
766−-- Metadata change Events (applicable only when 'setFileEvents' is 'On')
759+-- Metadata change Events (applicable only when 'setFileEvents' is 'True')
767760-------------------------------------------------------------------------------
768761
769762foreign import ccall safe
@@ -776,7 +769,7 @@ foreign import ccall safe
776769-- Note that this event may be generated even if the metadata is changed to the
777770-- same value again.
778771--
779−-- /Applicable only when 'setFileEvents' is 'On'/
772+-- /Applicable only when 'setFileEvents' is 'True'/
780773--
781774-- /Can occur for watched path or a file inside it/
782775--
@@ -797,7 +790,7 @@ foreign import ccall safe
797790-- modification time. It does not occur when the link count of a file changes
798791-- (as of macOS 10.15.1).
799792--
800−-- /Applicable only when 'setFileEvents' is 'On'/
793+-- /Applicable only when 'setFileEvents' is 'True'/
801794--
802795-- /Can occur for watched path or a file inside it/
803796--
@@ -815,7 +808,7 @@ foreign import ccall safe
815808-- | Determine whether the event indicates finder information metadata change
816809-- for an object contained within the monitored path.
817810--
818−-- /Applicable only when 'setFileEvents' is 'On'/
811+-- /Applicable only when 'setFileEvents' is 'True'/
819812--
820813-- /macOS 10.7+/
821814--
@@ -831,7 +824,7 @@ foreign import ccall safe
831824-- | Determine whether the event indicates extended attributes metadata change
832825-- for an object contained within the monitored path.
833826--
834−-- /Applicable only when 'setFileEvents' is 'On'/
827+-- /Applicable only when 'setFileEvents' is 'True'/
835828--
836829-- /Can occur for watched path or a file inside it/
837830--
@@ -843,7 +836,7 @@ isXAttrsModified :: Event -> Bool
843836isXAttrsModified = getFlag kFSEventStreamEventFlagItemXattrMod
844837
845838-------------------------------------------------------------------------------
846−-- CRUD Events (applicable only when 'setFileEvents' is 'On')
839+-- CRUD Events (applicable only when 'setFileEvents' is 'True')
847840-------------------------------------------------------------------------------
848841
849842foreign import ccall safe
@@ -865,7 +858,7 @@ foreign import ccall safe
865858-- only an 'isAttrsModified' event occurs and there is no 'isCreated'
866859-- event. However, this seems to have been fixed on 10.15.6.
867860--
868−-- /Applicable only when 'setFileEvents' is 'On'/
861+-- /Applicable only when 'setFileEvents' is 'True'/
869862--
870863-- /Can occur for watched path or a file inside it/
871864--
@@ -883,7 +876,7 @@ foreign import ccall safe
883876-- | Determine whether the event indicates deletion of an object within the
884877-- monitored path. This is true when a file or a hardlink is deleted.
885878--
886−-- Applicable only when 'setFileEvents' is 'On'.
879+-- Applicable only when 'setFileEvents' is 'True'.
887880--
888881-- /Can occur for watched path or a file inside it/
889882--
@@ -902,7 +895,7 @@ foreign import ccall safe
902895-- monitored path. This event is generated when a file is renamed within the
903896-- watched directory or if it is moved out of or in the watched directory.
904897--
905−-- /Applicable only when 'setFileEvents' is 'On'/
898+-- /Applicable only when 'setFileEvents' is 'True'/
906899--
907900-- /Can occur for watched path or a file inside it/
908901--
@@ -920,7 +913,7 @@ foreign import ccall safe
920913-- | Determine whether the event indicates modification of an object within the
921914-- monitored path. This event is generated only for files and not directories.
922915--
923−-- Applicable only when 'setFileEvents' is 'On'.
916+-- Applicable only when 'setFileEvents' is 'True'.
924917--
925918-- /macOS 10.7+/
926919--
@@ -938,7 +931,7 @@ foreign import ccall safe
938931-- monitored path. The "Duplicate" command in the "File" menu of the "Finder"
939932-- application generates a "clone" event.
940933--
941−-- Applicable only when 'setFileEvents' is 'On'.
934+-- Applicable only when 'setFileEvents' is 'True'.
942935--
943936-- /macOS 10.13+/
944937--
@@ -949,7 +942,7 @@ isCloned = getFlag kFSEventStreamEventFlagItemCloned
949942#endif
950943
951944-------------------------------------------------------------------------------
952−-- Information about path type (applicable only when 'setFileEvents' is 'On')
945+-- Information about path type (applicable only when 'setFileEvents' is 'True')
953946-------------------------------------------------------------------------------
954947
955948foreign import ccall safe
@@ -958,7 +951,7 @@ foreign import ccall safe
958951
959952-- | Determine whether the event is for a directory path.
960953--
961−-- Applicable only when 'setFileEvents' is 'On'.
954+-- Applicable only when 'setFileEvents' is 'True'.
962955--
963956-- /macOS 10.7+/
964957--
@@ -973,7 +966,7 @@ foreign import ccall safe
973966
974967-- | Determine whether the event is for a file path.
975968--
976−-- Applicable only when 'setFileEvents' is 'On'.
969+-- Applicable only when 'setFileEvents' is 'True'.
977970--
978971-- /macOS 10.7+/
979972--
@@ -988,7 +981,7 @@ foreign import ccall safe
988981
989982-- | Determine whether the event is for a symbolic link path.
990983--
991−-- Applicable only when 'setFileEvents' is 'On'.
984+-- Applicable only when 'setFileEvents' is 'True'.
992985--
993986-- /macOS 10.7+/
994987--
@@ -1008,7 +1001,7 @@ foreign import ccall safe
10081001-- which has or had more than one link in the past is removed. This is not true
10091002-- if a file never had more than one link.
10101003--
1011−-- Applicable only when 'setFileEvents' is 'On'.
1004+-- Applicable only when 'setFileEvents' is 'True'.
10121005--
10131006-- /macOS 10.10+/
10141007--
@@ -1026,7 +1019,7 @@ foreign import ccall safe
10261019-- is true when a file has had more than one link and now the last link is
10271020-- removed. In that case both 'isHardLink' and 'isLastHardLink" would be true.
10281021--
1029−-- Applicable only when 'setFileEvents' is 'On'.
1022+-- Applicable only when 'setFileEvents' is 'True'.
10301023--
10311024-- /macOS 10.10+/
10321025--
src/Streamly/Internal/FileSystem/Event/Linux.hs+66−77
@@ -64,7 +64,6 @@ module Streamly.Internal.FileSystem.Event.Linux
6464
6565 -- ** Default configuration
6666 Config (..)
67− , Switch (..)
6867 , defaultConfig
6968
7069 -- ** Watch Behavior
@@ -208,22 +207,12 @@ data Config = Config
208207-- Boolean settings
209208-------------------------------------------------------------------------------
210209
211−-- | Whether a setting is 'On' or 'Off'.
212−--
213−-- /Pre-release/
214−--
215−data Switch = On | Off deriving (Show, Eq)
216−
217−toggle :: Switch -> Switch
218−toggle On = Off
219−toggle Off = On
220−
221−setFlag :: Word32 -> Switch -> Config -> Config
210+setFlag :: Word32 -> Bool -> Config -> Config
222211setFlag mask status cfg@Config{..} =
223212 let flags =
224− case status of
225− On -> createFlags .|. mask
226− Off -> createFlags .&. complement mask
213+ if status
214+ then createFlags .|. mask
215+ else createFlags .&. complement mask
227216 in cfg {createFlags = flags}
228217
229218-------------------------------------------------------------------------------
@@ -233,12 +222,12 @@ setFlag mask status cfg@Config{..} =
233222-- | Watch the whole directory tree recursively instead of watching just one
234223-- level of directory.
235224--
236−-- /default: Off/
225+-- /default: False/
237226--
238227-- /Pre-release/
239228--
240−setRecursiveMode :: Switch -> Config -> Config
241−setRecursiveMode rec cfg@Config{} = cfg {watchRec = rec == On}
229+setRecursiveMode :: Bool -> Config -> Config
230+setRecursiveMode recursive cfg@Config{} = cfg {watchRec = recursive}
242231
243232foreign import capi
244233 "sys/inotify.h value IN_DONT_FOLLOW" iN_DONT_FOLLOW :: Word32
@@ -249,12 +238,12 @@ foreign import capi
249238-- Note that the path location in the events is through the original symbolic
250239-- link path rather than the resolved path.
251240--
252−-- /default: On/
241+-- /default: True/
253242--
254243-- /Pre-release/
255244--
256−setFollowSymLinks :: Switch -> Config -> Config
257−setFollowSymLinks s = setFlag iN_DONT_FOLLOW (toggle s)
245+setFollowSymLinks :: Bool -> Config -> Config
246+setFollowSymLinks s = setFlag iN_DONT_FOLLOW (not s)
258247
259248foreign import capi
260249 "sys/inotify.h value IN_EXCL_UNLINK" iN_EXCL_UNLINK :: Word32
@@ -262,11 +251,11 @@ foreign import capi
262251-- | If an object moves out of the directory being watched then stop watching
263252-- it.
264253--
265−-- /default: On/
254+-- /default: True/
266255--
267256-- /Pre-release/
268257--
269−setUnwatchMoved :: Switch -> Config -> Config
258+setUnwatchMoved :: Bool -> Config -> Config
270259setUnwatchMoved = setFlag iN_EXCL_UNLINK
271260
272261#if HAVE_DECL_IN_MASK_CREATE
@@ -283,7 +272,7 @@ foreign import capi
283272-- /Pre-release/
284273--
285274data WhenExists =
286− AddIfExists -- ^ Do not set an existing setting to 'Off' only set to 'On'
275+ AddIfExists -- ^ Do not set an existing setting to 'False' only set to 'True'
287276 | ReplaceIfExists -- ^ Replace the existing settings with new settings
288277#if HAVE_DECL_IN_MASK_CREATE
289278 | FailIfExists -- ^ Fail the API
@@ -299,10 +288,10 @@ data WhenExists =
299288setWhenExists :: WhenExists -> Config -> Config
300289setWhenExists val cfg =
301290 case val of
302− AddIfExists -> setFlag iN_MASK_ADD On cfg
303− ReplaceIfExists -> setFlag iN_MASK_ADD Off cfg
291+ AddIfExists -> setFlag iN_MASK_ADD True cfg
292+ ReplaceIfExists -> setFlag iN_MASK_ADD False cfg
304293#if HAVE_DECL_IN_MASK_CREATE
305− FailIfExists -> setFlag iN_MASK_CREATE On cfg
294+ FailIfExists -> setFlag iN_MASK_CREATE True cfg
306295#endif
307296
308297foreign import capi
@@ -310,11 +299,11 @@ foreign import capi
310299
311300-- | Watch the object only for one event and then remove it from the watch.
312301--
313−-- /default: Off/
302+-- /default: False/
314303--
315304-- /Pre-release/
316305--
317−setOneShot :: Switch -> Config -> Config
306+setOneShot :: Bool -> Config -> Config
318307setOneShot = setFlag iN_ONESHOT
319308
320309foreign import capi
@@ -323,11 +312,11 @@ foreign import capi
323312-- | Watch the object only if it is a directory. This provides a race-free way
324313-- to ensure that the watched object is a directory.
325314--
326−-- /default: Off/
315+-- /default: False/
327316--
328317-- /Pre-release/
329318--
330−setOnlyDir :: Switch -> Config -> Config
319+setOnlyDir :: Bool -> Config -> Config
331320setOnlyDir = setFlag iN_ONLYDIR
332321
333322-------------------------------------------------------------------------------
@@ -339,11 +328,11 @@ foreign import capi
339328
340329-- | Report when the watched path itself gets deleted.
341330--
342−-- /default: On/
331+-- /default: True/
343332--
344333-- /Pre-release/
345334--
346−setRootDeleted :: Switch -> Config -> Config
335+setRootDeleted :: Bool -> Config -> Config
347336setRootDeleted = setFlag iN_DELETE_SELF
348337
349338foreign import capi
@@ -351,20 +340,20 @@ foreign import capi
351340
352341-- | Report when the watched root path itself gets renamed.
353342--
354−-- /default: On/
343+-- /default: True/
355344--
356345-- /Pre-release/
357346--
358−setRootMoved :: Switch -> Config -> Config
347+setRootMoved :: Bool -> Config -> Config
359348setRootMoved = setFlag iN_MOVE_SELF
360349
361350-- | Report when the watched root path itself gets deleted or renamed.
362351--
363−-- /default: On/
352+-- /default: True/
364353--
365354-- /Pre-release/
366355--
367−setRootPathEvents :: Switch -> Config -> Config
356+setRootPathEvents :: Bool -> Config -> Config
368357setRootPathEvents = setFlag (iN_DELETE_SELF .|. iN_MOVE_SELF)
369358
370359foreign import capi
@@ -373,11 +362,11 @@ foreign import capi
373362-- | Report when the metadata e.g. owner, permission modes, modifications times
374363-- of an object changes.
375364--
376−-- /default: On/
365+-- /default: True/
377366--
378367-- /Pre-release/
379368--
380−setAttrsModified :: Switch -> Config -> Config
369+setAttrsModified :: Bool -> Config -> Config
381370setAttrsModified = setFlag iN_ATTRIB
382371
383372foreign import capi
@@ -385,11 +374,11 @@ foreign import capi
385374
386375-- | Report when a file is accessed.
387376--
388−-- /default: On/
377+-- /default: True/
389378--
390379-- /Pre-release/
391380--
392−setAccessed :: Switch -> Config -> Config
381+setAccessed :: Bool -> Config -> Config
393382setAccessed = setFlag iN_ACCESS
394383
395384foreign import capi
@@ -397,11 +386,11 @@ foreign import capi
397386
398387-- | Report when a file is opened.
399388--
400−-- /default: On/
389+-- /default: True/
401390--
402391-- /Pre-release/
403392--
404−setOpened :: Switch -> Config -> Config
393+setOpened :: Bool -> Config -> Config
405394setOpened = setFlag iN_OPEN
406395
407396foreign import capi
@@ -409,11 +398,11 @@ foreign import capi
409398
410399-- | Report when a file that was opened for writes is closed.
411400--
412−-- /default: On/
401+-- /default: True/
413402--
414403-- /Pre-release/
415404--
416−setWriteClosed :: Switch -> Config -> Config
405+setWriteClosed :: Bool -> Config -> Config
417406setWriteClosed = setFlag iN_CLOSE_WRITE
418407
419408foreign import capi
@@ -421,11 +410,11 @@ foreign import capi
421410
422411-- | Report when a file that was opened for not writing is closed.
423412--
424−-- /default: On/
413+-- /default: True/
425414--
426415-- /Pre-release/
427416--
428−setNonWriteClosed :: Switch -> Config -> Config
417+setNonWriteClosed :: Bool -> Config -> Config
429418setNonWriteClosed = setFlag iN_CLOSE_NOWRITE
430419
431420foreign import capi
@@ -433,11 +422,11 @@ foreign import capi
433422
434423-- | Report when a file is created.
435424--
436−-- /default: On/
425+-- /default: True/
437426--
438427-- /Pre-release/
439428--
440−setCreated :: Switch -> Config -> Config
429+setCreated :: Bool -> Config -> Config
441430setCreated = setFlag iN_CREATE
442431
443432foreign import capi
@@ -445,11 +434,11 @@ foreign import capi
445434
446435-- | Report when a file is deleted.
447436--
448−-- /default: On/
437+-- /default: True/
449438--
450439-- /Pre-release/
451440--
452−setDeleted :: Switch -> Config -> Config
441+setDeleted :: Bool -> Config -> Config
453442setDeleted = setFlag iN_DELETE
454443
455444foreign import capi
@@ -457,11 +446,11 @@ foreign import capi
457446
458447-- | Report the source of a move.
459448--
460−-- /default: On/
449+-- /default: True/
461450--
462451-- /Pre-release/
463452--
464−setMovedFrom :: Switch -> Config -> Config
453+setMovedFrom :: Bool -> Config -> Config
465454setMovedFrom = setFlag iN_MOVED_FROM
466455
467456foreign import capi
@@ -469,11 +458,11 @@ foreign import capi
469458
470459-- | Report the target of a move.
471460--
472−-- /default: On/
461+-- /default: True/
473462--
474463-- /Pre-release/
475464--
476−setMovedTo :: Switch -> Config -> Config
465+setMovedTo :: Bool -> Config -> Config
477466setMovedTo = setFlag iN_MOVED_TO
478467
479468foreign import capi
@@ -481,14 +470,14 @@ foreign import capi
481470
482471-- | Report when a file is modified.
483472--
484−-- /default: On/
473+-- /default: True/
485474--
486475-- /Pre-release/
487476--
488−setModified :: Switch -> Config -> Config
477+setModified :: Bool -> Config -> Config
489478setModified = setFlag iN_MODIFY
490479
491−-- | Set all tunable events 'On' or 'Off'. Equivalent to setting:
480+-- | Set all tunable events 'True' or 'False'. Equivalent to setting:
492481--
493482-- * setRootDeleted
494483-- * setRootMoved
@@ -505,7 +494,7 @@ setModified = setFlag iN_MODIFY
505494--
506495-- /Pre-release/
507496--
508−setAllEvents :: Switch -> Config -> Config
497+setAllEvents :: Bool -> Config -> Config
509498setAllEvents s =
510499 setRootDeleted s
511500 . setRootMoved s
@@ -529,30 +518,30 @@ setAllEvents s =
529518--
530519-- | The default configuration settings are:
531520--
532−-- * 'setFollowSymLinks' 'On'
533−-- * 'setUnwatchMoved' 'On'
534−-- * 'setOneShot' 'Off'
535−-- * 'setOnlyDir' 'Off'
521+-- * 'setFollowSymLinks' 'True'
522+-- * 'setUnwatchMoved' 'True'
523+-- * 'setOneShot' 'False'
524+-- * 'setOnlyDir' 'False'
536525-- * 'setWhenExists' 'AddIfExists'
537526--
538527-- The tunable events enabled by default are:
539528--
540−-- * setCreated On
541−-- * setDeleted On
542−-- * setMovedFrom On
543−-- * setMovedTo On
544−-- * setModified On
529+-- * setCreated True
530+-- * setDeleted True
531+-- * setMovedFrom True
532+-- * setMovedTo True
533+-- * setModified True
545534--
546535-- /Pre-release/
547536--
548537defaultConfig :: Config
549538defaultConfig =
550539 setWhenExists AddIfExists
551− $ setCreated On
552− $ setDeleted On
553− $ setMovedFrom On
554− $ setMovedTo On
555− $ setModified On
540+ $ setCreated True
541+ $ setDeleted True
542+ $ setMovedFrom True
543+ $ setMovedTo True
544+ $ setModified True
556545 $ Config
557546 { watchRec = False
558547 , createFlags = 0
@@ -911,7 +900,7 @@ watchToStream cfg wt@(Watch handle _) = do
911900--
912901-- @
913902-- watchwith
914−-- ('setFollowSymLinks' On . 'setUnwatchMoved' Off)
903+-- ('setFollowSymLinks' True . 'setUnwatchMoved' False)
915904-- [Array.fromList "dir"]
916905-- @
917906--
@@ -928,14 +917,14 @@ watchWith f paths = S.bracketIO before after (watchToStream cfg)
928917
929918-- | Same as 'watchWith' using 'defaultConfig' and recursive mode.
930919--
931−-- >>> watchRecursive = watchWith (setRecursiveMode On)
920+-- >>> watchRecursive = watchWith (setRecursiveMode True)
932921--
933922-- See 'watchWith' for pitfalls and bugs when using recursive watch on Linux.
934923--
935924-- /Pre-release/
936925--
937926watchRecursive :: NonEmpty (Array Word8) -> Stream IO Event
938−watchRecursive = watchWith (setRecursiveMode On)
927+watchRecursive = watchWith (setRecursiveMode True)
939928
940929-- | Same as 'watchWith' using defaultConfig and non-recursive mode.
941930--
@@ -1242,7 +1231,7 @@ isModified :: Event -> Bool
12421231isModified = getFlag iN_MODIFY
12431232
12441233-------------------------------------------------------------------------------
1245−-- Information about path type (applicable only when 'setFileEvents' is 'On')
1234+-- Information about path type (applicable only when 'setFileEvents' is 'True')
12461235-------------------------------------------------------------------------------
12471236
12481237foreign import capi
src/Streamly/Internal/FileSystem/Event/Windows.hs+32−39
@@ -48,7 +48,6 @@ module Streamly.Internal.FileSystem.Event.Windows
4848
4949 -- ** Default configuration
5050 Config
51− , Switch (..)
5251 , defaultConfig
5352
5453 -- ** Watch Behavior
@@ -142,28 +141,22 @@ data Config = Config
142141-- Boolean settings
143142-------------------------------------------------------------------------------
144143
145−-- | Whether a setting is 'On' or 'Off'.
146−--
147−-- /Pre-release/
148−--
149−data Switch = On | Off deriving (Show, Eq)
150−
151−setFlag :: DWORD -> Switch -> Config -> Config
144+setFlag :: DWORD -> Bool -> Config -> Config
152145setFlag mask status cfg@Config{..} =
153146 let flags =
154− case status of
155− On -> createFlags .|. mask
156− Off -> createFlags .&. complement mask
147+ if status
148+ then createFlags .|. mask
149+ else createFlags .&. complement mask
157150 in cfg {createFlags = flags}
158151
159152-- | Set watch event on directory recursively.
160153--
161−-- /default: Off/
154+-- /default: False/
162155--
163156-- /Pre-release/
164157--
165−setRecursiveMode :: Switch -> Config -> Config
166−setRecursiveMode rec cfg@Config{} = cfg {watchRec = rec == On}
158+setRecursiveMode :: Bool -> Config -> Config
159+setRecursiveMode recursive cfg@Config{} = cfg {watchRec = recursive}
167160
168161-- | Generate notify events on file create, rename or delete.
169162--
@@ -171,11 +164,11 @@ setRecursiveMode rec cfg@Config{} = cfg {watchRec = rec == On}
171164-- directory or subtree causes a change notification wait operation to return.
172165-- Changes include renaming, creating, or deleting a file.
173166--
174−-- /default: On/
167+-- /default: True/
175168--
176169-- /Pre-release/
177170--
178−setFileNameEvents :: Switch -> Config -> Config
171+setFileNameEvents :: Bool -> Config -> Config
179172setFileNameEvents = setFlag fILE_NOTIFY_CHANGE_FILE_NAME
180173
181174-- | Generate notify events on directory create, rename or delete.
@@ -184,21 +177,21 @@ setFileNameEvents = setFlag fILE_NOTIFY_CHANGE_FILE_NAME
184177-- directory or subtree causes a change notification wait operation to return.
185178-- Changes include creating or deleting a directory.
186179--
187−-- /default: On/
180+-- /default: True/
188181--
189182-- /Pre-release/
190183--
191−setDirNameEvents :: Switch -> Config -> Config
184+setDirNameEvents :: Bool -> Config -> Config
192185setDirNameEvents = setFlag fILE_NOTIFY_CHANGE_DIR_NAME
193186
194187-- | Generate an 'isModified' event on any attribute change in the watched
195188-- directory or subtree.
196189--
197−-- /default: Off/
190+-- /default: False/
198191--
199192-- /Pre-release/
200193--
201−setAttrsModified :: Switch -> Config -> Config
194+setAttrsModified :: Bool -> Config -> Config
202195setAttrsModified = setFlag fILE_NOTIFY_CHANGE_ATTRIBUTES
203196
204197-- | Generate an 'isModified' event when the file size is changed.
@@ -209,11 +202,11 @@ setAttrsModified = setFlag fILE_NOTIFY_CHANGE_ATTRIBUTES
209202-- written to the disk. For operating systems that use extensive caching,
210203-- detection occurs only when the cache is sufficiently flushed.
211204--
212−-- /default: Off/
205+-- /default: False/
213206--
214207-- /Pre-release/
215208--
216−setSizeModified :: Switch -> Config -> Config
209+setSizeModified :: Bool -> Config -> Config
217210setSizeModified = setFlag fILE_NOTIFY_CHANGE_SIZE
218211
219212-- | Generate an 'isModified' event when the last write timestamp of the file
@@ -226,24 +219,24 @@ setSizeModified = setFlag fILE_NOTIFY_CHANGE_SIZE
226219-- that use extensive caching, detection occurs only when the cache is
227220-- sufficiently flushed.
228221--
229−-- /default: Off/
222+-- /default: False/
230223--
231224-- /Pre-release/
232225--
233−setLastWriteTimeModified :: Switch -> Config -> Config
226+setLastWriteTimeModified :: Bool -> Config -> Config
234227setLastWriteTimeModified = setFlag fILE_NOTIFY_CHANGE_LAST_WRITE
235228
236229-- | Generate an 'isModified' event when any security-descriptor change occurs
237230-- in the watched directory or subtree.
238231--
239−-- /default: Off/
232+-- /default: False/
240233--
241234-- /Pre-release/
242235--
243−setSecurityModified :: Switch -> Config -> Config
236+setSecurityModified :: Bool -> Config -> Config
244237setSecurityModified = setFlag fILE_NOTIFY_CHANGE_SECURITY
245238
246−-- | Set all tunable events 'On' or 'Off'. Equivalent to setting:
239+-- | Set all tunable events 'True' or 'False'. Equivalent to setting:
247240--
248241-- * setFileNameEvents
249242-- * setDirNameEvents
@@ -254,7 +247,7 @@ setSecurityModified = setFlag fILE_NOTIFY_CHANGE_SECURITY
254247--
255248-- /Pre-release/
256249--
257−setAllEvents :: Switch -> Config -> Config
250+setAllEvents :: Bool -> Config -> Config
258251setAllEvents s =
259252 setFileNameEvents s
260253 . setDirNameEvents s
@@ -265,19 +258,19 @@ setAllEvents s =
265258
266259-- | The tunable events that are enabled by default are:
267260--
268−-- * setFileNameEvents On
269−-- * setDirNameEvents On
270−-- * setSizeModified On
271−-- * setLastWriteTimeModified On
261+-- * setFileNameEvents True
262+-- * setDirNameEvents True
263+-- * setSizeModified True
264+-- * setLastWriteTimeModified True
272265--
273266-- /Pre-release/
274267--
275268defaultConfig :: Config
276269defaultConfig =
277− setFileNameEvents On
278− $ setDirNameEvents On
279− $ setSizeModified On
280− $ setLastWriteTimeModified On
270+ setFileNameEvents True
271+ $ setDirNameEvents True
272+ $ setSizeModified True
273+ $ setLastWriteTimeModified True
281274 $ Config {watchRec = False, createFlags = 0}
282275
283276getConfigFlag :: Config -> DWORD
@@ -470,7 +463,7 @@ closePathHandleStream =
470463--
471464-- @
472465-- watchWith
473−-- ('setAttrsModified' On . 'setLastWriteTimeModified' Off)
466+-- ('setAttrsModified' True . 'setLastWriteTimeModified' False)
474467-- [Array.fromList "dir"]
475468-- @
476469--
@@ -487,12 +480,12 @@ watchWith f paths =
487480
488481-- | Same as 'watchWith' using 'defaultConfig' and recursive mode.
489482--
490−-- >>> watchRecursive = watchWith (setRecursiveMode On)
483+-- >>> watchRecursive = watchWith (setRecursiveMode True)
491484--
492485-- /Pre-release/
493486--
494487watchRecursive :: NonEmpty (Array Word8) -> Stream IO Event
495−watchRecursive = watchWith (setRecursiveMode On)
488+watchRecursive = watchWith (setRecursiveMode True)
496489
497490-- | Same as 'watchWith' using defaultConfig and non-recursive mode.
498491--
test/Streamly/Test/FileSystem/Event/Darwin.hs+1−1
@@ -78,7 +78,7 @@ main = do
7878 , fileModify "" (const [])
7979 ]
8080
81− let w = Event.watchWith (Event.setAllEvents Event.On)
81+ let w = Event.watchWith (Event.setAllEvents True)
8282 run = runTests moduleName "recursive" w
8383
8484 run DirType regularRootTests
test/Streamly/Test/FileSystem/Event/Linux.hs+2−2
@@ -96,7 +96,7 @@ main = do
9696 -- No events occur when a symlink root is moved
9797 : regSymTests
9898
99− let w = Event.watchWith (Event.setAllEvents Event.On)
99+ let w = Event.watchWith (Event.setAllEvents True)
100100 run = runTests moduleName "non-recursive" w
101101
102102 run DirType regTests
@@ -142,7 +142,7 @@ main = do
142142 recSymTests = symTests ++ regSymRecTests
143143
144144 let recw = Event.watchWith
145− (Event.setAllEvents Event.On . Event.setRecursiveMode Event.On)
145+ (Event.setAllEvents True . Event.setRecursiveMode True)
146146 runRec = runTests moduleName "recursive" recw
147147
148148 runRec DirType recRegTests
test/Streamly/Test/FileSystem/Event/Windows.hs+2−2
@@ -30,7 +30,7 @@ main = do
3030 --
3131 -- ++ dirDelete "" (\dir -> [(dir, Event.isDeleted)])
3232
33− let w = Event.watchWith (Event.setAllEvents Event.On)
33+ let w = Event.watchWith (Event.setAllEvents True)
3434 run = runTests moduleName "non-recursive" w
3535
3636 run DirType regularRootTests
@@ -44,7 +44,7 @@ main = do
4444 ] ++ commonRecTests
4545
4646 let recw = Event.watchWith
47− (Event.setAllEvents Event.On . Event.setRecursiveMode Event.On)
47+ (Event.setAllEvents True . Event.setRecursiveMode True)
4848 runRec = runTests moduleName "recursive" recw
4949
5050 runRec DirType (regularRootTests ++ recTests)