e213ef310f
* Fix minor FD leak in journal code. Closes: #754608 * direct: Fix handling of case where a work tree subdirectory cannot be written to due to permissions. * migrate: Avoid re-checksumming when migrating from hashE to hash backend. * uninit: Avoid failing final removal in some direct mode repositories due to file modes. * S3: Deal with AWS ACL configurations that do not allow creating or checking the location of a bucket, but only reading and writing content to it. * resolvemerge: New plumbing command that runs the automatic merge conflict resolver. * Deal with change in git 2.0 that made indirect mode merge conflict resolution leave behind old files. * sync: Fix git sync with local git remotes even when they don't have an annex.uuid set. (The assistant already did so.) * Set gcrypt-publish-participants when setting up a gcrypt repository, to avoid unncessary passphrase prompts. This is a security/usability tradeoff. To avoid exposing the gpg key ids who can decrypt the repository, users can unset gcrypt-publish-participants. * Install nautilus hooks even when ~/.local/share/nautilus/ does not yet exist, since it is not automatically created for Gnome 3 users. * Windows: Move .vbs files out of git\bin, to avoid that being in the PATH, which caused some weird breakage. (Thanks, divB) * Windows: Fix locking issue that prevented the webapp starting (since 5.20140707). # imported from the archive
70 lines
1.5 KiB
Haskell
70 lines
1.5 KiB
Haskell
{- disk free space checking
|
|
-
|
|
- Copyright 2012, 2014 Joey Hess <joey@kitenet.net>
|
|
-
|
|
- License: BSD-2-clause
|
|
-}
|
|
|
|
{-# LANGUAGE ForeignFunctionInterface, CPP #-}
|
|
|
|
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
|
|
|
|
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
|
|
|
|
getDiskFree :: FilePath -> IO (Maybe Integer)
|
|
getDiskFree _ = return Nothing
|
|
|
|
getDiskSize :: FilePath -> IO (Maybe Integer)
|
|
getDiskSize _ = return Nothing
|
|
|
|
#endif
|
|
#endif
|