aboutsummaryrefslogtreecommitdiff
path: root/Utility/DiskFree.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-01-22 22:19:52 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-01-22 22:19:52 -0400
commitd1c13779bb4606cdb6d80a6e1dfd2cdb11478199 (patch)
tree37c866991f327eefe92a4d7abe30d9c3200b4efb /Utility/DiskFree.hs
parent9042ae3f4a12e2af802557f571bb793ab94b40d3 (diff)
add getDiskSize
Couldn't find anything that exposed this for Windows.
Diffstat (limited to 'Utility/DiskFree.hs')
-rw-r--r--Utility/DiskFree.hs28
1 files changed, 23 insertions, 5 deletions
diff --git a/Utility/DiskFree.hs b/Utility/DiskFree.hs
index f04f636ec..2f296e2cb 100644
--- a/Utility/DiskFree.hs
+++ b/Utility/DiskFree.hs
@@ -1,13 +1,16 @@
{- disk free space checking
-
- - Copyright 2012 Joey Hess <joey@kitenet.net>
+ - Copyright 2012, 2014 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
{-# LANGUAGE ForeignFunctionInterface, CPP #-}
-module Utility.DiskFree ( getDiskFree ) where
+module Utility.DiskFree (
+ getDiskFree,
+ getDiskSize
+) where
#ifdef WITH_CLIBS
@@ -20,9 +23,12 @@ import Foreign.C.Error
foreign import ccall safe "libdiskfree.h diskfree" c_diskfree
:: CString -> IO CULLong
-getDiskFree :: FilePath -> IO (Maybe Integer)
-getDiskFree path = withFilePath path $ \c_path -> do
- free <- c_diskfree c_path
+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
@@ -30,6 +36,12 @@ getDiskFree path = withFilePath path $ \c_path -> do
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
@@ -41,6 +53,9 @@ getDiskFree :: FilePath -> IO (Maybe Integer)
getDiskFree path = catchMaybeIO $ do
(sectors, bytes, nfree, _ntotal) <- getDiskFreeSpace (Just path)
return $ toInteger sectors * toInteger bytes * toInteger nfree
+
+getDiskSize :: FilePath -> IO (Maybe Integer)
+getDiskSize _ = return Nothing
#else
#warning Building without disk free space checking support
@@ -48,5 +63,8 @@ getDiskFree path = catchMaybeIO $ do
getDiskFree :: FilePath -> IO (Maybe Integer)
getDiskFree _ = return Nothing
+getDiskSize :: FilePath -> IO (Maybe Integer)
+getDiskSize _ = return Nothing
+
#endif
#endif