{-# OPTIONS -Wall #-}
module Shelly.Directory where

import System.IO.Error (modifyIOError, ioeSetLocation, ioeGetLocation)

import qualified System.PosixCompat as Posix

createFileLink :: String -> String -> IO ()
createFileLink :: String -> String -> IO ()
createFileLink String
target String
link =
  (IOError -> String -> IOError
`ioeAddLocation` String
"createFileLink") (IOError -> IOError) -> IO () -> IO ()
forall a. (IOError -> IOError) -> IO a -> IO a
`modifyIOError` do
    String -> String -> IO ()
Posix.createSymbolicLink String
target String
link

getSymbolicLinkTarget :: String -> IO String
getSymbolicLinkTarget :: String -> IO String
getSymbolicLinkTarget String
path =
  (IOError -> String -> IOError
`ioeAddLocation` String
"getSymbolicLinkTarget") (IOError -> IOError) -> IO String -> IO String
forall a. (IOError -> IOError) -> IO a -> IO a
`modifyIOError` do
    String -> IO String
Posix.readSymbolicLink String
path

ioeAddLocation :: IOError -> String -> IOError
ioeAddLocation :: IOError -> String -> IOError
ioeAddLocation IOError
e String
loc = do
  IOError -> String -> IOError
ioeSetLocation IOError
e String
newLoc
  where
    newLoc :: String
newLoc = String
loc String -> String -> String
forall a. [a] -> [a] -> [a]
++ if String -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
Prelude.null String
oldLoc then String
"" else String
":" String -> String -> String
forall a. [a] -> [a] -> [a]
++ String
oldLoc
    oldLoc :: String
oldLoc = IOError -> String
ioeGetLocation IOError
e