[commit: packages/directory] master: Drop trailing path separators in `getPermissions` on Windows (3e56351)

git at git.haskell.org git at git.haskell.org
Thu Mar 19 11:37:58 UTC 2015


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

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/3e5635133c9ee42596ac0353f6856cef69dd09ff/directory

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

commit 3e5635133c9ee42596ac0353f6856cef69dd09ff
Author: Phil Ruffwind <rf at rufflewind.com>
Date:   Mon Mar 2 20:21:13 2015 -0500

    Drop trailing path separators in `getPermissions` on Windows
    
    This fixes the issue #9 where Windows fails to recognize paths that
    contain trailing path separators.


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

3e5635133c9ee42596ac0353f6856cef69dd09ff
 System/Directory.hs        |  3 ++-
 tests/getPermissions001.hs | 14 +++++++++-----
 2 files changed, 11 insertions(+), 6 deletions(-)

diff --git a/System/Directory.hs b/System/Directory.hs
index 7cbaa50..695db9c 100644
--- a/System/Directory.hs
+++ b/System/Directory.hs
@@ -197,7 +197,8 @@ The operation may fail with:
 getPermissions :: FilePath -> IO Permissions
 getPermissions name = do
 #ifdef mingw32_HOST_OS
-  withFilePath name $ \s -> do
+  -- issue #9: Windows doesn't like trailing path separators
+  withFilePath (dropTrailingPathSeparator name) $ \s -> do
   -- stat() does a better job of guessing the permissions on Windows
   -- than access() does.  e.g. for execute permission, it looks at the
   -- filename extension :-)
diff --git a/tests/getPermissions001.hs b/tests/getPermissions001.hs
index 5e9adf2..8290d3f 100644
--- a/tests/getPermissions001.hs
+++ b/tests/getPermissions001.hs
@@ -1,13 +1,17 @@
 import System.Directory
 
 main = do
+#ifndef mingw32_HOST_OS
+  let exe = ".exe"
+#else
+  let exe = ""
+#endif
   p <- getPermissions "."
   print p
   p <- getPermissions "getPermissions001.hs"
   print p
-#ifndef mingw32_HOST_OS
-  p <- getPermissions "getPermissions001"
-#else
-  p <- getPermissions "getPermissions001.exe"
-#endif
+  p <- getPermissions ("getPermissions001" ++ exe)
   print p
+
+  -- issue #9: Windows doesn't like trailing path separators
+  _ <- getPermissions "../tests/"



More information about the ghc-commits mailing list