Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions System/Posix/Directory.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ module System.Posix.Directory (
) where

import Data.Maybe
import System.IO.Error
import System.Posix.Error
import System.Posix.Types
import Foreign
Expand Down Expand Up @@ -157,18 +156,16 @@ foreign import ccall unsafe "getcwd"
-- the current working directory to @dir@.
changeWorkingDirectory :: FilePath -> IO ()
changeWorkingDirectory path =
modifyIOError (`ioeSetFileName` path) $
withFilePath path $ \s ->
throwErrnoIfMinus1Retry_ "changeWorkingDirectory" (c_chdir s)
withFilePath path $ \s ->
throwErrnoPathIfMinus1Retry_ "changeWorkingDirectory" path (c_chdir s)

foreign import ccall unsafe "chdir"
c_chdir :: CString -> IO CInt

removeDirectory :: FilePath -> IO ()
removeDirectory path =
modifyIOError (`ioeSetFileName` path) $
withFilePath path $ \s ->
throwErrnoIfMinus1Retry_ "removeDirectory" (c_rmdir s)
withFilePath path $ \s ->
throwErrnoPathIfMinus1Retry_ "removeDirectory" path (c_rmdir s)

foreign import ccall unsafe "rmdir"
c_rmdir :: CString -> IO CInt
11 changes: 4 additions & 7 deletions System/Posix/Directory/ByteString.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ module System.Posix.Directory.ByteString (
) where

import Data.Maybe
import System.IO.Error
import System.Posix.Types
import Foreign
import Foreign.C
Expand Down Expand Up @@ -158,18 +157,16 @@ foreign import ccall unsafe "getcwd"
-- the current working directory to @dir@.
changeWorkingDirectory :: RawFilePath -> IO ()
changeWorkingDirectory path =
modifyIOError (`ioeSetFileName` (BC.unpack path)) $
withFilePath path $ \s ->
throwErrnoIfMinus1Retry_ "changeWorkingDirectory" (c_chdir s)
withFilePath path $ \s ->
throwErrnoPathIfMinus1Retry_ "changeWorkingDirectory" path (c_chdir s)

foreign import ccall unsafe "chdir"
c_chdir :: CString -> IO CInt

removeDirectory :: RawFilePath -> IO ()
removeDirectory path =
modifyIOError (`ioeSetFileName` BC.unpack path) $
withFilePath path $ \s ->
throwErrnoIfMinus1Retry_ "removeDirectory" (c_rmdir s)
withFilePath path $ \s ->
throwErrnoPathIfMinus1Retry_ "removeDirectory" path (c_rmdir s)

foreign import ccall unsafe "rmdir"
c_rmdir :: CString -> IO CInt
18 changes: 4 additions & 14 deletions System/Posix/Directory/PosixPath.hsc
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,11 @@ module System.Posix.Directory.PosixPath (
changeWorkingDirectoryFd,
) where

import System.IO.Error
import System.Posix.Types
import Foreign
import Foreign.C

import System.OsPath.Types
import GHC.IO.Encoding.UTF8 ( mkUTF8 )
import GHC.IO.Encoding.Failure ( CodingFailureMode(..) )
import System.OsPath.Posix
import System.Posix.Directory hiding (createDirectory, openDirStream, readDirStream, getWorkingDirectory, changeWorkingDirectory, removeDirectory)
import qualified System.Posix.Directory.Common as Common
import System.Posix.PosixPath.FilePath
Expand Down Expand Up @@ -145,22 +141,16 @@ foreign import ccall unsafe "getcwd"
-- the current working directory to @dir@.
changeWorkingDirectory :: PosixPath -> IO ()
changeWorkingDirectory path =
modifyIOError (`ioeSetFileName` (_toStr path)) $
withFilePath path $ \s ->
throwErrnoIfMinus1Retry_ "changeWorkingDirectory" (c_chdir s)
withFilePath path $ \s ->
throwErrnoPathIfMinus1Retry_ "changeWorkingDirectory" path (c_chdir s)

foreign import ccall unsafe "chdir"
c_chdir :: CString -> IO CInt

removeDirectory :: PosixPath -> IO ()
removeDirectory path =
modifyIOError (`ioeSetFileName` _toStr path) $
withFilePath path $ \s ->
throwErrnoIfMinus1Retry_ "removeDirectory" (c_rmdir s)
withFilePath path $ \s ->
throwErrnoPathIfMinus1Retry_ "removeDirectory" path (c_rmdir s)

foreign import ccall unsafe "rmdir"
c_rmdir :: CString -> IO CInt

_toStr :: PosixPath -> String
_toStr fp = either (error . show) id $ decodeWith (mkUTF8 TransliterateCodingFailure) fp