@@ -89,6 +89,8 @@ import qualified Data.Text as T
89
89
import qualified Data.Text.IO as T
90
90
import qualified Data.Text.Encoding as E
91
91
import qualified Data.Yaml.Aeson as Y
92
+ import Data.List (isPrefixOf )
93
+ import Control.Monad.IO.Class (liftIO )
92
94
93
95
94
96
@@ -102,6 +104,33 @@ import qualified Data.Yaml.Aeson as Y
102
104
------------------
103
105
104
106
107
+ formatURI :: URI -> T. Text
108
+ formatURI uri =
109
+ let scheme = E. decodeUtf8 $ schemeBS $ uriScheme uri
110
+ auth = case uriAuthority uri of
111
+ Just a -> " //" <> E. decodeUtf8 (hostBS $ authorityHost a)
112
+ Nothing -> " "
113
+ path = E. decodeUtf8 $ uriPath uri
114
+ in scheme <> " :" <> auth <> path
115
+
116
+ -- | Logic to check if it is an Official Channel
117
+ isOfficialURI :: URI -> Bool
118
+ isOfficialURI uri = any (`isURIPrefix` uri) officialURIs
119
+ where
120
+ officialURIs = [isGitHubMetadata]
121
+ isGitHubMetadata uri' =
122
+ schemeBS (uriScheme uri') == " https" &&
123
+ maybe False (\ a -> hostBS (authorityHost a) == " raw.githubusercontent.com" ) (uriAuthority uri') &&
124
+ pathStartsWith " /haskell/ghcup-metadata/" (uriPath uri')
125
+ pathStartsWith prefix path = prefix `B.isPrefixOf` path
126
+ isURIPrefix predicate uri' = predicate uri'
127
+
128
+ -- | Special case to check for nightlies URL
129
+ isNightliesURI :: URI -> Bool
130
+ isNightliesURI uri =
131
+ schemeBS (uriScheme uri) == " https" &&
132
+ maybe False (\ a -> hostBS (authorityHost a) == " ghc.gitlab.haskell.org" ) (uriAuthority uri) &&
133
+ uriPath uri == " /ghcup-metadata/ghcup-nightlies-0.0.7.yaml"
105
134
106
135
-- | Downloads the download information! But only if we need to ;P
107
136
getDownloadsF :: ( FromJSONKey Tool
@@ -124,6 +153,17 @@ getDownloadsF :: ( FromJSONKey Tool
124
153
GHCupInfo
125
154
getDownloadsF pfreq@ (PlatformRequest arch plat _) = do
126
155
Settings { urlSource } <- lift getSettings
156
+ forM_ urlSource $ \ src ->
157
+ case src of
158
+ NewURI uri -> do
159
+ when (not (isOfficialURI uri) || isNightliesURI uri) $
160
+ logWarn $ " Warning: Using non-official metadata source: " <> formatURI uri <>
161
+ " \n This source is not maintained or verified by the GHCup team."
162
+ NewGHCupInfo _ ->
163
+ logWarn " Warning: Using custom GHCupInfo data that is not from an official GHCup metadata source"
164
+ NewSetupInfo _ ->
165
+ logWarn " Warning: Using custom SetupInfo data that is not from an official GHCup metadata source"
166
+ _ -> pure ()
127
167
infos <- liftE $ mapM dl' urlSource
128
168
keys <- if any isRight infos
129
169
then liftE . reThrowAll @ _ @ _ @ '[StackPlatformDetectError ] StackPlatformDetectError $ getStackPlatformKey pfreq
@@ -133,7 +173,7 @@ getDownloadsF pfreq@(PlatformRequest arch plat _) = do
133
173
Right si -> pure $ fromStackSetupInfo si keys
134
174
mergeGhcupInfo ghcupInfos
135
175
where
136
-
176
+
137
177
dl' :: ( FromJSONKey Tool
138
178
, FromJSONKey Version
139
179
, FromJSON VersionInfo
@@ -162,7 +202,9 @@ getDownloadsF pfreq@(PlatformRequest arch plat _) = do
162
202
catchE @ JSONError (\ (JSONDecodeError s) -> do
163
203
logDebug $ " Couldn't decode " <> T. pack base <> " as GHCupInfo, trying as SetupInfo: " <> T. pack s
164
204
Right <$> decodeMetadata @ Stack. SetupInfo base)
165
- $ fmap Left (decodeMetadata @ GHCupInfo base >>= \ gI -> warnOnMetadataUpdate uri gI >> pure gI)
205
+ $ fmap Left (decodeMetadata @ GHCupInfo base >>= \ gI ->
206
+ warnOnMetadataUpdate uri gI >> pure gI)
207
+
166
208
167
209
fromStackSetupInfo :: MonadThrow m
168
210
=> Stack. SetupInfo
@@ -890,4 +932,4 @@ applyMirrors (DM ms) uri@(URI { uriAuthority = Just (Authority { authorityHost =
890
932
}
891
933
Just (DownloadMirror auth Nothing ) ->
892
934
uri { uriAuthority = Just auth }
893
- applyMirrors _ uri = uri
935
+ applyMirrors _ uri = uri
0 commit comments