From de1af273e0e40aa4fc244ba9b50b7276f09ce458 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 22 Jan 2025 15:32:21 -0400 Subject: [PATCH] fix reversion In 793ddecd4b72a5e4746b3b426d3bca400737118b, writeSshConfig was made to writeFile a ByteString, which lost the newline conversion on Windows. Added linesFile to fix it. This will also be useful for other writeFile conversions. --- Utility/Misc.hs | 20 +++++++++++++++++++- Utility/SshConfig.hs | 2 +- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Utility/Misc.hs b/Utility/Misc.hs index d30cce2524..50982e6cf8 100644 --- a/Utility/Misc.hs +++ b/Utility/Misc.hs @@ -1,6 +1,6 @@ {- misc utility functions - - - Copyright 2010-2011 Joey Hess + - Copyright 2010-2025 Joey Hess - - License: BSD-2-clause -} @@ -18,6 +18,8 @@ module Utility.Misc ( firstLine', fileLines, fileLines', + linesFile, + linesFile', segment, segmentDelim, massReplace, @@ -113,6 +115,22 @@ fileLines' = map stripCR . S8.lines fileLines' = S8.lines #endif +-- One windows, writeFile does NewlineMode translation, +-- adding CR before LF. When converting to ByteString, use this to emulate that. +linesFile :: L.ByteString -> L.ByteString +#ifndef mingw32_HOST_OS +linesFile = id +#else +linesFile = L8.concat . concatMap (\x -> [x, L8.pack "\r\n"]) . fileLines +#endif + +linesFile' :: S.ByteString -> S.ByteString +#ifndef mingw32_HOST_OS +linesFile' = id +#else +linesFile' = S8.concat . concatMap (\x -> [x, S8.pack "\r\n"]) . fileLines' +#endif + {- Splits a list into segments that are delimited by items matching - a predicate. (The delimiters are not included in the segments.) - Segments may be empty. -} diff --git a/Utility/SshConfig.hs b/Utility/SshConfig.hs index d43347d7f1..8657beef7a 100644 --- a/Utility/SshConfig.hs +++ b/Utility/SshConfig.hs @@ -145,7 +145,7 @@ changeUserSshConfig modifier = do writeSshConfig :: OsPath -> String -> IO () writeSshConfig f s = do - F.writeFile' f (encodeBS s) + F.writeFile' f (linesFile' (encodeBS s)) setSshConfigMode (fromOsPath f) {- Ensure that the ssh config file lacks any group or other write bits,