From fae5cdc103edafb55ef86699dd9571f35b8cf8ed Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niklas=20Hamb=C3=BCchen?= <mail@nh2.me>
Date: Wed, 8 Feb 2017 03:09:00 +0100
Subject: [PATCH] Fix error message of `createSymbolicLink`.

Consider `ln` (or any other Unix tool):

    $ ln -s file1 file2
    $ ls -l file2
    lrwxrwxrwx 1 niklas niklas 5 Feb  8 03:09 file2 -> file1
    $ ln -s file1 file2
    ln: failed to create symbolic link 'file2': File exists

The file name mentioned in the error ("link2") is the one
that *could not be created*, not the content of the pointer.

`createSymbolicLink` got this wrong so far, it would print

    file1: createSymbolicLink: already exists (File exists)

which is wrong, this file doesn't already exist.

This commit fixes it.
---
 System/Posix/Files.hsc            | 2 +-
 System/Posix/Files/ByteString.hsc | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/System/Posix/Files.hsc b/System/Posix/Files.hsc
index bbda084..749f5da 100644
--- a/System/Posix/Files.hsc
+++ b/System/Posix/Files.hsc
@@ -253,7 +253,7 @@ createSymbolicLink :: FilePath -> FilePath -> IO ()
 createSymbolicLink file1 file2 =
   withFilePath file1 $ \s1 ->
   withFilePath file2 $ \s2 ->
-  throwErrnoPathIfMinus1_ "createSymbolicLink" file1 (c_symlink s1 s2)
+  throwErrnoPathIfMinus1_ "createSymbolicLink" file2 (c_symlink s1 s2)
 
 foreign import ccall unsafe "symlink"
   c_symlink :: CString -> CString -> IO CInt
diff --git a/System/Posix/Files/ByteString.hsc b/System/Posix/Files/ByteString.hsc
index 872817e..23a44e3 100644
--- a/System/Posix/Files/ByteString.hsc
+++ b/System/Posix/Files/ByteString.hsc
@@ -259,7 +259,7 @@ createSymbolicLink :: RawFilePath -> RawFilePath -> IO ()
 createSymbolicLink file1 file2 =
   withFilePath file1 $ \s1 ->
   withFilePath file2 $ \s2 ->
-  throwErrnoPathIfMinus1_ "createSymbolicLink" file1 (c_symlink s1 s2)
+  throwErrnoPathIfMinus1_ "createSymbolicLink" file2 (c_symlink s1 s2)
 
 foreign import ccall unsafe "symlink"
   c_symlink :: CString -> CString -> IO CInt
-- 
GitLab