From 3e5635133c9ee42596ac0353f6856cef69dd09ff Mon Sep 17 00:00:00 2001 From: Phil Ruffwind Date: Mon, 2 Mar 2015 20:21:13 -0500 Subject: [PATCH] Drop trailing path separators in `getPermissions` on Windows This fixes the issue #9 where Windows fails to recognize paths that contain trailing path separators. --- 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 7cbaa501..695db9cc 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 5e9adf2d..8290d3f8 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/"