summaryrefslogtreecommitdiff
path: root/Utility/DiskFree.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-03-05 11:22:32 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-03-05 11:22:32 -0400
commit80de75d25c19f37564ac6db97db534f40d26f108 (patch)
tree0ccf8611ba4fdfdccb6f90cee16c76a481d9feaa /Utility/DiskFree.hs
parentaa5de5e25c46cbf5c0eb2cd6e0fb6e84be5586fb (diff)
parentcd8e2e4eeb70d22f9a7daa375474d80aa188574b (diff)
Merge branch 'no-cbits'
Diffstat (limited to 'Utility/DiskFree.hs')
-rw-r--r--Utility/DiskFree.hs63
1 files changed, 8 insertions, 55 deletions
diff --git a/Utility/DiskFree.hs b/Utility/DiskFree.hs
index c4125d4f0..fe3a4577c 100644
--- a/Utility/DiskFree.hs
+++ b/Utility/DiskFree.hs
@@ -1,70 +1,23 @@
-{- disk free space checking
+{- disk free space checking shim
-
- - Copyright 2012, 2014 Joey Hess <id@joeyh.name>
+ - Copyright 2016 Joey Hess <id@joeyh.name>
-
- License: BSD-2-clause
-}
-{-# LANGUAGE ForeignFunctionInterface, CPP #-}
+{-# OPTIONS_GHC -fno-warn-tabs #-}
module Utility.DiskFree (
getDiskFree,
getDiskSize
) where
-#ifdef WITH_CLIBS
-
-import Common
-
-import Foreign.C.Types
-import Foreign.C.String
-import Foreign.C.Error
-
-foreign import ccall safe "libdiskfree.h diskfree" c_diskfree
- :: CString -> IO CULLong
-
-foreign import ccall safe "libdiskfree.h disksize" c_disksize
- :: CString -> IO CULLong
-
-getVal :: (CString -> IO CULLong) -> FilePath -> IO (Maybe Integer)
-getVal getter path = withFilePath path $ \c_path -> do
- free <- getter c_path
- ifM (safeErrno <$> getErrno)
- ( return $ Just $ toInteger free
- , return Nothing
- )
- where
- safeErrno (Errno v) = v == 0
-
-getDiskFree :: FilePath -> IO (Maybe Integer)
-getDiskFree = getVal c_diskfree
-
-getDiskSize :: FilePath -> IO (Maybe Integer)
-getDiskSize = getVal c_disksize
-
-#else
-#ifdef mingw32_HOST_OS
-
-import Common
-
-import System.Win32.File
+import System.DiskSpace
+import Utility.Applicative
+import Utility.Exception
getDiskFree :: FilePath -> IO (Maybe Integer)
-getDiskFree path = catchMaybeIO $ do
- (sectors, bytes, nfree, _ntotal) <- getDiskFreeSpace (Just path)
- return $ toInteger sectors * toInteger bytes * toInteger nfree
+getDiskFree = catchMaybeIO . getAvailSpace
getDiskSize :: FilePath -> IO (Maybe Integer)
-getDiskSize _ = return Nothing
-#else
-
-#warning Building without disk free space checking support
-
-getDiskFree :: FilePath -> IO (Maybe Integer)
-getDiskFree _ = return Nothing
-
-getDiskSize :: FilePath -> IO (Maybe Integer)
-getDiskSize _ = return Nothing
-
-#endif
-#endif
+getDiskSize = fmap diskTotal <$$> catchMaybeIO . getDiskUsage