-- | Try to ensure that a directory, and all its parents exist, creating them
-- if needed with the given access mode. Note that due to permissions or other
-- issues this can fail with various thrown excpetions.
createPath :: (PosixLike m) => FilePath -> FileMode -> m ()
createPath fp mode = do
    s <- (isDirectory `fmap` getFileStatus fp)
            `catchIOError` (const $ return False)
    unless s $ do
        createPath (takeDirectory fp) mode
        createDirectory fp mode

-- | Simplify a file path, elminiating . and .. components (if possible)
createPath :: (PosixLike m) => FilePath -> FileMode -> m ()
createPath fp mode = do
    s <- (isDirectory `fmap` getFileStatus fp)
            `catchIOError` (const $ return False)
    unless s $ do
        createPath (takeDirectory fp) mode
        createDirectory fp mode

-- | Simplify a file path, elminiating . and .. components (if possible)
createPath fp mode = do
    s <- (isDirectory `fmap` getFileStatus fp)
            `catchIOError` (const $ return False)
    unless s $ do
        createPath (takeDirectory fp) mode
        createDirectory fp mode

-- | Simplify a file path, elminiating . and .. components (if possible)