File tree Expand file tree Collapse file tree 2 files changed +25
-5
lines changed Expand file tree Collapse file tree 2 files changed +25
-5
lines changed Original file line number Diff line number Diff line change @@ -14,7 +14,9 @@ import Data.Attoparsec.ByteString.Char8 (
1414 double ,
1515 endOfLine ,
1616 isEndOfLine ,
17+ skipSpace ,
1718 takeTill ,
19+ try ,
1820 )
1921import NOM.Builds (
2022 Derivation (.. ),
@@ -80,10 +82,28 @@ planDownloads =
8082 , string " these " *> (decimal :: Parser Int ) *> string " paths"
8183 ]
8284 *> string " will be fetched ("
83- *> double
85+ *> byteSize
8486 )
85- <*> (string " MiB download, " *> double)
86- <*> (string " MiB unpacked):" *> endOfLine *> (fromList <$> many planDownloadLine))
87+ <*> (" download, " *> byteSize)
88+ <*> (" unpacked):" *> endOfLine *> (fromList <$> many planDownloadLine))
89+
90+ byteSize :: Parser Double
91+ byteSize = do
92+ num <- double
93+ skipSpace
94+ unit <- anyChar
95+ _ <- try (string " iB" )
96+ power <- case unit of
97+ ' K' -> pure 1
98+ ' M' -> pure 2
99+ ' G' -> pure 3
100+ ' T' -> pure 4
101+ ' P' -> pure 5
102+ ' E' -> pure 6
103+ ' Z' -> pure 7
104+ ' Y' -> pure 8
105+ x -> fail $ " Unknown unit: " <> [x] <> " iB"
106+ pure $ num * (1024 ** power)
87107
88108planDownloadLine :: Parser StorePath
89109planDownloadLine = indent *> storePathByteStringParser <* endOfLine
Original file line number Diff line number Diff line change @@ -45,8 +45,8 @@ main = do
4545 assertEqual
4646 " result matches"
4747 ( PlanDownloads
48- 134.19
49- 1863.82
48+ ( 134.19 * 1024 ** 2 )
49+ ( 1863.82 * 1024 ** 2 )
5050 (singleton (StorePath " 60zb5dndaw1fzir3s69sy3xhy19gll1p" " ghc-8.8.2" ))
5151 )
5252 result2
You can’t perform that action at this time.
0 commit comments