Haskell removeDirectoryRecursive: Permission denied on Windows

When I use removeDirectoryRecursiveWindows, the IOExceptiontype PermissionDeniedis issued with the message "removeDirectoryRecursive: rejection allowed." I have the necessary permissions to delete a directory. This problem does not occur on Linux for a directory with identical contents.

+4
source share
1 answer

If the directory you want to delete contains read-only files, they will not be deleted on Windows, but on Linux.

There is removePathForcibly, but it was introduced only recently .

, , . removeDirectoryRecursive.

import Control.Monad (forM_, when)
import System.FilePath ((</>))
import qualified System.Directory as FileSystem

-- Recursively makes all files and directories in a directory writable.
-- On Windows this is required to be able to recursively delete the directory.
makeWritableRecursive :: FilePath -> IO ()
makeWritableRecursive path = do
  permissions <- FileSystem.getPermissions path
  FileSystem.setPermissions path (FileSystem.setOwnerWritable True permissions)
  isDirectory <- FileSystem.doesDirectoryExist path
  when isDirectory $ do
    contents <- FileSystem.listDirectory path
    forM_ [path </> item | item <- contents] makeWritableRecursive
+3

Source: https://habr.com/ru/post/1651130/


All Articles