filemanip icon indicating copy to clipboard operation
filemanip copied to clipboard

Unsafe operations lead to delayed OS responses (such as stderr content)

Open andreasabel opened this issue 2 years ago • 0 comments

find lives in IO, but nevertheless uses unsafePerformIO. https://github.com/bos/filemanip/blob/1ed1659a6459aeb66f4cec588ea1519bb6c26828/System/FilePath/Find.hs#L131 This leads to weird effects. E.g. I experienced that on Windows some warnings cause by find are printed to stderr only after the results produced by find were inspected. This forced me to wrap find into Control.Exceptions.evaluate to trigger the printing of warnings at the correct moment. Details are here: https://github.com/andreasabel/cabal-clean/blob/015cf3d6bda2e7b9118f3b19f50e27c70592d75c/src/DiscoverGHCs.hs#L30-L33

  ghcs <- hSilence [stderr] $ do -- Silence warnings about broken symlinks produced by @find@.
    evaluate =<< do              -- Needed under Windows, otherwise warnings are raised too lazily
                                 -- and not caught by @hSilence@.
      concat <$> mapM (find recursionP filterP) path

unsafePerformIO: Your pact with the devil. Experience pleasure now, pay in eternity.

andreasabel avatar Aug 21 '22 16:08 andreasabel