@@ -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
@@ -103,7 +105,42 @@ import qualified Data.Yaml.Aeson as Y
103
105
104
106
105
107
108
+ officialPrefixes :: [String ]
109
+ officialPrefixes =
110
+ [ " https://raw.githubusercontent.com/haskell/ghcup-metadata/"
111
+ , " https://mirror.sjtu.edu.cn/ghcup/yaml/haskell/ghcup-metadata/"
112
+ ]
113
+
106
114
-- | Downloads the download information! But only if we need to ;P
115
+ isDefaultURL :: NewURLSource -> Bool
116
+ isDefaultURL NewGHCupURL = True
117
+ isDefaultURL NewStackSetupURL = True
118
+ isDefaultURL (NewChannelAlias StackChannel ) = True
119
+ isDefaultURL (NewChannelAlias _) = True
120
+ isDefaultURL (NewGHCupInfo _) = False -- Custom GHCupInfo is not a default source
121
+ isDefaultURL (NewSetupInfo _) = False -- Custom SetupInfo is not a default source
122
+ isDefaultURL (NewURI uri) = show uri `elem` defaultURLs
123
+
124
+ -- List of default/known URLs
125
+ defaultURLs :: [String ]
126
+ defaultURLs =
127
+ [ " https://raw.githubusercontent.com/haskell/ghcup-metadata/master/ghcup-0.0.9.yaml"
128
+ , " https://raw.githubusercontent.com/commercialhaskell/stackage-content/master/stack/stack-setup-2.yaml"
129
+ , " https://raw.githubusercontent.com/haskell/ghcup-metadata/master/ghcup-cross-0.0.9.yaml"
130
+ , " https://raw.githubusercontent.com/haskell/ghcup-metadata/master/ghcup-prereleases-0.0.9.yaml"
131
+ , " https://raw.githubusercontent.com/haskell/ghcup-metadata/master/ghcup-vanilla-0.0.9.yaml"
132
+ ]
133
+
134
+ -- Extract URL string from NewURLSource if possible, for checking
135
+ getUrlStringFromSource :: NewURLSource -> Maybe String
136
+ getUrlStringFromSource NewGHCupURL = Just $ show ghcupURL
137
+ getUrlStringFromSource NewStackSetupURL = Just $ show stackSetupURL
138
+ getUrlStringFromSource (NewChannelAlias c) = Just $ show $ channelURL c
139
+ getUrlStringFromSource (NewGHCupInfo _) = Nothing
140
+ getUrlStringFromSource (NewSetupInfo _) = Nothing
141
+ getUrlStringFromSource (NewURI uri) = Just $ show uri
142
+
143
+ -- Modified getDownloadsF to include URL prefix check
107
144
getDownloadsF :: ( FromJSONKey Tool
108
145
, FromJSONKey Version
109
146
, FromJSON VersionInfo
@@ -124,6 +161,22 @@ getDownloadsF :: ( FromJSONKey Tool
124
161
GHCupInfo
125
162
getDownloadsF pfreq@ (PlatformRequest arch plat _) = do
126
163
Settings { urlSource } <- lift getSettings
164
+
165
+ -- Check for custom URL sources that aren't in the default list
166
+ forM_ urlSource $ \ src ->
167
+ case src of
168
+ NewURI uri -> do
169
+ let url = show uri
170
+ when (not (url `elem` defaultURLs) &&
171
+ not (any (`isPrefixOf` url) officialPrefixes) ||
172
+ url == " https://ghc.gitlab.haskell.org/ghcup-metadata/ghcup-nightlies-0.0.7.yaml" ) $
173
+ logWarn $ " The URL " <> T. pack url <> " is not an official GHCup metadata source and may not be maintained or QA'd by GHCup."
174
+ NewGHCupInfo _ ->
175
+ logWarn " Using custom GHCupInfo which is not an official GHCup metadata source"
176
+ NewSetupInfo _ ->
177
+ logWarn " Using custom SetupInfo which is not an official GHCup metadata source"
178
+ _ -> pure ()
179
+
127
180
infos <- liftE $ mapM dl' urlSource
128
181
keys <- if any isRight infos
129
182
then liftE . reThrowAll @ _ @ _ @ '[StackPlatformDetectError ] StackPlatformDetectError $ getStackPlatformKey pfreq
@@ -133,7 +186,17 @@ getDownloadsF pfreq@(PlatformRequest arch plat _) = do
133
186
Right si -> pure $ fromStackSetupInfo si keys
134
187
mergeGhcupInfo ghcupInfos
135
188
where
136
-
189
+ -- Default URLs that are known to be official
190
+ defaultURLs :: [String ]
191
+ defaultURLs =
192
+ [ " https://raw.githubusercontent.com/haskell/ghcup-metadata/master/ghcup-0.0.9.yaml"
193
+ , " https://raw.githubusercontent.com/commercialhaskell/stackage-content/master/stack/stack-setup-2.yaml"
194
+ , " https://raw.githubusercontent.com/haskell/ghcup-metadata/master/ghcup-cross-0.0.9.yaml"
195
+ , " https://raw.githubusercontent.com/haskell/ghcup-metadata/master/ghcup-prereleases-0.0.9.yaml"
196
+ , " https://raw.githubusercontent.com/haskell/ghcup-metadata/master/ghcup-vanilla-0.0.9.yaml"
197
+ , " https://ghc.gitlab.haskell.org/ghcup-metadata/ghcup-nightlies-0.0.7.yaml" -- Nightly channel mentioned in config example
198
+ ]
199
+
137
200
dl' :: ( FromJSONKey Tool
138
201
, FromJSONKey Version
139
202
, FromJSON VersionInfo
@@ -164,6 +227,7 @@ getDownloadsF pfreq@(PlatformRequest arch plat _) = do
164
227
Right <$> decodeMetadata @ Stack. SetupInfo base)
165
228
$ fmap Left (decodeMetadata @ GHCupInfo base >>= \ gI -> warnOnMetadataUpdate uri gI >> pure gI)
166
229
230
+
167
231
fromStackSetupInfo :: MonadThrow m
168
232
=> Stack. SetupInfo
169
233
-> [String ]
@@ -890,4 +954,4 @@ applyMirrors (DM ms) uri@(URI { uriAuthority = Just (Authority { authorityHost =
890
954
}
891
955
Just (DownloadMirror auth Nothing ) ->
892
956
uri { uriAuthority = Just auth }
893
- applyMirrors _ uri = uri
957
+ applyMirrors _ uri = uri
0 commit comments