safeio 0.0.4.0 → 0.0.5.0
raw patch · 4 files changed
+90/−58 lines, 4 filesdep +exceptions
Dependencies added: exceptions
Files
- ChangeLog +4/−0
- Data/Conduit/SafeWrite.hs +3/−1
- System/IO/SafeWrite.hs +17/−10
- safeio.cabal +66/−47
ChangeLog view
@@ -1,3 +1,7 @@+Version 0.0.5.0 2018-01-18 by luispedro+ * Deprecate safeSinkFile+ * Add fake Windows support+ Version 0.0.4.0 2017-09-07 by luispedro * Add atomicConduitUseFile
Data/Conduit/SafeWrite.hs view
@@ -14,10 +14,12 @@ import System.IO.SafeWrite (allocateTempFile, finalizeTempFile) --- | Write to file |finalname| using a temporary file and atomic move.+-- | Write to file 'finalname' using a temporary file and atomic move. -- -- The file is only written if the sink runs to completion without errors. Any -- form of early termination will cause the output to be removed.+--+-- This function is deprecated in favor of 'Data.Conduit.Binary.SinkFileCautious' safeSinkFile :: (MonadResource m) => FilePath -- ^ Final filename -> C.Sink B.ByteString m ()
System/IO/SafeWrite.hs view
@@ -6,18 +6,22 @@ ) where import System.FilePath (takeDirectory, takeBaseName)-import System.Posix.IO (openFd, defaultFileFlags, closeFd, OpenMode(..))-import System.Posix.Unistd (fileSynchronise)-import Control.Exception (bracket, bracketOnError)+import Control.Monad.Catch (bracket, bracketOnError, MonadMask(..))+import Control.Monad.IO.Class (MonadIO(..)) import System.IO (Handle, hClose, openTempFile) import System.Directory (renameFile, removeFile) +#ifndef WINDOWS+import System.Posix.IO (openFd, defaultFileFlags, closeFd, OpenMode(..))+import System.Posix.Unistd (fileSynchronise)+#endif -- | Sync a file to disk ----- Only supported on Posix (patches with Windows support are welcome)+-- On Windows, this is a fake function. syncFile :: FilePath -- ^ File to sync -> IO ()+#ifndef WINDOWS syncFile fname = do bracket (openFd fname ReadWrite Nothing defaultFileFlags) closeFd@@ -26,6 +30,9 @@ bracket (openFd (takeDirectory fname) ReadOnly Nothing defaultFileFlags) closeFd fileSynchronise+#else+syncFile fname = return ()+#endif -- | Variation of 'withFile' for output files. --@@ -35,17 +42,17 @@ -- raised, then the temporary output file will be deleted and not saved to -- disk. Thus, the result file will either contain the complete result or will -- be empty.-withOutputFile ::+withOutputFile :: (MonadMask m, MonadIO m) => FilePath -- ^ Final desired file path- -> (Handle -> IO a) -- ^ action to execute- -> IO a+ -> (Handle -> m a) -- ^ action to execute+ -> m a withOutputFile finalname act = bracketOnError- (allocateTempFile finalname)- (finalizeTempFile finalname False)+ (liftIO $ allocateTempFile finalname)+ (liftIO . finalizeTempFile finalname False) (\tdata@(_, th) -> do r <- act th- finalizeTempFile finalname True tdata+ liftIO $ finalizeTempFile finalname True tdata return r) allocateTempFile :: FilePath -> IO (FilePath, Handle)
safeio.cabal view
@@ -1,56 +1,75 @@-name: safeio-version: 0.0.4.0-synopsis: Write output to disk atomically-description: This package implements utilities to perform atomic output- so as to avoid the problem of partial intermediate files.-category: IO-author: Luis Pedro Coelho-maintainer: Luis Pedro Coelho-license: MIT-license-file: COPYING-cabal-version: >= 1.10-build-type: Simple-bug-reports: https://github.com/luispedro/safeio/issues-extra-source-files: README.md ChangeLog+-- This file has been generated from package.yaml by hpack version 0.18.1.+--+-- see: https://github.com/sol/hpack +name: safeio+version: 0.0.5.0+synopsis: Write output to disk atomically+description: This package implements utilities to perform atomic output so as to avoid the problem of partial intermediate files.+category: IO+homepage: https://github.com/luispedro/safeio#readme+bug-reports: https://github.com/luispedro/safeio/issues+author: Luis Pedro Coelho+maintainer: Luis Pedro Coelho+license: MIT+license-file: COPYING+build-type: Simple+cabal-version: >= 1.10++extra-source-files:+ ChangeLog+ README.md++source-repository head+ type: git+ location: https://github.com/luispedro/safeio+ library- default-language: Haskell2010- exposed-modules: System.IO.SafeWrite,- Data.Conduit.SafeWrite+ hs-source-dirs:+ ./+ default-extensions: BangPatterns OverloadedStrings CPP ghc-options: -Wall build-depends:- base > 4.8 && < 5,- bytestring,- conduit >= 1.0,- conduit-combinators,- directory,- filepath,- resourcet,- unix--Test-Suite safeiotest+ base > 4.8 && < 5+ , bytestring+ , conduit >= 1.0+ , conduit-combinators+ , directory+ , exceptions+ , filepath+ , resourcet+ , unix+ if os(windows)+ cpp-options: -DWINDOWS+ exposed-modules:+ System.IO.SafeWrite+ Data.Conduit.SafeWrite default-language: Haskell2010++test-suite safeiotest type: exitcode-stdio-1.0 main-is: System/IO/SafeWrite/Tests.hs- other-modules:- System.IO.SafeWrite- Data.Conduit.SafeWrite+ hs-source-dirs:+ ./+ default-extensions: BangPatterns OverloadedStrings CPP ghc-options: -Wall- hs-source-dirs: . build-depends:- base > 4.8 && < 5,- bytestring,- conduit >= 1.0,- conduit-combinators,- directory,- filepath,- resourcet,- unix,- HUnit,- test-framework,- test-framework-hunit,- test-framework-th--source-repository head- type: git- location: https://github.com/luispedro/safeio+ base > 4.8 && < 5+ , bytestring+ , conduit >= 1.0+ , conduit-combinators+ , directory+ , exceptions+ , filepath+ , resourcet+ , unix+ , HUnit+ , test-framework+ , test-framework-hunit+ , test-framework-th+ if os(windows)+ cpp-options: -DWINDOWS+ other-modules:+ Data.Conduit.SafeWrite+ System.IO.SafeWrite+ default-language: Haskell2010