module Compat.Directory (
getAppUserDataDirectory,
copyFile,
- findExecutable
+ findExecutable,
+ createDirectoryIfMissing
) where
#if __GLASGOW_HASKELL__ < 603
import System.Environment (getEnv)
import System.FilePath
import System.IO
-#if defined(mingw32_TARGET_OS)
import Foreign
import Foreign.C
-#endif
-import System.Directory(doesFileExist, getPermissions, setPermissions)
+import System.Directory(doesFileExist, doesDirectoryExist, getPermissions, setPermissions, createDirectory)
#if defined(__GLASGOW_HASKELL__)
import GHC.IOBase ( IOException(..) )
#endif
-> CString
-> IO CInt
-foreign import ccall unsafe "__hscore_long_path_size"
+-- __compat_long_path_size defined in cbits/directory.c
+foreign import ccall unsafe "__compat_long_path_size"
long_path_size :: Int
foreign import ccall unsafe "__hscore_CSIDL_APPDATA" csidl_APPDATA :: CInt
b <- doesFileExist path
if b then return (Just path)
else search ds
+
+createDirectoryIfMissing :: Bool -- ^ Create its parents too?
+ -> FilePath -- ^ The path to the directory you want to make
+ -> IO ()
+createDirectoryIfMissing parents file = do
+ b <- doesDirectoryExist file
+ case (b,parents, file) of
+ (_, _, "") -> return ()
+ (True, _, _) -> return ()
+ (_, True, _) -> mapM_ (createDirectoryIfMissing False) (tail (pathParents file))
+ (_, False, _) -> createDirectory file