File: Files.hs

package info (click to toggle)
haskell-unixutils 1.52-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 112 kB
  • sloc: haskell: 494; makefile: 2
file content (16 lines) | stat: -rw-r--r-- 611 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
module System.Unix.Files where

import Control.Exception (catch)
import Prelude hiding (catch)
import System.Posix.Files (createSymbolicLink, removeLink)
import System.IO.Error (isAlreadyExistsError)

-- |calls 'createSymbolicLink' but will remove the target and retry if
-- 'createSymbolicLink' raises EEXIST.
forceSymbolicLink :: FilePath -> FilePath -> IO ()
forceSymbolicLink target linkName =
    createSymbolicLink target linkName `catch`
      (\e -> if isAlreadyExistsError e 
             then do removeLink linkName
                     createSymbolicLink target linkName
             else ioError e)