Copy the permissions to the *temporary* file before moving it, no to the
probably non-existing real destination file. Before this fix, "try" silently
wiped this bug under the carpet, leading to silently broken permissions.
bracketOnError openTmp cleanTmp $ \(tmpFPath, hTmp) ->
do allocaBytes bufferSize $ copyContents hFrom hTmp
hClose hTmp
- try (copyPermissions fromFPath toFPath)
+ try (copyPermissions fromFPath tmpFPath)
renameFile tmpFPath toFPath
openTmp = openBinaryTempFile (takeDirectory toFPath) ".copyFile.tmp"
cleanTmp (tmpFPath, hTmp) = do try $ hClose hTmp