{-# LANGUAGE CPP #-}
module Distribution.RPM.PackageTreeDiff
(RPMPkgDiff(..),
Ignore(..),
diffPkgs,
NVRA(..),
readNVRA
) where
#if !MIN_VERSION_base(4,8,0)
import Control.Applicative ((<$>))
#endif
import Data.RPM.VerRel
import Data.RPM.NVRA
import Data.RPM.VerCmp (rpmVerCompare)
data Ignore = IgnoreNone
| IgnoreRelease
| IgnoreVersion
deriving Ignore -> Ignore -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Ignore -> Ignore -> Bool
$c/= :: Ignore -> Ignore -> Bool
== :: Ignore -> Ignore -> Bool
$c== :: Ignore -> Ignore -> Bool
Eq
data RPMPkgDiff = PkgUpdate NVRA NVRA
| PkgDowngrade NVRA NVRA
| PkgAdd NVRA
| PkgDel NVRA
| PkgArch NVRA NVRA
deriving RPMPkgDiff -> RPMPkgDiff -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RPMPkgDiff -> RPMPkgDiff -> Bool
$c/= :: RPMPkgDiff -> RPMPkgDiff -> Bool
== :: RPMPkgDiff -> RPMPkgDiff -> Bool
$c== :: RPMPkgDiff -> RPMPkgDiff -> Bool
Eq
diffPkgs :: Ignore -> [NVRA] -> [NVRA] -> [RPMPkgDiff]
diffPkgs :: Ignore -> [NVRA] -> [NVRA] -> [RPMPkgDiff]
diffPkgs Ignore
_ [] [] = []
diffPkgs Ignore
ignore (NVRA
p:[NVRA]
ps) [] = NVRA -> RPMPkgDiff
PkgDel NVRA
p forall a. a -> [a] -> [a]
: Ignore -> [NVRA] -> [NVRA] -> [RPMPkgDiff]
diffPkgs Ignore
ignore [NVRA]
ps []
diffPkgs Ignore
ignore [] (NVRA
p:[NVRA]
ps) = NVRA -> RPMPkgDiff
PkgAdd NVRA
p forall a. a -> [a] -> [a]
: Ignore -> [NVRA] -> [NVRA] -> [RPMPkgDiff]
diffPkgs Ignore
ignore [] [NVRA]
ps
diffPkgs Ignore
ignore (NVRA
p1:[NVRA]
ps1) (NVRA
p2:[NVRA]
ps2) =
case forall a. Ord a => a -> a -> Ordering
compare (NVRA -> String
rpmName NVRA
p1) (NVRA -> String
rpmName NVRA
p2) of
Ordering
LT -> NVRA -> RPMPkgDiff
PkgDel NVRA
p1 forall a. a -> [a] -> [a]
: Ignore -> [NVRA] -> [NVRA] -> [RPMPkgDiff]
diffPkgs Ignore
ignore [NVRA]
ps1 (NVRA
p2forall a. a -> [a] -> [a]
:[NVRA]
ps2)
Ordering
EQ -> case Maybe RPMPkgDiff
diffPkg of
Just RPMPkgDiff
diff -> (RPMPkgDiff
diff forall a. a -> [a] -> [a]
:)
Maybe RPMPkgDiff
Nothing -> forall a. a -> a
id
forall a b. (a -> b) -> a -> b
$ Ignore -> [NVRA] -> [NVRA] -> [RPMPkgDiff]
diffPkgs Ignore
ignore [NVRA]
ps1 [NVRA]
ps2
Ordering
GT -> NVRA -> RPMPkgDiff
PkgAdd NVRA
p2 forall a. a -> [a] -> [a]
: Ignore -> [NVRA] -> [NVRA] -> [RPMPkgDiff]
diffPkgs Ignore
ignore (NVRA
p1forall a. a -> [a] -> [a]
:[NVRA]
ps1) [NVRA]
ps2
where
diffPkg :: Maybe RPMPkgDiff
diffPkg :: Maybe RPMPkgDiff
diffPkg =
if NVRA -> String
rpmArch NVRA
p1 forall a. Eq a => a -> a -> Bool
== NVRA -> String
rpmArch NVRA
p2
then case Ignore -> VerRel -> VerRel -> Ordering
cmpVR Ignore
ignore (NVRA -> VerRel
rpmVerRel NVRA
p1) (NVRA -> VerRel
rpmVerRel NVRA
p2) of
Ordering
LT -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ NVRA -> NVRA -> RPMPkgDiff
PkgUpdate NVRA
p1 NVRA
p2
Ordering
EQ -> forall a. Maybe a
Nothing
Ordering
GT -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ NVRA -> NVRA -> RPMPkgDiff
PkgDowngrade NVRA
p1 NVRA
p2
else forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ NVRA -> NVRA -> RPMPkgDiff
PkgArch NVRA
p1 NVRA
p2
cmpVR :: Ignore -> VerRel -> VerRel -> Ordering
cmpVR :: Ignore -> VerRel -> VerRel -> Ordering
cmpVR Ignore
IgnoreNone VerRel
vr VerRel
vr' = forall a. Ord a => a -> a -> Ordering
compare VerRel
vr VerRel
vr'
cmpVR Ignore
IgnoreRelease (VerRel String
v String
_) (VerRel String
v' String
_) = String -> String -> Ordering
rpmVerCompare String
v String
v'
cmpVR Ignore
IgnoreVersion VerRel
_ VerRel
_ = Ordering
EQ