File size distribution: Difference between revisions

Content added Content deleted
Line 426: Line 426:
fileSizes = foldr f []
fileSizes = foldr f []
where
where
f (File _ n) acc = n : acc
f (File _ n) acc = n:acc
f _ acc = acc
f _ acc = acc


Line 509: Line 509:
| n >= 2^30 && n <= 2^40 = display (2^30) "GB"
| n >= 2^30 && n <= 2^40 = display (2^30) "GB"
| n >= 2^40 && n <= 2^50 = display (2^40) "TB"
| n >= 2^40 && n <= 2^50 = display (2^40) "TB"
| otherwise = printf "%8dB " n
| otherwise = "Too large!"
where
where
display :: Double -> String -> String
display :: Double -> String -> String
Line 519: Line 519:


collectItems :: FilePath -> IO [Item]
collectItems :: FilePath -> IO [Item]
collectItems folderPath = catch tryCollect
collectItems folderPath = catch tryCollect $ \e -> do
(\e -> do
hPrintf stderr "Skipping: %s\n" $ show (e :: IOException)
hPrintf stderr "Skipping: %s\n" $ show (e :: IOException)
pure [])
pure []
where
where
tryCollect = do
tryCollect = do
Line 559: Line 558:
loop :: Chan FilePath -> Chan [Item] -> [Item] -> IO [Item]
loop :: Chan FilePath -> Chan [Item] -> [Item] -> IO [Item]
loop folderChan resultItemsChan xs = do
loop folderChan resultItemsChan xs = do
let fs = folders xs
regularFolders <- filterM (pathIsSymbolicLink >=> (pure . not)) $ folders xs
regularFolders <- filterM (pathIsSymbolicLink >=> (pure . not)) fs
if null regularFolders then pure []
if null regularFolders then pure []
else do
else do
Line 583: Line 581:
putStrLn $ replicate 46 '-'
putStrLn $ replicate 46 '-'
let results = expandedGroups groupSize (sizes items) (groupThreshold fileCount) items
let results = expandedGroups groupSize (sizes items) (groupThreshold fileCount) items
-- let results = initialGroups groupSize items
mapM_ (displayFrequency fileCount) $ Map.assocs results
mapM_ (displayFrequency fileCount) $ Map.assocs results
where
where