summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--compiler/main/SysTools.hs13
1 files changed, 11 insertions, 2 deletions
diff --git a/compiler/main/SysTools.hs b/compiler/main/SysTools.hs
index 57d77a3a13..b48bbf4202 100644
--- a/compiler/main/SysTools.hs
+++ b/compiler/main/SysTools.hs
@@ -1340,9 +1340,18 @@ getFinalPath name = do
(fILE_ATTRIBUTE_NORMAL .|. fILE_FLAG_BACKUP_SEMANTICS)
Nothing
let fnPtr = makeGetFinalPathNameByHandle $ castPtrToFunPtr addr
- path <- Win32.try "GetFinalPathName"
+ -- First try to resolve the path to get the actual path
+ -- of any symlinks or other file system redirections that
+ -- may be in place. However this function can fail, and in
+ -- the event it does fail, we need to try using the
+ -- original path and see if we can decompose that.
+ -- If the call fails Win32.try will raise an exception
+ -- that needs to be caught. See #14159
+ path <- (Win32.try "GetFinalPathName"
(\buf len -> fnPtr handle buf len 0) 512
- `finally` closeHandle handle
+ `finally` closeHandle handle)
+ `catch`
+ (\(_ :: IOException) -> return name)
return $ Just path
type GetFinalPath = HANDLE -> LPTSTR -> DWORD -> DWORD -> IO DWORD