forked from haskell/directory
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement safer version of canonicalizePath for POSIX
Apply realpath to the largest prefix of the given path that is still accessible (that can be stat successfully) so that canonicalizePath will return reasonable results even for non-existent paths. It should very rarely throw exceptions now. Fixes haskell#23.
- Loading branch information
1 parent
cb72ff5
commit 83c1f54
Showing
7 changed files
with
96 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{-# LANGUAGE CPP #-} | ||
module CanonicalizePath where | ||
#include "util.inl" | ||
import System.Directory | ||
import System.FilePath ((</>), normalise) | ||
|
||
main :: TestEnv -> IO () | ||
main _t = do | ||
dot <- canonicalizePath "." | ||
nul <- canonicalizePath "" | ||
T(expectEq) () dot nul | ||
|
||
writeFile "bar" "" | ||
bar <- canonicalizePath "bar" | ||
T(expectEq) () bar (normalise (dot </> "bar")) | ||
|
||
createDirectory "foo" | ||
foo <- canonicalizePath "foo/" | ||
T(expectEq) () foo (normalise (dot </> "foo/")) | ||
|
||
-- should not fail for non-existent paths | ||
fooNon <- canonicalizePath "foo/non-existent" | ||
T(expectEq) () fooNon (normalise (foo </> "non-existent")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
module Main (main) where | ||
import qualified Util as T | ||
import qualified CanonicalizePath | ||
import qualified FileTime | ||
import qualified T8482 | ||
|
||
main :: IO () | ||
main = T.testMain $ \ _t -> do | ||
T.isolatedRun _t "CanonicalizePath" CanonicalizePath.main | ||
T.isolatedRun _t "FileTime" FileTime.main | ||
T.isolatedRun _t "T8482" T8482.main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.