sak 0.1.2.6 → 0.1.3.0
raw patch · 6 files changed
+44/−8 lines, 6 filesdep +unix-compat
Dependencies added: unix-compat
Files
- CHANGELOG.md +5/−0
- sak.cabal +3/−2
- src/Compression.cpphs +1/−0
- src/Compression/Type.cpphs +1/−0
- src/Info.cpphs +9/−2
- src/Main.hs +25/−4
CHANGELOG.md view
@@ -1,5 +1,10 @@ # sak +## 0.1.3.0++ * Preserve file permissions+ * Detect brotli streams+ ## 0.1.2.6 * Default to `-with-snappy` for sake of Mac
sak.cabal view
@@ -1,6 +1,6 @@ cabal-version: 1.18 name: sak-version: 0.1.2.6+version: 0.1.3.0 license: BSD3 license-file: LICENSE copyright: Copyright: (c) 2020 Vanessa McHale@@ -62,7 +62,8 @@ bytestring -any, directory >=1.3.1.0, parallel-io -any,- lzo >=0.1.1.0+ lzo >=0.1.1.0,+ unix-compat -any if flag(with-snappy) build-depends: snappy-lazy -any
src/Compression.cpphs view
@@ -92,6 +92,7 @@ #endif | ".lzo" `isSuffixOf` fp = Lzo | ".tzo" `isSuffixOf` fp = Lzo+ | ".lrz" `isSuffixOf` fp = Lrzip | otherwise = None -- error "Suffix not supported or invalid" toFileDecompressor :: Compression -> FilePath -> IO BSL.ByteString
src/Compression/Type.cpphs view
@@ -15,5 +15,6 @@ | Lzo | Lz4 | Z+ | Lrzip | None deriving (Show, Enum)
src/Info.cpphs view
@@ -15,10 +15,17 @@ | xzMagic `isPrefixOf` bs = Lzma | zstdMagic `isPrefixOf` bs = Zstd | bzMagic `isPrefixOf` bs = BZip+ | lrzipMagic `isPrefixOf` bs = Lrzip+#ifdef BROTLI+ | brotliMagic `isPrefixOf` bs = Brotli+#endif | otherwise = None --- lrzipMagic :: BS.ByteString--- lrzipMagic = BS.pack [0x4c, 0x52, 0x5a, 0x49]+brotliMagic :: BS.ByteString+brotliMagic = BS.pack [0xce, 0xb2, 0xcf, 0x81]++lrzipMagic :: BS.ByteString+lrzipMagic = BS.pack [0x4c, 0x52, 0x5a, 0x49] zstdMagic :: BS.ByteString zstdMagic = BS.pack [0x28, 0xb5, 0x2f, 0xfd]
src/Main.hs view
@@ -11,6 +11,8 @@ import Detect import Options.Applicative import System.Directory (getSymbolicLinkTarget, pathIsSymbolicLink)+import System.PosixCompat.Files (fileMode, getFileStatus, setFileMode)+import System.PosixCompat.Types (FileMode) import Version (allVersionsString) reifyPath :: FilePath -> IO FilePath@@ -20,6 +22,15 @@ then getSymbolicLinkTarget fp else pure fp +-- setFileMode, getFileMode+getFilePerms :: FilePath -> IO FileMode+getFilePerms = fmap fileMode . getFileStatus++matchPerms :: FilePath -- ^ Input+ -> FilePath -- ^ Output+ -> IO ()+matchPerms inp o = setFileMode o =<< getFilePerms inp+ data Command = Decompress !FilePath !(Maybe FilePath) | Compress !FilePath !FilePath !CompressionLevel | Recompress !FilePath !CompressionLevel@@ -52,7 +63,10 @@ decompressFile :: FilePath -- ^ Compressed file -> FilePath -- ^ Output -> IO ()-decompressFile inp o = BSL.writeFile o =<< f inp+decompressFile inp o =+ (BSL.writeFile o =<< f inp) *>+ matchPerms inp o+ where f = toFileDecompressor (detectCompression inp) decompressDetectFile :: FilePath -- ^ Compressed file@@ -61,20 +75,26 @@ decompressDetectFile inp o = do f <- toFileDecompressor <$> (detectFileCompression inp) BSL.writeFile o =<< (f inp)+ matchPerms inp o compressFile :: CompressionLevel -> FilePath -- ^ Input file -> FilePath -- ^ Compressed output -> IO ()-compressFile lvl inp o = BSL.writeFile o =<< f inp+compressFile lvl inp o =+ (BSL.writeFile o =<< f inp) *>+ matchPerms inp o+ where f = toFileCompressor (detectCompression o) lvl compressMatrix :: CompressionLevel -> FilePath -> Compression -> IO ()-compressMatrix lvl inp c =- BSL.writeFile (inp ++ ext c) =<< toFileCompressor c lvl inp+compressMatrix lvl inp c = do+ let o = inp ++ ext c+ BSL.writeFile o =<< toFileCompressor c lvl inp+ matchPerms inp o run :: Command -> IO () run (Recompress i lvl) = recompressFile lvl =<< reifyPath i@@ -87,6 +107,7 @@ Lzip -> Just . (8*) . fromIntegral <$> fileSize i _ -> pure Nothing BSL.writeFile o . toCompressor cO lvl guessSz =<< toFileDecompressor (detectCompression i) =<< reifyPath i+ matchPerms i o run (Verify i) = check (detectCompression i) =<< BSL.readFile =<< reifyPath i run (Matrix inp lvl) = parallel_ (compressMatrix lvl inp <$> [Lzma .. Lz4]) *>