nix-diff 1.0.16 → 1.0.17
raw patch · 3 files changed
+21/−4 lines, 3 filesdep +bytestringdep ~attoparsec
Dependencies added: bytestring
Dependency ranges changed: attoparsec
Files
- CHANGELOG.md +4/−0
- nix-diff.cabal +2/−1
- src/Main.hs +15/−3
CHANGELOG.md view
@@ -1,3 +1,7 @@+1.0.17++* [Handle `.drv` and `.nix` files that contain non-UTF8 text](https://github.com/Gabriel439/nix-diff/pull/50)+ 1.0.16 * [Accept realised store paths as input](https://github.com/Gabriel439/nix-diff/pull/47)
nix-diff.cabal view
@@ -1,5 +1,5 @@ name: nix-diff-version: 1.0.16+version: 1.0.17 synopsis: Explain why two Nix derivations differ description: This package provides a @nix-diff@ executable which explains why two Nix derivations (i.e. @*.drv@ files)@@ -21,6 +21,7 @@ main-is: Main.hs build-depends: base >= 4.9 && < 5 , attoparsec >= 0.13 && < 0.14+ , bytestring >= 0.9 && < 0.12 , containers >= 0.5 && < 0.7 , directory < 1.4 , mtl >= 2.2 && < 2.3
src/Main.hs view
@@ -49,6 +49,9 @@ #if MIN_VERSION_base(4,9,0) import Control.Monad.Fail (MonadFail)+import qualified Data.ByteString+import qualified Data.Text.Encoding+import qualified Data.Text.Encoding.Error #endif data Color = Always | Auto | Never@@ -208,11 +211,20 @@ where predicate key' = buildProductName key == buildProductName key' +-- | Read a file as utf-8 encoded string, replacing non-utf-8 characters+-- with the unicode replacement character.+-- This is necessary since derivations (and nix source code!) can in principle+-- contain arbitrary bytes, but `nix-derivation` can only parse from 'Text'.+readFileUtf8Lenient :: FilePath -> IO Text+readFileUtf8Lenient file =+ Data.Text.Encoding.decodeUtf8With Data.Text.Encoding.Error.lenientDecode+ <$> Data.ByteString.readFile file+ -- | Read and parse a derivation from a file readDerivation :: FilePath -> Diff (Derivation FilePath Text) readDerivation path = do let string = path- text <- liftIO (Text.IO.readFile string)+ text <- liftIO (readFileUtf8Lenient string) case Data.Attoparsec.Text.parse Nix.Derivation.parseDerivation text of Done _ derivation -> do return derivation@@ -573,8 +585,8 @@ rightExists <- liftIO (Directory.doesFileExist rightPath) if leftExists && rightExists then do- leftText <- liftIO (Text.IO.readFile leftPath)- rightText <- liftIO (Text.IO.readFile rightPath)+ leftText <- liftIO (readFileUtf8Lenient leftPath)+ rightText <- liftIO (readFileUtf8Lenient rightPath) text <- diffText leftText rightText echo (" " <> text)