Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: d20cd192cc
Fetching contributors…

Cannot retrieve contributors at this time

file 29 lines (23 sloc) 0.655 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
{- disk free space checking
-
- Copyright 2012 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}

{-# LANGUAGE ForeignFunctionInterface #-}

module Utility.DiskFree ( getDiskFree ) where

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

getDiskFree :: FilePath -> IO (Maybe Integer)
getDiskFree path = withFilePath path $ \c_path -> do
free <- c_diskfree c_path
ifM (safeErrno <$> getErrno)
( return $ Just $ toInteger free
, return Nothing
)
where
safeErrno (Errno v) = v == 0
Something went wrong with that request. Please try again.