packages feed

rpm-nvr 0.1.0 → 0.1.1

raw patch · 9 files changed

+72/−27 lines, 9 filesdep +filepathPVP ok

version bump matches the API change (PVP)

Dependencies added: filepath

API changes (from Hackage documentation)

+ Data.RPM.NVR: [nvrName] :: NVR -> String
+ Data.RPM.NVR: [nvrVerRel] :: NVR -> VerRel
+ Data.RPM.NVR: [vrRelease] :: VerRel -> String
+ Data.RPM.NVR: [vrVersion] :: VerRel -> String
+ Data.RPM.VerRel: [vrRelease] :: VerRel -> String
+ Data.RPM.VerRel: [vrVersion] :: VerRel -> String

Files

ChangeLog.md view
@@ -1,4 +1,9 @@ # Revision history for rpm-nvr +## 0.1.1 (2021-11-02)+- fix a critical bug in rpmVerCompare numeric comparison+- reading NVRA now removes any directory prefix+- NVR and VerRel are now records+ ## 0.1.0 (2021-06-06) - initial release with NV, NVR, NVRA, VerRel and rpmVerCompare
README.md view
@@ -7,5 +7,7 @@  See the haddock documentation for more details. +rpm-nvr is distributed under the GPLv2+ license.+ The testsuite includes testcases for comparing rpm versions from the main rpm project.
rpm-nvr.cabal view
@@ -1,6 +1,6 @@ name:                rpm-nvr-version:             0.1.0-synopsis:            RPM package name-version-release datatypes+version:             0.1.1+synopsis:            RPM package name-version-release data types description:             The library provides types related to RPM package             name-version-releases. There are modules for reading and showing:@@ -29,7 +29,7 @@                      ChangeLog.md cabal-version:       1.18 tested-with:         GHC == 8.0.2, GHC == 8.2.2, GHC == 8.4.4, GHC == 8.6.5,-                     GHC == 8.8.4, GHC == 8.10.4, GHC == 9.0.1+                     GHC == 8.8.4, GHC == 8.10.7, GHC == 9.0.1  source-repository head   type:                git@@ -37,7 +37,9 @@  library   build-depends:       base < 5,-                       extra >= 1.5.1+                       extra >= 1.5.1,+                       filepath+   default-language:    Haskell2010   exposed-modules:     Data.RPM                        Data.RPM.NV@@ -61,6 +63,8 @@                        -Wpartial-fields   if impl(ghc >= 8.10)     ghc-options:       -Wunused-packages+  if impl(ghc < 7.6)+     buildable: False  test-suite tests     type:               exitcode-stdio-1.0@@ -70,6 +74,7 @@                         RPM.VersionSpec     build-depends:      hspec,                         base < 5.0,+                        filepath,                         rpm-nvr      default-language:   Haskell2010
src/Data/RPM/NVR.hs view
@@ -20,7 +20,8 @@ import Data.RPM.VerRel  -- | An rpm package name-version-release-data NVR = NVR String VerRel+data NVR = NVR {nvrName :: String,+                nvrVerRel :: VerRel}   deriving Eq  -- | render an name-version-release
src/Data/RPM/NVRA.hs view
@@ -19,12 +19,15 @@  import Data.Either.Extra import Data.List.Extra-import Data.Maybe+#if !MIN_VERSION_extra(1,6,4)+import Data.Maybe (fromMaybe)+#endif #if !MIN_VERSION_base(4,11,0) import Data.Monoid ((<>)) #endif import Data.RPM.NVR import Data.RPM.VerRel+import System.FilePath (takeFileName)  -- | RPM package with name, version-release, and architecture --@@ -41,11 +44,13 @@ showNVRA (NVRA n vr a) = n <> "-" <> showVerRel vr <> "." <> a  -- | Either read a name-version-release.arch or return a failure string+--+-- Strips off ".rpm" extension and any directory path prefix. eitherNVRA :: String -> Either String NVRA eitherNVRA "" = Left "NVRA string cannot be empty" eitherNVRA s@('-':_) = Left $ "NVRA cannot start with '-': " ++ s eitherNVRA s =-  let nvra = fromMaybe s $ stripSuffix ".rpm" s+  let nvra = dropSuffix ".rpm" $ takeFileName s   in     case reverse (splitOn "-" nvra) of       ps@(relarch:ver:emaN) ->@@ -76,3 +81,8 @@ -- | Identifier for an RPM package identified by name and arch showPkgIdent :: NVRA -> String showPkgIdent p = rpmName p <> "." <> rpmArch p++#if !MIN_VERSION_extra(1,6,4)+dropSuffix :: Eq a => [a] -> [a] -> [a]+dropSuffix a b = fromMaybe b $ stripSuffix a b+#endif
src/Data/RPM/VerCmp.hs view
@@ -25,18 +25,17 @@ rpmVerCompare :: String -> String -> Ordering rpmVerCompare a b =   if a == b then EQ-    else let+  else     -- strip out all non-version characters     -- keep in mind the strings may be empty after this-    a' = dropSeparators a-    b' = dropSeparators b--    -- rpm compares strings by digit and non-digit components, so grab the first-    -- component of one type-    fn = if isDigit (head a') then isDigit else isAsciiAlpha-    (prefixA, suffixA) = span fn a'-    (prefixB, suffixB) = span fn b'- in+    let a' = dropSeparators a+        b' = dropSeparators b+        -- rpm compares strings by digit and non-digit components,+        -- so grab the first component of one type+        fn = if isDigit (head a') then isDigit else isAsciiAlpha+        (prefixA, suffixA) = span fn a'+        (prefixB, suffixB) = span fn b'+    in     if | a' == b'                                       -> EQ        -- Nothing left means the versions are equal        {- null a' && null b'                             -> EQ -}@@ -53,9 +52,10 @@        -- otherwise, if one of the strings is null, the other is greater        | (null a')                                        -> LT        | (null b')                                        -> GT-       -- Now we have two non-null strings, starting with a non-tilde version character-       -- If one prefix is a number and the other is a string, the one that is a number-       -- is greater.+       -- Now we have two non-null strings starting with+       -- a non-tilde version character.+       -- If one prefix is a number and the other is a string,+       -- the one that is a number is greater.        | isDigit (head a') && (not . isDigit) (head b') -> GT        | (not . isDigit) (head a') && isDigit (head b') -> LT        | isDigit (head a')                                -> (prefixA `compareAsInts` prefixB) <> (suffixA `rpmVerCompare` suffixB)@@ -65,11 +65,17 @@     -- the version numbers can overflow Int, so strip leading 0's and do a string compare,     -- longest string wins     compareAsInts x y =-        let x' = dropWhile (== '0') x-            y' = dropWhile (== '0') y-        in-            if length x' > length y' then GT-            else x' `compare` y'+      if | x == y -> EQ+         | null x -> LT+         | null y -> GT+         | otherwise ->+           let x' = dropWhile (== '0') x+               y' = dropWhile (== '0') y+           in+             case compare (length x') (length y') of+               EQ ->+                 (read x' :: Int) `compare` read y'+               o -> o      -- isAlpha returns any unicode alpha, but we just want ASCII characters     isAsciiAlpha :: Char -> Bool
src/Data/RPM/VerRel.hs view
@@ -22,7 +22,8 @@ -- @rpmVerCompare@ for version and release. -- -- FIXME: note currently rpmVerCompare is not used for Eq (like codec-rpm).-data VerRel = VerRel String String+data VerRel = VerRel {vrVersion :: String,+                      vrRelease :: String}   deriving (Eq)  -- | Display a VerRel
test/RPM/PackageSpec.hs view
@@ -6,6 +6,8 @@ import           Data.RPM.NVR import           Data.RPM.NVRA +import System.FilePath (dropExtension, takeFileName)+ -- FIXME add some failures too pkgspec :: Spec pkgspec = do@@ -23,3 +25,13 @@     forM_ ["my-pkg-1.0.1-1.2.x86_64"] $ \pkg ->       it pkg $       showNVRA (readNVRA pkg) `shouldBe` pkg++  describe "NVRA.rpm" $ do+    forM_ ["my-pkg-1.0.1-1.2.x86_64.rpm"] $ \pkg ->+      it pkg $+      showNVRA (readNVRA pkg) `shouldBe` dropExtension pkg++  describe "dir/NVRA.rpm" $ do+    forM_ ["dir/my-pkg-1.0.1-1.2.x86_64.rpm"] $ \pkg ->+      it pkg $+      showNVRA (readNVRA pkg) `shouldBe` dropExtension (takeFileName pkg)
test/RPM/VersionSpec.hs view
@@ -128,7 +128,10 @@                          ("1.0~rc1", "1.0~rc1^git1", LT),                          ("1.0^git1~pre", "1.0^git1~pre", EQ),                          ("1.0^git1", "1.0^git1~pre", GT),-                         ("1.0^git1~pre", "1.0^git1", LT)+                         ("1.0^git1~pre", "1.0^git1", LT),++                         -- local+                         ("8", "13", LT)                          ]          forM_ vercmpCases $ \(verA, verB, ord) ->