Skip to content

Commit

Permalink
Simplify the internal canonicalizePathWith API
Browse files Browse the repository at this point in the history
  • Loading branch information
Rufflewind committed Jan 23, 2024
1 parent 0f90681 commit 9893189
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
12 changes: 4 additions & 8 deletions System/Directory/Internal/Posix.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,10 @@ withRealpath path action = case c_PATH_MAX of
allocaBytes (pathMax + 1) (realpath >=> action)
where realpath = throwErrnoIfNull "" . c_realpath path

canonicalizePathWith :: ((OsPath -> IO OsPath) -> OsPath -> IO OsPath)
-> OsPath
-> IO OsPath
canonicalizePathWith attemptRealpath path = do
let realpath (OsString path') =
Posix.withFilePath path'
(`withRealpath` ((OsString <$>) . Posix.peekFilePath))
attemptRealpath realpath path
realPath :: OsPath -> IO OsPath
realPath (OsString path') =
Posix.withFilePath path'
(`withRealpath` ((OsString <$>) . Posix.peekFilePath))

canonicalizePathSimplify :: OsPath -> IO OsPath
canonicalizePathSimplify = pure
Expand Down
6 changes: 2 additions & 4 deletions System/Directory/Internal/Windows.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -407,10 +407,8 @@ peekTStringWith bufferSize cFunc = do
Left proposedSize -> peekTStringWith proposedSize cFunc
Right result -> pure result

canonicalizePathWith :: ((OsPath -> IO OsPath) -> OsPath -> IO OsPath)
-> OsPath
-> IO OsPath
canonicalizePathWith attemptRealpath = attemptRealpath getFinalPathName
realPath :: OsPath -> IO OsPath
realPath = getFinalPathName

canonicalizePathSimplify :: OsPath -> IO OsPath
canonicalizePathSimplify path =
Expand Down
2 changes: 1 addition & 1 deletion System/Directory/OsPath.hs
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,7 @@ canonicalizePath = \ path ->
(`ioeSetOsPath` path)) `modifyIOError` do
-- simplify does more stuff, like upper-casing the drive letter
dropTrailingPathSeparator . simplify <$>
(canonicalizePathWith attemptRealpath =<< prependCurrentDirectory path)
(attemptRealpath realPath =<< prependCurrentDirectory path)
where

-- allow up to 64 cycles before giving up
Expand Down

0 comments on commit 9893189

Please sign in to comment.