+#ifdef mingw32_HOST_OS
+ System.Win32.createDirectory path Nothing
+#else
+ System.Posix.createDirectory path 0o777
+#endif
+
+#else /* !__GLASGOW_HASKELL__ */
+
+copyPermissions :: FilePath -> FilePath -> IO ()
+copyPermissions fromFPath toFPath
+ = getPermissions fromFPath >>= setPermissions toFPath
+
+#endif
+
+-- | @'createDirectoryIfMissing' parents dir@ creates a new directory
+-- @dir@ if it doesn\'t exist. If the first argument is 'True'
+-- the function will also create all parent directories if they are missing.
+createDirectoryIfMissing :: Bool -- ^ Create its parents too?
+ -> FilePath -- ^ The path to the directory you want to make
+ -> IO ()
+createDirectoryIfMissing create_parents "" = return ()
+createDirectoryIfMissing create_parents path0
+ = do r <- try $ createDirectory path
+ case (r :: Either IOException ()) of
+ Right _ -> return ()
+ Left e
+ | isAlreadyExistsError e -> return ()
+ | isDoesNotExistError e && create_parents -> do
+ createDirectoryIfMissing True (dropFileName path)
+ createDirectoryIfMissing True path
+ | otherwise -> throw e
+ where
+ -- we want createDirectoryIfMissing "a/" to behave like
+ -- createDirectoryIfMissing "a". Also, unless we apply
+ -- dropTrailingPathSeparator first, dropFileName won't drop
+ -- anything from "a/".
+ path = dropTrailingPathSeparator path0