removeDirectoryRecursive :: Options -> FilePath -> IO ()
removeDirectoryRecursive opts fp = do
    when (optReportRemove opts) $ putStrLn fp
    case (optRemove opts) of
        OptDryRun -> return ()
        OptScript -> putStrLn ("rm -rf " ++ fp)
        OptRemove -> rmrf fp
  where
    rmrf f = do
        st <- getSymbolicLinkStatus f
        if isDirectory st
            then do
                entries f >>= mapM_ rmrf
                safely f $ removeDirectory f
            else
                safely f $ removeLink f

-- | Remove a file. Like shell command "rm -f".
-- If file is a symlinks, removes the symlink, not what it points to.
removeDirectoryRecursive :: Options -> FilePath -> IO ()
removeDirectoryRecursive opts fp = do
    when (optReportRemove opts) $ putStrLn fp
    case (optRemove opts) of
        OptDryRun -> return ()
        OptScript -> putStrLn ("rm -rf " ++ fp)
        OptRemove -> rmrf fp
  where
    rmrf f = do
        st <- getSymbolicLinkStatus f
        if isDirectory st
            then do
                entries f >>= mapM_ rmrf
                safely f $ removeDirectory f
            else
                safely f $ removeLink f

-- | Remove a file. Like shell command "rm -f".
-- If file is a symlinks, removes the symlink, not what it points to.
removeDirectoryRecursive opts fp = do
    when (optReportRemove opts) $ putStrLn fp
    case (optRemove opts) of
        OptDryRun -> return ()
        OptScript -> putStrLn ("rm -rf " ++ fp)
        OptRemove -> rmrf fp
  where
    rmrf f = do
        st <- getSymbolicLinkStatus f
        if isDirectory st
            then do
                entries f >>= mapM_ rmrf
                safely f $ removeDirectory f
            else
                safely f $ removeLink f

-- | Remove a file. Like shell command "rm -f".
-- If file is a symlinks, removes the symlink, not what it points to.