packages feed

atomic-write 0.2.0.6 → 0.2.0.7

raw patch · 21 files changed

+1076/−88 lines, 21 filesPVP: minor bump suggested

API additions: PVP suggests at least a minor version bump

API changes (from Hackage documentation)

+ System.AtomicWrite.Writer.ByteString.Binary: atomicWriteFile :: FilePath -> ByteString -> IO ()
+ System.AtomicWrite.Writer.ByteString.Binary: atomicWriteFileWithMode :: FileMode -> FilePath -> ByteString -> IO ()
+ System.AtomicWrite.Writer.LazyByteString.Binary: atomicWriteFile :: FilePath -> ByteString -> IO ()
+ System.AtomicWrite.Writer.LazyByteString.Binary: atomicWriteFileWithMode :: FileMode -> FilePath -> ByteString -> IO ()
+ System.AtomicWrite.Writer.LazyText.Binary: atomicWriteFile :: FilePath -> Text -> IO ()
+ System.AtomicWrite.Writer.LazyText.Binary: atomicWriteFileWithMode :: FileMode -> FilePath -> Text -> IO ()
+ System.AtomicWrite.Writer.String.Binary: atomicWithFile :: FilePath -> (Handle -> IO ()) -> IO ()
+ System.AtomicWrite.Writer.String.Binary: atomicWithFileAndMode :: FileMode -> FilePath -> (Handle -> IO ()) -> IO ()
+ System.AtomicWrite.Writer.String.Binary: atomicWriteFile :: FilePath -> String -> IO ()
+ System.AtomicWrite.Writer.String.Binary: atomicWriteFileWithMode :: FileMode -> FilePath -> String -> IO ()
+ System.AtomicWrite.Writer.Text.Binary: atomicWriteFile :: FilePath -> Text -> IO ()
+ System.AtomicWrite.Writer.Text.Binary: atomicWriteFileWithMode :: FileMode -> FilePath -> Text -> IO ()

Files

LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2015-2018 Stack Builders Inc.+Copyright (c) 2015-2019 Stack Builders Inc.  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the
atomic-write.cabal view
@@ -1,5 +1,5 @@ name:                atomic-write-version:             0.2.0.6+version:             0.2.0.7 synopsis:            Atomically write to a file homepage:            https://github.com/stackbuilders/atomic-write description:@@ -43,7 +43,7 @@ license-file:        LICENSE author:              Justin Leitgeb maintainer:          support@stackbuilders.com-copyright:           2015-2018 Stack Builders Inc.+copyright:           2015-2019 Stack Builders Inc. category:            System build-type:          Simple cabal-version:       >=1.10@@ -51,11 +51,16 @@  library   exposed-modules:       System.AtomicWrite.Writer.ByteString+                       , System.AtomicWrite.Writer.ByteString.Binary                        , System.AtomicWrite.Writer.ByteStringBuilder                        , System.AtomicWrite.Writer.LazyByteString+                       , System.AtomicWrite.Writer.LazyByteString.Binary                        , System.AtomicWrite.Writer.String+                       , System.AtomicWrite.Writer.String.Binary                        , System.AtomicWrite.Writer.Text+                       , System.AtomicWrite.Writer.Text.Binary                        , System.AtomicWrite.Writer.LazyText+                       , System.AtomicWrite.Writer.LazyText.Binary    other-modules:       System.AtomicWrite.Internal @@ -78,11 +83,16 @@   main-is: Spec.hs    other-modules:       System.AtomicWrite.Writer.ByteStringSpec+                     , System.AtomicWrite.Writer.ByteString.BinarySpec                      , System.AtomicWrite.Writer.ByteStringBuilderSpec                      , System.AtomicWrite.Writer.LazyByteStringSpec+                     , System.AtomicWrite.Writer.LazyByteString.BinarySpec                      , System.AtomicWrite.Writer.StringSpec+                     , System.AtomicWrite.Writer.String.BinarySpec                      , System.AtomicWrite.Writer.TextSpec+                     , System.AtomicWrite.Writer.Text.BinarySpec                      , System.AtomicWrite.Writer.LazyTextSpec+                     , System.AtomicWrite.Writer.LazyText.BinarySpec    build-depends:       base >= 4.5 && < 5.0                      , atomic-write
+ spec/System/AtomicWrite/Writer/ByteString/BinarySpec.hs view
@@ -0,0 +1,142 @@+module System.AtomicWrite.Writer.ByteString.BinarySpec (spec) where+++import           Test.Hspec                                  (Spec, describe,+                                                              it, shouldBe)++import           System.AtomicWrite.Writer.ByteString.Binary (atomicWriteFile, atomicWriteFileWithMode)++import           System.FilePath.Posix                       (joinPath)+import           System.IO.Temp                              (withSystemTempDirectory)+import           System.PosixCompat.Files                    (fileMode,+                                                              getFileStatus,+                                                              setFileCreationMask,+                                                              setFileMode)++import           Data.ByteString.Char8                       (pack)+++spec :: Spec+spec = do+  describe "atomicWriteFile" $ do+    it "writes the contents to a file" $+      withSystemTempDirectory "atomicFileTest" $ \tmpDir -> do++        let path = joinPath [ tmpDir, "writeTest.tmp" ]++        atomicWriteFile path $ pack "just testing"+        contents <- readFile path++        contents `shouldBe` "just testing"+    it "preserves the permissions of original file, regardless of umask" $+      withSystemTempDirectory "atomicFileTest" $ \tmpDir -> do+        let filePath = joinPath [tmpDir, "testFile"]++        writeFile filePath "initial contents"+        setFileMode filePath 0o100644++        newStat <- getFileStatus filePath+        fileMode newStat `shouldBe` 0o100644++        -- New files are created with 100600 perms.+        _ <- setFileCreationMask 0o100066++        -- Create a new file once different mask is set and make sure that mask+        -- is applied.+        writeFile (joinPath [tmpDir, "sanityCheck"]) "with sanity check mask"+        sanityCheckStat <- getFileStatus $ joinPath [tmpDir, "sanityCheck"]+        fileMode sanityCheckStat `shouldBe` 0o100600++        -- Since we move, this makes the new file assume the filemask of 0600+        atomicWriteFile filePath $ pack "new contents"++        resultStat <- getFileStatus filePath++        -- reset mask to not break subsequent specs+        _ <- setFileCreationMask 0o100022++        -- Fails when using atomic mv command unless apply perms on initial file+        fileMode resultStat `shouldBe` 0o100644+++    it "creates a new file with permissions based on active umask" $+      withSystemTempDirectory "atomicFileTest" $ \tmpDir -> do+        let+          filePath       = joinPath [tmpDir, "testFile"]+          sampleFilePath = joinPath [tmpDir, "sampleFile"]++        -- Set somewhat distinctive defaults for test+        _ <- setFileCreationMask 0o100171++        -- We don't know what the default file permissions are, so create a+        -- file to sample them.+        writeFile sampleFilePath "I'm being written to sample permissions"++        newStat <- getFileStatus sampleFilePath+        fileMode newStat `shouldBe` 0o100606++        atomicWriteFile filePath $ pack "new contents"++        resultStat <- getFileStatus filePath++        -- reset mask to not break subsequent specs+        _ <- setFileCreationMask 0o100022++        -- The default tempfile permissions are 0600, so this fails unless we+        -- make sure that the default umask is relied on for creation of the+        -- tempfile.+        fileMode resultStat `shouldBe` 0o100606+  describe "atomicWriteFileWithMode" $ do+    it "writes contents to a file" $+      withSystemTempDirectory "atomicFileTest" $ \tmpDir -> do++        let path = joinPath [ tmpDir, "writeTest.tmp" ]++        atomicWriteFileWithMode 0o100777 path $ pack "just testing"++        contents <- readFile path++        contents `shouldBe` "just testing"+++    it "changes the permissions of a previously created file, regardless of umask" $+      withSystemTempDirectory "atomicFileTest" $ \tmpDir -> do+        let filePath = joinPath [tmpDir, "testFile"]++        writeFile filePath "initial contents"+        setFileMode filePath 0o100644++        newStat <- getFileStatus filePath+        fileMode newStat `shouldBe` 0o100644++        -- New files are created with 100600 perms.+        _ <- setFileCreationMask 0o100066++        -- Create a new file once different mask is set and make sure that mask+        -- is applied.+        writeFile (joinPath [tmpDir, "sanityCheck"]) "with sanity check mask"+        sanityCheckStat <- getFileStatus $ joinPath [tmpDir, "sanityCheck"]+        fileMode sanityCheckStat `shouldBe` 0o100600++        -- Since we move, this makes the new file assume the filemask of 0600+        atomicWriteFileWithMode 0o100655 filePath $ pack "new contents"++        resultStat <- getFileStatus filePath++        -- reset mask to not break subsequent specs+        _ <- setFileCreationMask 0o100022++        -- Fails when using atomic mv command unless apply perms on initial file+        fileMode resultStat `shouldBe` 0o100655+++    it "creates a new file with specified permissions" $+      withSystemTempDirectory "atomicFileTest" $ \tmpDir -> do+        let+          filePath       = joinPath [tmpDir, "testFile"]+        atomicWriteFileWithMode 0o100606 filePath $ pack "new contents"++        resultStat <- getFileStatus filePath++        fileMode resultStat `shouldBe` 0o100606+
spec/System/AtomicWrite/Writer/ByteStringSpec.hs view
@@ -1,15 +1,18 @@ module System.AtomicWrite.Writer.ByteStringSpec (spec) where -import Test.Hspec (it, describe, shouldBe, Spec)+import           Test.Hspec                           (Spec, describe, it,+                                                       shouldBe) -import System.AtomicWrite.Writer.ByteString (atomicWriteFile, atomicWriteFileWithMode)+import           System.AtomicWrite.Writer.ByteString (atomicWriteFile,+                                                       atomicWriteFileWithMode) -import System.IO.Temp (withSystemTempDirectory)-import System.FilePath.Posix (joinPath)-import System.PosixCompat.Files-  (setFileMode, setFileCreationMask, getFileStatus, fileMode)+import           System.FilePath.Posix                (joinPath)+import           System.IO.Temp                       (withSystemTempDirectory)+import           System.PosixCompat.Files             (fileMode, getFileStatus,+                                                       setFileCreationMask,+                                                       setFileMode) -import Data.ByteString.Char8 (pack)+import           Data.ByteString.Char8                (pack)  spec :: Spec spec = do@@ -134,3 +137,4 @@         resultStat <- getFileStatus filePath          fileMode resultStat `shouldBe` 0o100606+
+ spec/System/AtomicWrite/Writer/LazyByteString/BinarySpec.hs view
@@ -0,0 +1,141 @@+module System.AtomicWrite.Writer.LazyByteString.BinarySpec (spec) where++import           Test.Hspec                                      (Spec,+                                                                  describe, it,+                                                                  shouldBe)++import           System.AtomicWrite.Writer.LazyByteString.Binary (atomicWriteFile,+                                                                  atomicWriteFileWithMode)++import           System.FilePath.Posix                           (joinPath)+import           System.IO.Temp                                  (withSystemTempDirectory)+import           System.PosixCompat.Files                        (fileMode,+                                                                  getFileStatus,+                                                                  setFileCreationMask,+                                                                  setFileMode)++import           Data.ByteString.Lazy.Char8                      (pack)++spec :: Spec+spec = do+  describe "atomicWriteFile" $ do+    it "writes contents to a file" $+      withSystemTempDirectory "atomicFileTest" $ \tmpDir -> do++        let path = joinPath [ tmpDir, "writeTest.tmp" ]++        atomicWriteFile path $ pack "just testing"+        contents <- readFile path++        contents `shouldBe` "just testing"+    it "preserves the permissions of original file, regardless of umask" $+      withSystemTempDirectory "atomicFileTest" $ \tmpDir -> do+        let filePath = joinPath [tmpDir, "testFile"]++        writeFile filePath "initial contents"+        setFileMode filePath 0o100644++        newStat <- getFileStatus filePath+        fileMode newStat `shouldBe` 0o100644++        -- New files are created with 100600 perms.+        _ <- setFileCreationMask 0o100066++        -- Create a new file once different mask is set and make sure that mask+        -- is applied.+        writeFile (joinPath [tmpDir, "sanityCheck"]) "with sanity check mask"+        sanityCheckStat <- getFileStatus $ joinPath [tmpDir, "sanityCheck"]+        fileMode sanityCheckStat `shouldBe` 0o100600++        -- Since we move, this makes the new file assume the filemask of 0600+        atomicWriteFile filePath $ pack "new contents"++        resultStat <- getFileStatus filePath++        -- reset mask to not break subsequent specs+        _ <- setFileCreationMask 0o100022++        -- Fails when using atomic mv command unless apply perms on initial file+        fileMode resultStat `shouldBe` 0o100644+++    it "creates a new file with permissions based on active umask" $+      withSystemTempDirectory "atomicFileTest" $ \tmpDir -> do+        let+          filePath       = joinPath [tmpDir, "testFile"]+          sampleFilePath = joinPath [tmpDir, "sampleFile"]++        -- Set somewhat distinctive defaults for test+        _ <- setFileCreationMask 0o100171++        -- We don't know what the default file permissions are, so create a+        -- file to sample them.+        writeFile sampleFilePath "I'm being written to sample permissions"++        newStat <- getFileStatus sampleFilePath+        fileMode newStat `shouldBe` 0o100606++        atomicWriteFile filePath $ pack "new contents"++        resultStat <- getFileStatus filePath++        -- reset mask to not break subsequent specs+        _ <- setFileCreationMask 0o100022++        -- The default tempfile permissions are 0600, so this fails unless we+        -- make sure that the default umask is relied on for creation of the+        -- tempfile.+        fileMode resultStat `shouldBe` 0o100606+  describe "atomicWriteFileWithMode" $ do+    it "writes contents to a file" $+      withSystemTempDirectory "atomicFileTest" $ \tmpDir -> do++        let path = joinPath [ tmpDir, "writeTest.tmp" ]++        atomicWriteFileWithMode 0o100777 path $ pack "just testing"++        contents <- readFile path++        contents `shouldBe` "just testing"+++    it "changes the permissions of a previously created file, regardless of umask" $+      withSystemTempDirectory "atomicFileTest" $ \tmpDir -> do+        let filePath = joinPath [tmpDir, "testFile"]++        writeFile filePath "initial contents"+        setFileMode filePath 0o100644++        newStat <- getFileStatus filePath+        fileMode newStat `shouldBe` 0o100644++        -- New files are created with 100600 perms.+        _ <- setFileCreationMask 0o100066++        -- Create a new file once different mask is set and make sure that mask+        -- is applied.+        writeFile (joinPath [tmpDir, "sanityCheck"]) "with sanity check mask"+        sanityCheckStat <- getFileStatus $ joinPath [tmpDir, "sanityCheck"]+        fileMode sanityCheckStat `shouldBe` 0o100600++        -- Since we move, this makes the new file assume the filemask of 0600+        atomicWriteFileWithMode 0o100655 filePath $ pack "new contents"++        resultStat <- getFileStatus filePath++        -- reset mask to not break subsequent specs+        _ <- setFileCreationMask 0o100022++        -- Fails when using atomic mv command unless apply perms on initial file+        fileMode resultStat `shouldBe` 0o100655+++    it "creates a new file with specified permissions" $+      withSystemTempDirectory "atomicFileTest" $ \tmpDir -> do+        let+          filePath       = joinPath [tmpDir, "testFile"]+        atomicWriteFileWithMode 0o100606 filePath $ pack "new contents"++        resultStat <- getFileStatus filePath++        fileMode resultStat `shouldBe` 0o100606
+ spec/System/AtomicWrite/Writer/LazyText/BinarySpec.hs view
@@ -0,0 +1,139 @@+module System.AtomicWrite.Writer.LazyText.BinarySpec (spec) where++import           Test.Hspec                                (Spec, describe, it,+                                                            shouldBe)++import           System.AtomicWrite.Writer.LazyText.Binary (atomicWriteFile, atomicWriteFileWithMode)++import           System.FilePath.Posix                     (joinPath)+import           System.IO.Temp                            (withSystemTempDirectory)+import           System.PosixCompat.Files                  (fileMode,+                                                            getFileStatus,+                                                            setFileCreationMask,+                                                            setFileMode)++import           Data.Text.Lazy                            (pack)++spec :: Spec+spec = do+  describe "atomicWriteFile" $ do+    it "writes contents to a file" $+      withSystemTempDirectory "atomicFileTest" $ \tmpDir -> do++        let path = joinPath [ tmpDir, "writeTest.tmp" ]++        atomicWriteFile path $ pack "just testing"+        contents <- readFile path++        contents `shouldBe` "just testing"+    it "preserves the permissions of original file, regardless of umask" $+      withSystemTempDirectory "atomicFileTest" $ \tmpDir -> do+        let filePath = joinPath [tmpDir, "testFile"]++        writeFile filePath "initial contents"+        setFileMode filePath 0o100644++        newStat <- getFileStatus filePath+        fileMode newStat `shouldBe` 0o100644++        -- New files are created with 100600 perms.+        _ <- setFileCreationMask 0o100066++        -- Create a new file once different mask is set and make sure that mask+        -- is applied.+        writeFile (joinPath [tmpDir, "sanityCheck"]) "with sanity check mask"+        sanityCheckStat <- getFileStatus $ joinPath [tmpDir, "sanityCheck"]+        fileMode sanityCheckStat `shouldBe` 0o100600++        -- Since we move, this makes the new file assume the filemask of 0600+        atomicWriteFile filePath $ pack "new contents"++        resultStat <- getFileStatus filePath++        -- reset mask to not break subsequent specs+        _ <- setFileCreationMask 0o100022++        -- Fails when using atomic mv command unless apply perms on initial file+        fileMode resultStat `shouldBe` 0o100644+++    it "creates a new file with permissions based on active umask" $+      withSystemTempDirectory "atomicFileTest" $ \tmpDir -> do+        let+          filePath       = joinPath [tmpDir, "testFile"]+          sampleFilePath = joinPath [tmpDir, "sampleFile"]++        -- Set somewhat distinctive defaults for test+        _ <- setFileCreationMask 0o100171++        -- We don't know what the default file permissions are, so create a+        -- file to sample them.+        writeFile sampleFilePath "I'm being written to sample permissions"++        newStat <- getFileStatus sampleFilePath+        fileMode newStat `shouldBe` 0o100606++        atomicWriteFile filePath $ pack "new contents"++        resultStat <- getFileStatus filePath++        -- reset mask to not break subsequent specs+        _ <- setFileCreationMask 0o100022++        -- The default tempfile permissions are 0600, so this fails unless we+        -- make sure that the default umask is relied on for creation of the+        -- tempfile.+        fileMode resultStat `shouldBe` 0o100606+  describe "atomicWriteFileWithMode" $ do+    it "writes contents to a file" $+      withSystemTempDirectory "atomicFileTest" $ \tmpDir -> do++        let path = joinPath [ tmpDir, "writeTest.tmp" ]++        atomicWriteFileWithMode 0o100777 path $ pack "just testing"++        contents <- readFile path++        contents `shouldBe` "just testing"+++    it "changes the permissions of a previously created file, regardless of umask" $+      withSystemTempDirectory "atomicFileTest" $ \tmpDir -> do+        let filePath = joinPath [tmpDir, "testFile"]++        writeFile filePath "initial contents"+        setFileMode filePath 0o100644++        newStat <- getFileStatus filePath+        fileMode newStat `shouldBe` 0o100644++        -- New files are created with 100600 perms.+        _ <- setFileCreationMask 0o100066++        -- Create a new file once different mask is set and make sure that mask+        -- is applied.+        writeFile (joinPath [tmpDir, "sanityCheck"]) "with sanity check mask"+        sanityCheckStat <- getFileStatus $ joinPath [tmpDir, "sanityCheck"]+        fileMode sanityCheckStat `shouldBe` 0o100600++        -- Since we move, this makes the new file assume the filemask of 0600+        atomicWriteFileWithMode 0o100655 filePath $ pack "new contents"++        resultStat <- getFileStatus filePath++        -- reset mask to not break subsequent specs+        _ <- setFileCreationMask 0o100022++        -- Fails when using atomic mv command unless apply perms on initial file+        fileMode resultStat `shouldBe` 0o100655+++    it "creates a new file with specified permissions" $+      withSystemTempDirectory "atomicFileTest" $ \tmpDir -> do+        let+          filePath       = joinPath [tmpDir, "testFile"]+        atomicWriteFileWithMode 0o100606 filePath $ pack "new contents"++        resultStat <- getFileStatus filePath++        fileMode resultStat `shouldBe` 0o100606
+ spec/System/AtomicWrite/Writer/String/BinarySpec.hs view
@@ -0,0 +1,143 @@+module System.AtomicWrite.Writer.String.BinarySpec (spec) where++import           Test.Hspec                              (Spec, describe, it,+                                                          shouldBe)++import           System.AtomicWrite.Writer.String.Binary (atomicWriteFile, atomicWriteFileWithMode)++import           System.FilePath                         (joinPath)+import           System.IO.Temp                          (withSystemTempDirectory)+import           System.PosixCompat.Files                (fileMode,+                                                          getFileStatus,+                                                          setFileCreationMask,+                                                          setFileMode)+++{-# ANN module "HLint: ignore Reduce duplication" #-}++spec :: Spec+spec = do+  describe "atomicWriteFile" $ do+    it "writes contents to a file" $+      withSystemTempDirectory "atomicFileTest" $ \tmpDir -> do++        let path = joinPath [ tmpDir, "writeTest.tmp" ]++        atomicWriteFile path "just testing"++        contents <- readFile path++        contents `shouldBe` "just testing"+++    it "preserves the permissions of original file, regardless of umask" $+      withSystemTempDirectory "atomicFileTest" $ \tmpDir -> do+        let filePath = joinPath [tmpDir, "testFile"]++        writeFile filePath "initial contents"+        setFileMode filePath 0o100644++        newStat <- getFileStatus filePath+        fileMode newStat `shouldBe` 0o100644++        -- New files are created with 100600 perms.+        _ <- setFileCreationMask 0o100066++        -- Create a new file once different mask is set and make sure that mask+        -- is applied.+        writeFile (joinPath [tmpDir, "sanityCheck"]) "with sanity check mask"+        sanityCheckStat <- getFileStatus $ joinPath [tmpDir, "sanityCheck"]+        fileMode sanityCheckStat `shouldBe` 0o100600++        -- Since we move, this makes the new file assume the filemask of 0600+        atomicWriteFile filePath "new contents"++        resultStat <- getFileStatus filePath++        -- reset mask to not break subsequent specs+        _ <- setFileCreationMask 0o100022++        -- Fails when using atomic mv command unless apply perms on initial file+        fileMode resultStat `shouldBe` 0o100644+++    it "creates a new file with permissions based on active umask" $+      withSystemTempDirectory "atomicFileTest" $ \tmpDir -> do+        let+          filePath       = joinPath [tmpDir, "testFile"]+          sampleFilePath = joinPath [tmpDir, "sampleFile"]++        -- Set somewhat distinctive defaults for test+        _ <- setFileCreationMask 0o100171++        -- We don't know what the default file permissions are, so create a+        -- file to sample them.+        writeFile sampleFilePath "I'm being written to sample permissions"++        newStat <- getFileStatus sampleFilePath+        fileMode newStat `shouldBe` 0o100606++        atomicWriteFile filePath "new contents"++        resultStat <- getFileStatus filePath++        -- reset mask to not break subsequent specs+        _ <- setFileCreationMask 0o100022++        -- The default tempfile permissions are 0600, so this fails unless we+        -- make sure that the default umask is relied on for creation of the+        -- tempfile.+        fileMode resultStat `shouldBe` 0o100606+  describe "atomicWriteFileWithMode" $ do+    it "writes contents to a file" $+      withSystemTempDirectory "atomicFileTest" $ \tmpDir -> do++        let path = joinPath [ tmpDir, "writeTest.tmp" ]++        atomicWriteFileWithMode 0o100777 path "just testing"++        contents <- readFile path++        contents `shouldBe` "just testing"+++    it "changes the permissions of a previously created file, regardless of umask" $+      withSystemTempDirectory "atomicFileTest" $ \tmpDir -> do+        let filePath = joinPath [tmpDir, "testFile"]++        writeFile filePath "initial contents"+        setFileMode filePath 0o100644++        newStat <- getFileStatus filePath+        fileMode newStat `shouldBe` 0o100644++        -- New files are created with 100600 perms.+        _ <- setFileCreationMask 0o100066++        -- Create a new file once different mask is set and make sure that mask+        -- is applied.+        writeFile (joinPath [tmpDir, "sanityCheck"]) "with sanity check mask"+        sanityCheckStat <- getFileStatus $ joinPath [tmpDir, "sanityCheck"]+        fileMode sanityCheckStat `shouldBe` 0o100600++        -- Since we move, this makes the new file assume the filemask of 0600+        atomicWriteFileWithMode 0o100655 filePath "new contents"++        resultStat <- getFileStatus filePath++        -- reset mask to not break subsequent specs+        _ <- setFileCreationMask 0o100022++        -- Fails when using atomic mv command unless apply perms on initial file+        fileMode resultStat `shouldBe` 0o100655+++    it "creates a new file with specified permissions" $+      withSystemTempDirectory "atomicFileTest" $ \tmpDir -> do+        let+          filePath       = joinPath [tmpDir, "testFile"]+        atomicWriteFileWithMode 0o100606 filePath "new contents"++        resultStat <- getFileStatus filePath++        fileMode resultStat `shouldBe` 0o100606
spec/System/AtomicWrite/Writer/StringSpec.hs view
@@ -1,13 +1,15 @@ module System.AtomicWrite.Writer.StringSpec (spec) where -import Test.Hspec (it, describe, shouldBe, Spec)+import           Test.Hspec                       (Spec, describe, it, shouldBe) -import System.AtomicWrite.Writer.String (atomicWriteFile, atomicWriteFileWithMode)+import           System.AtomicWrite.Writer.String (atomicWriteFile,+                                                   atomicWriteFileWithMode) -import System.IO.Temp (withSystemTempDirectory)-import System.FilePath (joinPath)-import System.PosixCompat.Files-  (setFileMode, setFileCreationMask, getFileStatus, fileMode)+import           System.FilePath                  (joinPath)+import           System.IO.Temp                   (withSystemTempDirectory)+import           System.PosixCompat.Files         (fileMode, getFileStatus,+                                                   setFileCreationMask,+                                                   setFileMode)   {-# ANN module "HLint: ignore Reduce duplication" #-}
+ spec/System/AtomicWrite/Writer/Text/BinarySpec.hs view
@@ -0,0 +1,139 @@+module System.AtomicWrite.Writer.Text.BinarySpec (spec) where++import           Test.Hspec                            (Spec, describe, it,+                                                        shouldBe)++import           System.AtomicWrite.Writer.Text.Binary (atomicWriteFile,+                                                        atomicWriteFileWithMode)++import           System.FilePath.Posix                 (joinPath)+import           System.IO.Temp                        (withSystemTempDirectory)+import           System.PosixCompat.Files              (fileMode, getFileStatus,+                                                        setFileCreationMask,+                                                        setFileMode)++import           Data.Text                             (pack)++spec :: Spec+spec = do+  describe "atomicWriteFile" $ do+    it "writes contents to a file" $+      withSystemTempDirectory "atomicFileTest" $ \tmpDir -> do++        let path = joinPath [ tmpDir, "writeTest.tmp" ]++        atomicWriteFile path $ pack "just testing"+        contents <- readFile path++        contents `shouldBe` "just testing"+    it "preserves the permissions of original file, regardless of umask" $+      withSystemTempDirectory "atomicFileTest" $ \tmpDir -> do+        let filePath = joinPath [tmpDir, "testFile"]++        writeFile filePath "initial contents"+        setFileMode filePath 0o100644++        newStat <- getFileStatus filePath+        fileMode newStat `shouldBe` 0o100644++        -- New files are created with 100600 perms.+        _ <- setFileCreationMask 0o100066++        -- Create a new file once different mask is set and make sure that mask+        -- is applied.+        writeFile (joinPath [tmpDir, "sanityCheck"]) "with sanity check mask"+        sanityCheckStat <- getFileStatus $ joinPath [tmpDir, "sanityCheck"]+        fileMode sanityCheckStat `shouldBe` 0o100600++        -- Since we move, this makes the new file assume the filemask of 0600+        atomicWriteFile filePath $ pack "new contents"++        resultStat <- getFileStatus filePath++        -- reset mask to not break subsequent specs+        _ <- setFileCreationMask 0o100022++        -- Fails when using atomic mv command unless apply perms on initial file+        fileMode resultStat `shouldBe` 0o100644+++    it "creates a new file with permissions based on active umask" $+      withSystemTempDirectory "atomicFileTest" $ \tmpDir -> do+        let+          filePath       = joinPath [tmpDir, "testFile"]+          sampleFilePath = joinPath [tmpDir, "sampleFile"]++        -- Set somewhat distinctive defaults for test+        _ <- setFileCreationMask 0o100171++        -- We don't know what the default file permissions are, so create a+        -- file to sample them.+        writeFile sampleFilePath "I'm being written to sample permissions"++        newStat <- getFileStatus sampleFilePath+        fileMode newStat `shouldBe` 0o100606++        atomicWriteFile filePath $ pack "new contents"++        resultStat <- getFileStatus filePath++        -- reset mask to not break subsequent specs+        _ <- setFileCreationMask 0o100022++        -- The default tempfile permissions are 0600, so this fails unless we+        -- make sure that the default umask is relied on for creation of the+        -- tempfile.+        fileMode resultStat `shouldBe` 0o100606+  describe "atomicWriteFileWithMode" $ do+    it "writes contents to a file" $+      withSystemTempDirectory "atomicFileTest" $ \tmpDir -> do++        let path = joinPath [ tmpDir, "writeTest.tmp" ]++        atomicWriteFileWithMode 0o100777 path $ pack "just testing"++        contents <- readFile path++        contents `shouldBe` "just testing"+++    it "changes the permissions of a previously created file, regardless of umask" $+      withSystemTempDirectory "atomicFileTest" $ \tmpDir -> do+        let filePath = joinPath [tmpDir, "testFile"]++        writeFile filePath "initial contents"+        setFileMode filePath 0o100644++        newStat <- getFileStatus filePath+        fileMode newStat `shouldBe` 0o100644++        -- New files are created with 100600 perms.+        _ <- setFileCreationMask 0o100066++        -- Create a new file once different mask is set and make sure that mask+        -- is applied.+        writeFile (joinPath [tmpDir, "sanityCheck"]) "with sanity check mask"+        sanityCheckStat <- getFileStatus $ joinPath [tmpDir, "sanityCheck"]+        fileMode sanityCheckStat `shouldBe` 0o100600++        -- Since we move, this makes the new file assume the filemask of 0600+        atomicWriteFileWithMode 0o100655 filePath $ pack "new contents"++        resultStat <- getFileStatus filePath++        -- reset mask to not break subsequent specs+        _ <- setFileCreationMask 0o100022++        -- Fails when using atomic mv command unless apply perms on initial file+        fileMode resultStat `shouldBe` 0o100655+++    it "creates a new file with specified permissions" $+      withSystemTempDirectory "atomicFileTest" $ \tmpDir -> do+        let+          filePath       = joinPath [tmpDir, "testFile"]+        atomicWriteFileWithMode 0o100606 filePath $ pack "new contents"++        resultStat <- getFileStatus filePath++        fileMode resultStat `shouldBe` 0o100606
src/System/AtomicWrite/Internal.hs view
@@ -1,6 +1,6 @@ -- |--- Module      :  Configuration.Dotenv.Parse--- Copyright   :  © 2015-2017 Stack Builders Inc.+-- Module      :  System.AtomicWrite.Internal+-- Copyright   :  © 2015-2019 Stack Builders Inc. -- License     :  MIT -- -- Maintainer  :  Stack Builders <hackage@stackbuilders.com>@@ -10,14 +10,15 @@ -- Provides functionality to create a temporary file with correct permissions -- atomically. -module System.AtomicWrite.Internal (closeAndRename, tempFileFor, maybeSetFileMode) where+module System.AtomicWrite.Internal where -import System.Directory (doesFileExist, renameFile)-import System.PosixCompat.Files (setFileMode, getFileStatus, fileMode)-import System.Posix.Types (FileMode)-import System.FilePath (takeDirectory)-import System.IO-  (hClose, Handle, openTempFile, openTempFileWithDefaultPermissions)+import           System.Directory         (doesFileExist, renameFile)+import           System.FilePath          (takeDirectory)+import           System.IO                (Handle, hClose, hSetBinaryMode,+                                           openTempFile,+                                           openTempFileWithDefaultPermissions)+import           System.Posix.Types       (FileMode)+import           System.PosixCompat.Files (fileMode, getFileStatus, setFileMode)  -- | Returns a temporary file with permissions correctly set. Chooses -- either previously-set permissions if the file that we're writing@@ -57,3 +58,29 @@   maybe     ( return () )     ( \mode -> setFileMode path mode )+++-- Helper Function+atomicWriteFileMaybeModeText ::+  Maybe FileMode -- ^ The mode to set the file to+  -> FilePath    -- ^ The path where the file will be updated or created+  -> (Handle -> a -> IO ()) -- ^ The function to use to write on the file+  -> a        -- ^ The content to write to the file+  -> IO ()+atomicWriteFileMaybeModeText mmode path hF text =+  tempFileFor path >>= \(tmpPath, h) -> hSetBinaryMode h False+                    >> hF h text+                    >> closeAndRename h tmpPath path+                    >> maybeSetFileMode path mmode+-- Helper Function+atomicWriteFileMaybeModeBinary ::+  Maybe FileMode -- ^ The mode to set the file to+  -> FilePath    -- ^ The path where the file will be updated or created+  -> (Handle -> a -> IO ()) -- ^ The function to use to write on the file+  -> a        -- ^ The content to write to the file+  -> IO ()+atomicWriteFileMaybeModeBinary mmode path hF text =+  tempFileFor path >>= \(tmpPath, h) -> hSetBinaryMode h True+                    >> hF h text+                    >> closeAndRename h tmpPath path+                    >> maybeSetFileMode path mmode
src/System/AtomicWrite/Writer/ByteString.hs view
@@ -1,6 +1,6 @@ -- |--- Module      :  Configuration.Dotenv.Parse--- Copyright   :  © 2015-2017 Stack Builders Inc.+-- Module      :  System.AtomicWrite.Writer.ByteString+-- Copyright   :  © 2015-2019 Stack Builders Inc. -- License     :  MIT -- -- Maintainer  :  Stack Builders <hackage@stackbuilders.com>@@ -8,16 +8,17 @@ -- Portability :  portable -- -- Provides functionality to dump the contents of a ByteString--- to a file.+-- to a file in text mode.  module System.AtomicWrite.Writer.ByteString (atomicWriteFile, atomicWriteFileWithMode) where -import System.AtomicWrite.Internal (closeAndRename, tempFileFor, maybeSetFileMode)+import           System.AtomicWrite.Internal (atomicWriteFileMaybeModeText) -import System.Posix.Types (FileMode)+import           System.Posix.Types          (FileMode) -import Data.ByteString (ByteString, hPutStr)+import           Data.ByteString             (ByteString, hPutStr) + -- | Creates or modifies a file atomically on POSIX-compliant -- systems while preserving permissions. atomicWriteFile ::@@ -33,8 +34,7 @@   -> FilePath      -- ^ The path where the file will be updated or created   -> ByteString -- ^ The content to write to the file   -> IO ()-atomicWriteFileWithMode mode =-  atomicWriteFileMaybeMode $ Just mode+atomicWriteFileWithMode = atomicWriteFileMaybeMode . Just  -- | Helper function atomicWriteFileMaybeMode ::@@ -42,7 +42,5 @@   -> FilePath      -- ^ The path where the file will be updated or created   -> ByteString -- ^ The content to write to the file   -> IO ()-atomicWriteFileMaybeMode mmode path text =-  tempFileFor path >>= \(tmpPath, h) -> hPutStr h text-                    >> closeAndRename h tmpPath path-                    >> maybeSetFileMode path mmode+atomicWriteFileMaybeMode mmode path = atomicWriteFileMaybeModeText mmode path hPutStr+
+ src/System/AtomicWrite/Writer/ByteString/Binary.hs view
@@ -0,0 +1,48 @@+-- |+-- Module      :  System.AtomicWrite.Writer.ByteString.Binary+-- Copyright   :  © 2015-2019 Stack Builders Inc.+-- License     :  MIT+--+-- Maintainer  :  Stack Builders <hackage@stackbuilders.com>+-- Stability   :  experimental+-- Portability :  portable+--+-- Provides functionality to dump the contents of a ByteString+-- to a file open in binary mode++module System.AtomicWrite.Writer.ByteString.Binary (atomicWriteFile, atomicWriteFileWithMode) where++import           System.AtomicWrite.Internal (atomicWriteFileMaybeModeBinary)++import           System.Posix.Types          (FileMode)++import           Data.ByteString             (ByteString, hPutStr)+++-- | Creates or modifies a file atomically on POSIX-compliant+-- systems while preserving permissions. The file is opened in+-- binary mode.+atomicWriteFile ::+  FilePath      -- ^ The path where the file will be updated or created+  -> ByteString -- ^ The content to write to the file+  -> IO ()+atomicWriteFile = atomicWriteFileMaybeMode Nothing++-- | Creates or modifies a file atomically on POSIX-compliant+-- systems and updates permissions. The file is opened in binary+-- mode.+atomicWriteFileWithMode ::+  FileMode+  -> FilePath      -- ^ The path where the file will be updated or created+  -> ByteString -- ^ The content to write to the file+  -> IO ()+atomicWriteFileWithMode mode =+  atomicWriteFileMaybeMode $ Just mode++-- | Helper function for opening the file in binary mode.+atomicWriteFileMaybeMode ::+  Maybe FileMode+  -> FilePath      -- ^ The path where the file will be updated or created+  -> ByteString -- ^ The content to write to the file+  -> IO ()+atomicWriteFileMaybeMode mmode path = atomicWriteFileMaybeModeBinary mmode path hPutStr
src/System/AtomicWrite/Writer/ByteStringBuilder.hs view
@@ -1,6 +1,6 @@ -- |--- Module      :  Configuration.Dotenv.Parse--- Copyright   :  © 2015-2017 Stack Builders Inc.+-- Module      :  System.AtomicWrite.Writer.ByteStringBuilder+-- Copyright   :  © 2015-2019 Stack Builders Inc. -- License     :  MIT -- -- Maintainer  :  Stack Builders <hackage@stackbuilders.com>@@ -12,13 +12,15 @@  module System.AtomicWrite.Writer.ByteStringBuilder (atomicWriteFile, atomicWriteFileWithMode) where -import System.AtomicWrite.Internal (closeAndRename, tempFileFor, maybeSetFileMode)+import           System.AtomicWrite.Internal (closeAndRename, maybeSetFileMode,+                                              tempFileFor) -import Data.ByteString.Builder (hPutBuilder, Builder, hPutBuilder)+import           Data.ByteString.Builder     (Builder, hPutBuilder) -import GHC.IO.Handle (hSetBinaryMode, hSetBuffering, BufferMode (BlockBuffering))+import           GHC.IO.Handle               (BufferMode (BlockBuffering),+                                              hSetBinaryMode, hSetBuffering) -import System.Posix.Types (FileMode)+import           System.Posix.Types          (FileMode)  -- | Creates or modifies a file atomically on POSIX-compliant -- systems while preserving permissions.
src/System/AtomicWrite/Writer/LazyByteString.hs view
@@ -1,6 +1,6 @@ -- |--- Module      :  Configuration.Dotenv.Parse--- Copyright   :  © 2015-2017 Stack Builders Inc.+-- Module      :  System.AtomicWrite.Writer.LazyByteString+-- Copyright   :  © 2015-2019 Stack Builders Inc. -- License     :  MIT -- -- Maintainer  :  Stack Builders <hackage@stackbuilders.com>@@ -12,11 +12,11 @@  module System.AtomicWrite.Writer.LazyByteString (atomicWriteFile, atomicWriteFileWithMode) where -import System.AtomicWrite.Internal (closeAndRename, tempFileFor, maybeSetFileMode)+import           System.AtomicWrite.Internal (atomicWriteFileMaybeModeText) -import Data.ByteString.Lazy (ByteString, hPutStr)+import           Data.ByteString.Lazy        (ByteString, hPutStr) -import System.Posix.Types (FileMode)+import           System.Posix.Types          (FileMode)  -- | Creates or modifies a file atomically on POSIX-compliant -- systems while preserving permissions.@@ -34,8 +34,8 @@   -> FilePath   -- ^ The path where the file will be updated or created   -> ByteString -- ^ The content to write to the file   -> IO ()-atomicWriteFileWithMode mode =-  atomicWriteFileMaybeMode $ Just mode+atomicWriteFileWithMode =+  atomicWriteFileMaybeMode . Just  -- Helper Function atomicWriteFileMaybeMode ::@@ -43,7 +43,4 @@   -> FilePath    -- ^ The path where the file will be updated or created   -> ByteString  -- ^ The content to write to the file   -> IO ()-atomicWriteFileMaybeMode mmode path text =-  tempFileFor path >>= \(tmpPath, h) -> hPutStr h text-                    >> closeAndRename h tmpPath path-                    >> maybeSetFileMode path mmode+atomicWriteFileMaybeMode mmode path = atomicWriteFileMaybeModeText mmode path hPutStr
+ src/System/AtomicWrite/Writer/LazyByteString/Binary.hs view
@@ -0,0 +1,46 @@+-- |+-- Module      :  System.AtomicWrite.Writer.LazyByteString.Binary+-- Copyright   :  © 2015-2019 Stack Builders Inc.+-- License     :  MIT+--+-- Maintainer  :  Stack Builders <hackage@stackbuilders.com>+-- Stability   :  experimental+-- Portability :  portable+--+-- Provides functionality to dump the contents of a Lazy ByteString+-- to a file in binary mode.++module System.AtomicWrite.Writer.LazyByteString.Binary (atomicWriteFile, atomicWriteFileWithMode) where++import           System.AtomicWrite.Internal (atomicWriteFileMaybeModeBinary)++import           Data.ByteString.Lazy        (ByteString, hPutStr)++import           System.Posix.Types          (FileMode)+++-- | Creates or modifies a file atomically on POSIX-compliant+-- systems while preserving permissions.+atomicWriteFile ::+  FilePath      -- ^ The path where the file will be updated or created+  -> ByteString -- ^ The content to write to the file+  -> IO ()+atomicWriteFile =+  atomicWriteFileMaybeMode Nothing++-- | Creates or modifies a file atomically on+-- POSIX-compliant systems and updates permissions+atomicWriteFileWithMode ::+  FileMode      -- ^ The mode to set the file to+  -> FilePath   -- ^ The path where the file will be updated or created+  -> ByteString -- ^ The content to write to the file+  -> IO ()+atomicWriteFileWithMode = atomicWriteFileMaybeMode . Just++-- Helper Function+atomicWriteFileMaybeMode ::+  Maybe FileMode -- ^ The mode to set the file to+  -> FilePath    -- ^ The path where the file will be updated or created+  -> ByteString  -- ^ The content to write to the file+  -> IO ()+atomicWriteFileMaybeMode mmode path = atomicWriteFileMaybeModeBinary mmode path hPutStr
src/System/AtomicWrite/Writer/LazyText.hs view
@@ -1,6 +1,6 @@ -- |--- Module      :  Configuration.Dotenv.Parse--- Copyright   :  © 2015-2017 Stack Builders Inc.+-- Module      :  System.AtomicWrite.Writer.LazyText+-- Copyright   :  © 2015-2019 Stack Builders Inc. -- License     :  MIT -- -- Maintainer  :  Stack Builders <hackage@stackbuilders.com>@@ -12,13 +12,13 @@  module System.AtomicWrite.Writer.LazyText (atomicWriteFile, atomicWriteFileWithMode) where -import System.AtomicWrite.Internal (closeAndRename, tempFileFor, maybeSetFileMode)+import           System.AtomicWrite.Internal (atomicWriteFileMaybeModeText) -import Data.Text.Lazy (Text)+import           Data.Text.Lazy              (Text) -import Data.Text.Lazy.IO (hPutStr)+import           Data.Text.Lazy.IO           (hPutStr) -import System.Posix.Types (FileMode)+import           System.Posix.Types          (FileMode)  -- | Creates a file atomically on POSIX-compliant -- systems while preserving permissions.@@ -36,8 +36,8 @@   -> FilePath   -- ^ The path where the file will be updated or created   -> Text       -- ^ The content to write to the file   -> IO ()-atomicWriteFileWithMode mode =-  atomicWriteFileMaybeMode $ Just mode+atomicWriteFileWithMode =+  atomicWriteFileMaybeMode . Just  -- Helper Function atomicWriteFileMaybeMode ::@@ -45,7 +45,4 @@   -> FilePath    -- ^ The path where the file will be updated or created   -> Text        -- ^ The content to write to the file   -> IO ()-atomicWriteFileMaybeMode mmode path text =-  tempFileFor path >>= \(tmpPath, h) -> hPutStr h text-                    >> closeAndRename h tmpPath path-                    >> maybeSetFileMode path mmode+atomicWriteFileMaybeMode mmode path = atomicWriteFileMaybeModeText mmode path hPutStr
+ src/System/AtomicWrite/Writer/LazyText/Binary.hs view
@@ -0,0 +1,48 @@+-- |+-- Module      :  System.AtomicWrite.Writer.LazyText.Binary+-- Copyright   :  © 2015-2019 Stack Builders Inc.+-- License     :  MIT+--+-- Maintainer  :  Stack Builders <hackage@stackbuilders.com>+-- Stability   :  experimental+-- Portability :  portable+--+-- Provides functionality to dump the contents of a Text+-- to a file in binary mode.++module System.AtomicWrite.Writer.LazyText.Binary (atomicWriteFile, atomicWriteFileWithMode) where++import           System.AtomicWrite.Internal (atomicWriteFileMaybeModeBinary)++import           Data.Text.Lazy              (Text)++import           Data.Text.Lazy.IO           (hPutStr)++import           System.Posix.Types          (FileMode)+++-- | Creates a file atomically on POSIX-compliant+-- systems while preserving permissions.+atomicWriteFile ::+  FilePath   -- ^ The path where the file will be updated or created+  -> Text    -- ^ The content to write to the file+  -> IO ()+atomicWriteFile =+  atomicWriteFileMaybeMode Nothing++-- | Creates or modifies a file atomically on+-- POSIX-compliant systems and updates permissions+atomicWriteFileWithMode ::+  FileMode      -- ^ The mode to set the file to+  -> FilePath   -- ^ The path where the file will be updated or created+  -> Text       -- ^ The content to write to the file+  -> IO ()+atomicWriteFileWithMode = atomicWriteFileMaybeMode . Just++-- Helper Function+atomicWriteFileMaybeMode ::+  Maybe FileMode -- ^ The mode to set the file to+  -> FilePath    -- ^ The path where the file will be updated or created+  -> Text        -- ^ The content to write to the file+  -> IO ()+atomicWriteFileMaybeMode mmode path = atomicWriteFileMaybeModeBinary mmode path hPutStr
src/System/AtomicWrite/Writer/String.hs view
@@ -1,6 +1,6 @@ -- |--- Module      :  Configuration.Dotenv.Parse--- Copyright   :  © 2015-2017 Stack Builders Inc.+-- Module      :  System.AtomicWrite.Writer.String+-- Copyright   :  © 2015-2019 Stack Builders Inc. -- License     :  MIT -- -- Maintainer  :  Stack Builders <hackage@stackbuilders.com>@@ -12,11 +12,12 @@  module System.AtomicWrite.Writer.String (atomicWriteFile, atomicWithFile, atomicWriteFileWithMode, atomicWithFileAndMode) where -import System.AtomicWrite.Internal (closeAndRename, tempFileFor, maybeSetFileMode)+import           System.AtomicWrite.Internal (closeAndRename, maybeSetFileMode,+                                              tempFileFor) -import System.IO (Handle, hPutStr)+import           System.IO                   (Handle, hPutStr) -import System.Posix.Types (FileMode)+import           System.Posix.Types          (FileMode)  -- | Creates or modifies a file atomically on POSIX-compliant -- systems while preserving permissions.@@ -35,20 +36,18 @@   -> String   -- ^ The content to write to the file   -> IO () atomicWriteFileWithMode mode = ( . flip hPutStr)-                             . ( atomicWithFileAndMode mode )+                             .  atomicWithFileAndMode mode  -- | A general version of 'atomicWriteFile' atomicWithFile :: FilePath -> (Handle -> IO ()) -> IO ()-atomicWithFile f action =-  atomicWithFileAndMaybeMode Nothing f action+atomicWithFile = atomicWithFileAndMaybeMode Nothing  -- | A general version of 'atomicWriteFileWithMode' atomicWithFileAndMode :: FileMode                       -> FilePath                       -> (Handle -> IO ())                       -> IO ()-atomicWithFileAndMode mode path action =-  atomicWithFileAndMaybeMode (Just mode) path action+atomicWithFileAndMode = atomicWithFileAndMaybeMode . Just  -- | Helper function atomicWithFileAndMaybeMode :: Maybe FileMode
+ src/System/AtomicWrite/Writer/String/Binary.hs view
@@ -0,0 +1,61 @@+-- |+-- Module      :  System.AtomicWrite.Writer.String.Binary+-- Copyright   :  © 2015-2019 Stack Builders Inc.+-- License     :  MIT+--+-- Maintainer  :  Stack Builders <hackage@stackbuilders.com>+-- Stability   :  experimental+-- Portability :  portable+--+-- Provides functionality to dump the contents of a String+-- to a file in binary mode.++module System.AtomicWrite.Writer.String.Binary (atomicWriteFile, atomicWithFile, atomicWriteFileWithMode, atomicWithFileAndMode) where++import           System.AtomicWrite.Internal (closeAndRename, maybeSetFileMode,+                                              tempFileFor)++import           System.IO                   (Handle, hPutStr, hSetBinaryMode)++import           System.Posix.Types          (FileMode)++-- | Creates or modifies a file atomically on POSIX-compliant+-- systems while preserving permissions.+atomicWriteFile ::+  FilePath   -- ^ The path where the file will be updated or created+  -> String  -- ^ The content to write to the file+  -> IO ()+atomicWriteFile = (. flip hPutStr) . atomicWithFile+++-- | Creates or modifies a file atomically on+-- POSIX-compliant systems and updates permissions+atomicWriteFileWithMode ::+  FileMode    -- ^ The mode to set the file to+  -> FilePath -- ^ The path where the file will be updated or created+  -> String   -- ^ The content to write to the file+  -> IO ()+atomicWriteFileWithMode mode = ( . flip hPutStr)+                             .  atomicWithFileAndMode mode++-- | A general version of 'atomicWriteFile'+atomicWithFile :: FilePath -> (Handle -> IO ()) -> IO ()+atomicWithFile = atomicWithFileAndMaybeMode Nothing++-- | A general version of 'atomicWriteFileWithMode'+atomicWithFileAndMode :: FileMode+                      -> FilePath+                      -> (Handle -> IO ())+                      -> IO ()+atomicWithFileAndMode = atomicWithFileAndMaybeMode . Just++-- | Helper function+atomicWithFileAndMaybeMode :: Maybe FileMode+                           -> FilePath+                           -> (Handle -> IO ())+                           -> IO ()+atomicWithFileAndMaybeMode mmode path action =+  tempFileFor path >>= \(tmpPath, h) -> hSetBinaryMode h True+                    >> action h+                    >> closeAndRename h tmpPath path+                    >> maybeSetFileMode path mmode
src/System/AtomicWrite/Writer/Text.hs view
@@ -1,6 +1,6 @@ -- |--- Module      :  Configuration.Dotenv.Parse--- Copyright   :  © 2015-2017 Stack Builders Inc.+-- Module      :  System.AtomicWrite.Writer.Text+-- Copyright   :  © 2015-2019 Stack Builders Inc. -- License     :  MIT -- -- Maintainer  :  Stack Builders <hackage@stackbuilders.com>@@ -12,13 +12,13 @@  module System.AtomicWrite.Writer.Text (atomicWriteFile, atomicWriteFileWithMode) where -import System.AtomicWrite.Internal (closeAndRename, tempFileFor, maybeSetFileMode)+import           System.AtomicWrite.Internal (atomicWriteFileMaybeModeText) -import Data.Text (Text)+import           Data.Text                   (Text) -import Data.Text.IO (hPutStr)+import           Data.Text.IO                (hPutStr) -import System.Posix.Types (FileMode)+import           System.Posix.Types          (FileMode)  -- | Creates a file atomically on POSIX-compliant -- systems while preserving permissions.@@ -36,8 +36,8 @@   -> FilePath   -- ^ The path where the file will be updated or created   -> Text       -- ^ The content to write to the file   -> IO ()-atomicWriteFileWithMode mode =-  atomicWriteFileMaybeMode $ Just mode+atomicWriteFileWithMode =+  atomicWriteFileMaybeMode . Just  -- Helper Function atomicWriteFileMaybeMode ::@@ -45,7 +45,4 @@   -> FilePath    -- ^ The path where the file will be updated or created   -> Text        -- ^ The content to write to the file   -> IO ()-atomicWriteFileMaybeMode mmode path text =-  tempFileFor path >>= \(tmpPath, h) -> hPutStr h text-                    >> closeAndRename h tmpPath path-                    >> maybeSetFileMode path mmode+atomicWriteFileMaybeMode mmode path = atomicWriteFileMaybeModeText mmode path hPutStr
+ src/System/AtomicWrite/Writer/Text/Binary.hs view
@@ -0,0 +1,48 @@+-- |+-- Module      :  System.AtomicWrite.Writer.Text.Binary+-- Copyright   :  © 2015-2019 Stack Builders Inc.+-- License     :  MIT+--+-- Maintainer  :  Stack Builders <hackage@stackbuilders.com>+-- Stability   :  experimental+-- Portability :  portable+--+-- Provides functionality to dump the contents of a Text+-- to a file in binary mode.++module System.AtomicWrite.Writer.Text.Binary (atomicWriteFile, atomicWriteFileWithMode) where++import           System.AtomicWrite.Internal (atomicWriteFileMaybeModeBinary)++import           Data.Text                   (Text)++import           Data.Text.IO                (hPutStr)++import           System.Posix.Types          (FileMode)++-- | Creates a file atomically on POSIX-compliant+-- systems while preserving permissions.+atomicWriteFile ::+  FilePath   -- ^ The path where the file will be updated or created+  -> Text    -- ^ The content to write to the file+  -> IO ()+atomicWriteFile =+  atomicWriteFileMaybeMode Nothing++-- | Creates or modifies a file atomically on+-- POSIX-compliant systems and updates permissions+atomicWriteFileWithMode ::+  FileMode      -- ^ The mode to set the file to+  -> FilePath   -- ^ The path where the file will be updated or created+  -> Text       -- ^ The content to write to the file+  -> IO ()+atomicWriteFileWithMode =+  atomicWriteFileMaybeMode . Just++-- Helper Function+atomicWriteFileMaybeMode ::+  Maybe FileMode -- ^ The mode to set the file to+  -> FilePath    -- ^ The path where the file will be updated or created+  -> Text        -- ^ The content to write to the file+  -> IO ()+atomicWriteFileMaybeMode mmode path = atomicWriteFileMaybeModeBinary mmode path hPutStr