Skip to content

Commit 5662ff4

Browse files
authored
Merge pull request #1225 from RaoulHC/avoid-repeated-tarball-mirroring
Filter out metadata revisions in index before mirroring
2 parents 30a4d84 + b48fa5f commit 5662ff4

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

exes/MirrorClient.hs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ module Main (main) where
44
import Control.Exception
55
import Control.Monad
66
import Control.Monad.Trans
7+
import Data.Function (on)
78
import Data.List
9+
import qualified Data.List.NonEmpty as NonEmpty
810
import Data.Version
911
import Network.Browser
1012
import System.Directory
@@ -118,10 +120,14 @@ mirrorOnce verbosity opts
118120
| null (selectedPkgs opts) = pkgsMissingFromDest
119121
| otherwise = subsetIndex (selectedPkgs opts)
120122
pkgsMissingFromDest
121-
pkgsToMirror' = filter (\(PkgIndexInfo pkg _ _ _) ->
122-
pkg `Set.notMember` missingPkgs
123-
&& pkg `Set.notMember` unmirrorablePkgs )
124-
pkgsToMirror
123+
byPkgId cmp = on cmp (\(PkgIndexInfo pkg _ _ _) -> pkg)
124+
pkgsToMirror'
125+
-- Remove any duplicates in the index from metadata revisions
126+
= map NonEmpty.head . NonEmpty.groupBy (byPkgId (==)) . sortBy (byPkgId compare)
127+
$ filter (\(PkgIndexInfo pkg _ _ _) ->
128+
pkg `Set.notMember` missingPkgs
129+
&& pkg `Set.notMember` unmirrorablePkgs)
130+
pkgsToMirror
125131
mirrorCount = length pkgsToMirror'
126132
ignoreCount = length pkgsToMirror - mirrorCount
127133

0 commit comments

Comments
 (0)