Skip to content

Commit

Permalink
Drop trailing path separators in getPermissions on Windows
Browse files Browse the repository at this point in the history
This fixes the issue haskell#9 where Windows fails to recognize paths that
contain trailing path separators.
  • Loading branch information
Rufflewind committed Mar 3, 2015
1 parent abfa69b commit 3e56351
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
3 changes: 2 additions & 1 deletion System/Directory.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 :-)
Expand Down
14 changes: 9 additions & 5 deletions tests/getPermissions001.hs
Original file line number Diff line number Diff line change
@@ -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/"

0 comments on commit 3e56351

Please sign in to comment.