sizes 1.0.0 → 1.0.2
raw patch · 2 files changed
+16/−18 lines, 2 files
Files
- Main.hs +15/−17
- sizes.cabal +1/−1
Main.hs view
@@ -22,10 +22,10 @@ import System.Posix.Files import Text.Printf -default (Int, Text)+default (Integer, Text) version :: String-version = "1.0.0"+version = "1.0.2" copyright :: String copyright = "2012"@@ -59,19 +59,19 @@ help "Calculate amount of disk used by the given directories" data EntryInfo = EntryInfo { _entryPath :: !FilePath- , _entryCount :: !Int- , _entrySize :: !Int+ , _entryCount :: !Integer+ , _entrySize :: !Integer , _entryIsDir :: !Bool } deriving Show +makeLenses ''EntryInfo+ instance NFData EntryInfo where rnf a = a `seq` () newEntry :: FilePath -> Bool -> EntryInfo-newEntry p isDir = EntryInfo p 0 0 isDir--makeLenses ''EntryInfo-+newEntry p = EntryInfo p 0 0+ main :: IO () main = do mainArgs <- getArgs@@ -85,9 +85,6 @@ reportSizes opts $ map (fromText . pack) (dirs opts) stopGlobalPool -parMap :: (a -> IO b) -> [a] -> IO ()-parMap f xs = parallel (map f xs) >> return ()- reportSizes :: SizesOpts -> [FilePath] -> IO () reportSizes opts xs = do entryInfos <- parallel $ map (gatherSizesW (depth opts) 0) xs@@ -101,7 +98,7 @@ || entry^.entryCount > 100) $ reportEntry entry -humanReadable :: Int -> String+humanReadable :: Integer -> String humanReadable x | x < 1024 = printf "%db" x | x < 1024^2 = printf "%.0fK" (fromIntegral x / (1024 :: Double))@@ -109,7 +106,8 @@ | x < 1024^4 = printf "%.2fG" (fromIntegral x / (1024^3 :: Double)) | x < 1024^5 = printf "%.3fT" (fromIntegral x / (1024^4 :: Double)) | x < 1024^6 = printf "%.3fP" (fromIntegral x / (1024^5 :: Double))- | otherwise = error "Too large"+ | x < 1024^7 = printf "%.3fX" (fromIntegral x / (1024^6 :: Double))+ | otherwise = printf "%db" x reportEntry :: EntryInfo -> IO () reportEntry entry =@@ -118,7 +116,7 @@ (humanReadable (entry^.entrySize)) (entry^.entryCount) path (unpack $ if entry^.entryIsDir && L.last path /= '/' then "/" else "")-+ toTextIgnore :: FilePath -> Text toTextIgnore p = case toText p of Left _ -> ""; Right x -> x @@ -126,7 +124,7 @@ gatherSizesW m d p = catch (gatherSizes m d p) (\e -> do- putStrLn $ show (e :: IOException)+ print (e :: IOException) return (newEntry p False, [])) gatherSizes :: Int -> Int -> FilePath -> IO (EntryInfo, [EntryInfo])@@ -149,12 +147,12 @@ (newEntry path True) firsts , if curDepth < maxDepth- then firsts ++ L.concat (map snd entries)+ then firsts ++ L.concatMap snd entries else [] ) else if isRegularFile status then return ( entryCount .~ 1 $- entrySize .~ fromIntegral (fileSize status) $+ entrySize .~ fromIntegral (fileSize status) $ newEntry path False, [] ) else return (newEntry path False, [])
sizes.cabal view
@@ -1,6 +1,6 @@ Name: sizes -Version: 1.0.0+Version: 1.0.2 Synopsis: Recursively show space (size and i-nodes) used in subdirectories Description: Recursively show space (size and i-nodes) used in subdirectories