use openTempFile from file-io

And follow-on changes.

Note that relatedTemplate was changed to operate on a RawFilePath, and
so when it counts the length, it is now the number of bytes, not the
number of code points. This will just make it truncate shorter strings
in some cases, the truncation is still unicode aware.

When not building with the OsPath flag, toOsPath . fromRawFilePath and
fromRawFilePath . fromOsPath do extra conversions back and forth between
String and ByteString. That overhead could be avoided, but that's the
non-optimised build mode, so didn't bother.

Sponsored-by: unqueued
This commit is contained in:
Joey Hess 2025-01-21 17:00:37 -04:00
parent 1faa3af9cd
commit 793ddecd4b
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
46 changed files with 235 additions and 178 deletions

View file

@ -28,6 +28,7 @@ import Common
import Utility.UserInfo
import Utility.Tmp
import Utility.FileMode
import qualified Utility.FileIO as F
import Data.Char
import Data.Ord
@ -140,12 +141,12 @@ changeUserSshConfig modifier = do
-- If it's a symlink, replace the file it
-- points to.
f <- catchDefaultIO configfile (canonicalizePath configfile)
viaTmp writeSshConfig f c'
viaTmp writeSshConfig (toOsPath (toRawFilePath f)) c'
writeSshConfig :: FilePath -> String -> IO ()
writeSshConfig :: OsPath -> String -> IO ()
writeSshConfig f s = do
writeFile f s
setSshConfigMode (toRawFilePath f)
F.writeFile' f (encodeBS s)
setSshConfigMode (fromOsPath f)
{- Ensure that the ssh config file lacks any group or other write bits,
- since ssh is paranoid about not working if other users can write