{-# LINE 1 "libraries\\Win32\\System\\Win32\\WindowsString\\SymbolicLink.hsc" #-}
{-# LANGUAGE CPP #-}
module System.Win32.WindowsString.SymbolicLink
( SymbolicLinkFlags
, sYMBOLIC_LINK_FLAG_FILE
, sYMBOLIC_LINK_FLAG_DIRECTORY
, sYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE
, createSymbolicLink
, createSymbolicLink'
, createSymbolicLinkFile
, createSymbolicLinkDirectory
) where
import System.Win32.SymbolicLink.Internal
import Data.Bits ((.|.))
import System.Win32.WindowsString.Types
import System.Win32.WindowsString.File ( failIfFalseWithRetry_ )
import System.OsPath.Windows
import Unsafe.Coerce (unsafeCoerce)
#include "windows_cconv.h"
createSymbolicLink :: WindowsPath
-> WindowsPath
-> SymbolicLinkFlags -> IO ()
createSymbolicLink = flip createSymbolicLink'
createSymbolicLinkFile :: WindowsPath
-> WindowsPath
-> Bool
-> IO ()
createSymbolicLinkFile target link unprivileged =
createSymbolicLink'
link
target
( if unprivileged
then sYMBOLIC_LINK_FLAG_FILE .|. sYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE
else sYMBOLIC_LINK_FLAG_FILE
)
createSymbolicLinkDirectory :: WindowsPath
-> WindowsPath
-> Bool
-> IO ()
createSymbolicLinkDirectory target link unprivileged =
createSymbolicLink'
link
target
( if unprivileged
then
sYMBOLIC_LINK_FLAG_DIRECTORY
.|. sYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE
else sYMBOLIC_LINK_FLAG_DIRECTORY
)
createSymbolicLink' :: WindowsPath
-> WindowsPath
-> SymbolicLinkFlags -> IO ()
createSymbolicLink' link target flag = do
withTString link $ \c_link ->
withTString target $ \c_target ->
failIfFalseWithRetry_ (unwords ["CreateSymbolicLink",show link,show target]) $
c_CreateSymbolicLink c_link c_target (unsafeCoerce flag)