packages feed

ztar 0.1.1 → 0.1.2

raw patch · 4 files changed

+32/−15 lines, 4 filesdep +bytestring-arbitrarydep +deepseqdep ~bytestring

Dependencies added: bytestring-arbitrary, deepseq

Dependency ranges changed: bytestring

Files

CHANGELOG.md view
@@ -1,3 +1,8 @@+# ztar 0.1.2++Changes:+* Fix for creating archives of non-UTF8 encoded files+ # ztar 0.1.1  Changes:
src/Codec/Archive/Tar.hs view
@@ -20,10 +20,9 @@  module Codec.Archive.Tar where +import Control.DeepSeq (force)+import Control.Exception (evaluate) import qualified Data.ByteString.Lazy as BS-import qualified Data.Text.IO as Text-import qualified Data.Text.Lazy as TextL-import qualified Data.Text.Lazy.Encoding as TextL import GHC.IO.Handle (hClose) import Prelude hiding (read) import System.Directory (createDirectoryIfMissing, removeFile)@@ -56,7 +55,7 @@   (archive, h) <- mkstemp "tar-pack"   hClose h   tar $ ["-cf", archive, "-C", base] ++ paths-  contents <- TextL.encodeUtf8 . TextL.fromStrict <$> Text.readFile archive+  contents <- evaluate . force =<< BS.readFile archive   removeFile archive   return $ TarArchive contents 
test/Test.hs view
@@ -3,6 +3,8 @@ import Codec.Archive.ZTar import Control.Monad (forM, forM_) import Control.Monad.Extra (unlessM)+import qualified Data.ByteString as BS+import Data.ByteString.Arbitrary (ArbByteString(..)) import Data.List (dropWhileEnd, intercalate, nub) import Data.Maybe (fromJust) import Path@@ -19,8 +21,8 @@     , (</>)     ) import Path.IO (doesFileExist, ensureDir, isLocationOccupied, withTempDir)-import Test.QuickCheck (Arbitrary(..), Gen, Property, elements, listOf, listOf1, suchThat)-import Test.QuickCheck.Monadic (monadicIO, pick, run)+import Test.QuickCheck+import Test.QuickCheck.Monadic import Test.Tasty (defaultMain, testGroup) import Test.Tasty.QuickCheck (testProperty) @@ -35,19 +37,22 @@ testZTar compression = monadicIO $ do   archive:src:dest:paths <- pick $ uniqueListOf 4 arbitrary +  files <- forM paths $ \path -> do+    Blind (ABS contents) <- pick arbitrary+    return (toRelFile path, contents)+   run $ withTempDir [absdir|/tmp|] "" $ \dir -> do-    let paths' = map toRelFile paths-        archive' = dir </> toRelFile archive+    let archive' = dir </> toRelFile archive         src' = dir </> toRelDir src         dest' = dir </> toRelDir dest      -- write files to be bundled-    forM_ paths' $ \path -> do+    forM_ files $ \(path, contents) -> do       let path' = src' </> path       -- case writing `a` when `a/b` already exists       unlessM (isLocationOccupied path') $ do         ensureDir $ parent path'-        writeFile (fromAbsFile path') (show path)+        BS.writeFile (fromAbsFile path') contents      -- create and extract archive     ensureDir $ parent archive'@@ -55,15 +60,15 @@     extract (fromAbsDir dest') (fromAbsFile archive')      -- check files-    fmap and $ forM paths' $ \path -> do+    fmap and $ forM files $ \(path, contents) -> do       let path' = dest' </> path       isExist <- isLocationOccupied path'       isFile <- doesFileExist path'       case (isExist, isFile) of         (False, _) -> return False         (True, True) -> do-          contents <- readFile $ fromAbsFile path'-          return $ contents == show path+          contents' <- BS.readFile $ fromAbsFile path'+          return $ contents' == contents         (True, False) -> return True  {- Helpers -}@@ -99,7 +104,12 @@   arbitrary = do     -- https://stackoverflow.com/a/2306003/8565175     name <- take 14 <$> listOf1 (elements validChars)-    if last name == '.' || name `elem` ["nul"]+    if or+      [ last name == '.'+      , name `elem` ["nul"]+      -- https://superuser.com/questions/259703/get-mac-tar-to-stop-putting-filenames-in-tar-archives+      , name !! 0 == '.' && name !! 1 == '_'+      ]       then arbitrary       else return $ ValidName name     where
ztar.cabal view
@@ -1,5 +1,5 @@ name:                ztar-version:             0.1.1+version:             0.1.2 license:             BSD3 license-file:        LICENSE.md author:              Brandon Chinn <brandonchinn178@gmail.com>@@ -37,6 +37,7 @@                     , zip >= 0.2 && < 0.3                     , zlib >= 0.6 && < 0.7                     -- For Codec.Archive.Tar+                    , deepseq                     , process                     , text                     , unix-compat@@ -75,6 +76,8 @@   hs-source-dirs:     test   main-is:            Test.hs   build-depends:      base+                    , bytestring+                    , bytestring-arbitrary                     , extra                     , path                     , path-io