Skip to content

Commit

Permalink
locli: add a fallback workaround for broken GECOS
Browse files Browse the repository at this point in the history
  • Loading branch information
deepfire committed Mar 31, 2023
1 parent aa89f8d commit 7352cfc
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion bench/locli/src/Cardano/Report.hs
Expand Up @@ -17,6 +17,7 @@ import Data.Text.Lazy qualified as LT
import Data.Time.Clock
import System.FilePath as FS
import System.Posix.User
import System.Environment (lookupEnv)

import Text.EDE hiding (Id)

Expand Down Expand Up @@ -48,11 +49,26 @@ instance ToJSON ReportMeta where

getReport :: Version -> Maybe Revision -> IO ReportMeta
getReport rmTarget mrev = do
rmAuthor <- (getUserEntryForID =<< getRealUserID) <&> Author . T.pack . takeWhile (/= ',') . userGecos
rmAuthor <- getGecosFullUsername
`catch`
\(_ :: SomeException) ->
getFallbackUserId
rmDate <- getCurrentTime
let rmRevision = fromMaybe (Revision 1) mrev
rmLocliVersion = getLocliVersion
pure ReportMeta{..}
where
getGecosFullUsername, getFallbackUserId :: IO Author
getGecosFullUsername =
(getUserEntryForID =<< getRealUserID)
<&> Author . T.pack . takeWhile (/= ',') . userGecos

getFallbackUserId =
(\user host->
Author . T.pack $
fromMaybe "user" user <> "@" <> fromMaybe "localhost" host)
<$> lookupEnv "USER"
<*> lookupEnv "HOSTNAME"

data Workload
= WValue
Expand Down

0 comments on commit 7352cfc

Please sign in to comment.