From 5688797d03028912208b0eee6b9c2f0290c51caf Mon Sep 17 00:00:00 2001 From: Erchiusx <99174225+Erchiusx@users.noreply.github.com> Date: Wed, 25 Dec 2024 19:16:00 +0800 Subject: [PATCH 1/2] Update ghcupsync.hs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ghcup metadata 在 0.0.7 添加了 vanilla , 并在 0.0.8 添加了 cross compiler , 而在原本的 version parser 中并没有支持。 我修改了 parseVersionFromFileName 以添加支持, 同时考虑到未来可能的更多不同 metadata 版本, 实现了向前兼容(但性能更差的) parser 版本。 --- ghcup/ghcupsync.hs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ghcup/ghcupsync.hs b/ghcup/ghcupsync.hs index a171244..d02ce96 100644 --- a/ghcup/ghcupsync.hs +++ b/ghcup/ghcupsync.hs @@ -72,9 +72,22 @@ parseVersionFromFileName :: FilePath -> Maybe Version parseVersionFromFileName filename = do let basename = takeBaseName filename noPrefix <- stripPrefix "ghcup-prereleases-" basename + <|> stripPrefix "ghcup-cross-" basename + <|> stripPrefix "ghcup-vanilla-" basename <|> stripPrefix "ghcup-" basename listToMaybe $ map fst . filter (\(_, rem) -> null rem) $ readP_to_S parseVersion noPrefix +-- This versoin of parseVersionFromFileName may have more forward compatability +-- but poorer performance +-- parseVersionFromFileName filename = do +-- let basename = takeBaseName filename +-- case find isJust . map tryParse $ tails basename of +-- (Just m) -> m -- if found, it will be a double Just, i.e. (Just (Just Version)) +-- Nothing -> Nothing +-- where +-- tryParse :: String -> Maybe Version +-- tryParse = listToMaybe . map fst . reverse . readP_to_S parseVersion + ------------------------------------------------------------------------ syncByMetadata :: FilePath -> FilePath -> IO () syncByMetadata basedir mdpath = do From e5d7eb1777af009668f550149f345b9ebe7464ba Mon Sep 17 00:00:00 2001 From: Erchiusx <99174225+Erchiusx@users.noreply.github.com> Date: Wed, 25 Dec 2024 19:34:10 +0800 Subject: [PATCH 2/2] fix typo of version Co-authored-by: taoky --- ghcup/ghcupsync.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ghcup/ghcupsync.hs b/ghcup/ghcupsync.hs index d02ce96..aea8d1a 100644 --- a/ghcup/ghcupsync.hs +++ b/ghcup/ghcupsync.hs @@ -77,7 +77,7 @@ parseVersionFromFileName filename = do <|> stripPrefix "ghcup-" basename listToMaybe $ map fst . filter (\(_, rem) -> null rem) $ readP_to_S parseVersion noPrefix --- This versoin of parseVersionFromFileName may have more forward compatability +-- This version of parseVersionFromFileName may have more forward compatability -- but poorer performance -- parseVersionFromFileName filename = do -- let basename = takeBaseName filename