5

How to create a symlink with Haskell? The directory package to my knowledge does not provide a way to do it.

Mark Karpov
  • 7,499
  • 2
  • 27
  • 62
  • 3
    [System.Posix.Files.createSymbolicLink](https://hackage.haskell.org/package/unix-2.7.2.0/docs/System-Posix-Files.html#g:9) – n. m. could be an AI May 11 '16 at 05:20
  • @n.m. Feel free to post as an answer, unless a duplicate question already exists. – Mark Karpov May 11 '16 at 05:23
  • Apparently there's a (near) duplicate [here](http://stackoverflow.com/questions/35369470/what-is-the-command-to-create-a-soft-link-with-haskell-turtle). – n. m. could be an AI May 11 '16 at 05:37
  • @n.m. I think this question will be easier to find via search engines, I think we should keep this one. – Mark Karpov May 11 '16 at 05:43
  • @Mark: Closing as a duplicate won't delete this question. Instead, it will still come up in search engines. (By the way, I knew I answered this question already somewhere :D) – Zeta May 11 '16 at 07:02

2 Answers2

10

Creating a symbolic link is non-portable. For example, the creation symbolic links on Windows is re­strict­ed1. Therefore it does not fit into directory providing "a basic set of operations for ma­nip­u­lat­ing files and directories in a portable way" (emphasis mine). This affects all platform independent packages.

The platform specific package unix provides that functionality in System.Posix.Files with createSymbolicLink though:

import System.Posix.Files (createSymbolicLink)

main :: IO ()
main = createSymbolicLink "/opt/ghc/7.10.3" "/opt/ghc/active"

1: That's also a reason why unix-compat does not implement createSymbolicLink

snak
  • 6,483
  • 3
  • 23
  • 33
Zeta
  • 103,620
  • 13
  • 194
  • 236
0

directory-1.3.1 has

createFileLink :: FilePath -> FilePath -> IO ()

This is supposed to work even on Windows – only on a suitable file system, of course.

leftaroundabout
  • 117,950
  • 5
  • 174
  • 319