[commit: packages/directory] master: Improve error of removeDirectoryRecursive on dir symlinks (4490526)

git at git.haskell.org git at git.haskell.org
Sat Apr 16 19:13:32 UTC 2016


Repository : ssh://git@git.haskell.org/directory

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/4490526d4065ac4b2d1f09aa6fefc54cde62888b/directory

>---------------------------------------------------------------

commit 4490526d4065ac4b2d1f09aa6fefc54cde62888b
Author: Phil Ruffwind <rf at rufflewind.com>
Date:   Thu Apr 14 02:30:27 2016 -0400

    Improve error of removeDirectoryRecursive on dir symlinks


>---------------------------------------------------------------

4490526d4065ac4b2d1f09aa6fefc54cde62888b
 System/Directory.hs | 14 ++++++++++----
 changelog.md        |  3 +++
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/System/Directory.hs b/System/Directory.hs
index 5e709fd..7e5edb1 100644
--- a/System/Directory.hs
+++ b/System/Directory.hs
@@ -553,15 +553,21 @@ removeDirectory path =
 
 -- | @'removeDirectoryRecursive' dir@ removes an existing directory /dir/
 -- together with its contents and subdirectories. Within this directory,
--- symbolic links are removed without affecting their the targets.
+-- symbolic links are removed without affecting their targets.
+--
+-- On Windows, the operation fails if /dir/ is a directory symbolic link.
 removeDirectoryRecursive :: FilePath -> IO ()
 removeDirectoryRecursive path =
   (`ioeSetLocation` "removeDirectoryRecursive") `modifyIOError` do
     dirType <- getDirectoryType path
     case dirType of
-      Directory -> removeContentsRecursive path
-      _         -> ioError . (`ioeSetErrorString` "not a directory") $
-                   mkIOError InappropriateType "" Nothing (Just path)
+      Directory ->
+        removeContentsRecursive path
+      DirectoryLink ->
+        ioError (err `ioeSetErrorString` "is a directory symbolic link")
+      NotDirectory ->
+        ioError (err `ioeSetErrorString` "not a directory")
+  where err = mkIOError InappropriateType "" Nothing (Just path)
 
 -- | @'removePathRecursive' path@ removes an existing file or directory at
 -- /path/ together with its contents and subdirectories. Symbolic links are
diff --git a/changelog.md b/changelog.md
index bf0d660..f917252 100644
--- a/changelog.md
+++ b/changelog.md
@@ -12,6 +12,9 @@ Changelog for the [`directory`][1] package
   * Add `copyFileWithAttrs`, which copies additional metadata
     ([#40](https://github.com/haskell/directory/issues/40))
 
+  * Improve error message of `removeDirectoryRecursive` when used on a
+    directory symbolic link on Windows.
+
 ## 1.2.5.1 (February 2015)
 
   * Improve error message of `getCurrentDirectory` when the current working



More information about the ghc-commits mailing list