Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/Database/Postgres/Temp/Internal/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import Data.Maybe
import Data.Monoid
import Data.Monoid.Generic
import Data.List
import qualified Data.List.NonEmpty as NonEmpty
import Data.Traversable
import qualified Database.PostgreSQL.Simple.Options as Client
import GHC.Generics (Generic)
Expand Down Expand Up @@ -639,12 +640,14 @@ getInitDbVersion :: String
getInitDbVersion = unsafePerformIO $ readProcessWithExitCode "initdb" ["--version"] "" >>= \case
(ExitSuccess, outputString, _) -> do
let
theLastPart = last $ words outputString
versionPart = takeWhile (\x -> isDigit x || x == '.' || x == '-') theLastPart
humanReadable = if last versionPart == '.'
then init versionPart
else versionPart
pure $ humanReadable <> take 8 (makeArgumentHash outputString)
getVersionPart s =
fmap (\s' -> (if NonEmpty.last s' == '.' then NonEmpty.init else NonEmpty.toList) s')
. NonEmpty.nonEmpty
. takeWhile (\x -> isDigit x || x == '.' || x == '-')
version =
fromMaybe (error $ "Could not find version in `initdb --version` output:\n" <> outputString) $
find getVersionPart $ reverse $ words outputString
pure $ version <> take 8 (makeArgumentHash outputString)

(startErrorExitCode, startErrorStdOut, startErrorStdErr) ->
throwIO InitDbFailed {..}
Expand Down