Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Use "makepkg -g" to compute md5sums and drop dependency on PureMD5.

  • Loading branch information...
commit 0a16e7814c7107fc077b03b19d2204023d53fb22 1 parent 096c17d
Rémy Oudompheng authored magthe committed
Showing with 19 additions and 20 deletions.
  1. +19 −19 Main.hs
  2. +0 −1  cabal2arch.cabal
View
38 Main.hs
@@ -36,9 +36,6 @@ import Distribution.Simple.PackageIndex
-- from the archlinux package:
import Distribution.ArchLinux.PkgBuild
-import Data.Digest.Pure.MD5
-import qualified Data.ByteString.Lazy as B
-
import Control.Monad
import Control.Concurrent
import qualified Control.OldException as C
@@ -170,26 +167,29 @@ main =
------------------------------------------------------------------------
--- | Given an abstract pkgbuild, download the source bundle,
--- and compute its md5, returning a modified PkgBuild with
--- the md5 set.
---
--- TODO we may want to use a local package.
+-- | Given an abstract pkgbuild, run "makepkg -g" to compute md5
+-- of source files (possibly cached locally), and modify the PkgBuild
+-- accordingly.
--
getMD5 :: PkgBuild -> IO PkgBuild
-getMD5 pkg@(PkgBuild { arch_source = ArchList [url] }) = do
- hPutStrLn stderr $ "Fetching " ++ url
- hFlush stderr
- eres <- myReadProcess "wget" [url] []
+getMD5 pkg = do
+ putStrLn "Feeding the PKGBUILD to `makepkg -g`..."
+ eres <- readProcessWithExitCode "makepkg" ["-g"] (render $ disp pkg)
case eres of
- Left (_,s,_) -> do
- hPutStrLn stderr s
- hPutStrLn stderr $ "Couldn't download package: " ++ show url
+ (ExitFailure _,_,err) -> do
+ hPutStrLn stderr err
+ hPutStrLn stderr $ "makepkg encountered an error while calculating MD5."
return pkg
- Right _ -> do
- src <- B.readFile (takeBaseName url <.> "gz")
- let !md5sum = show (md5 src)
- return pkg { arch_md5sum = ArchList [md5sum] }
+ (ExitSuccess,out,err) -> do
+ -- s should be "md5sums=(' ... ')"
+ hPutStrLn stderr err
+ if "md5sums=('" `isPrefixOf` out
+ then
+ let md5sum = takeWhile (\x -> x `elem` "0123456789abcdef") $ drop 10 out
+ in return pkg { arch_md5sum = ArchList [md5sum] }
+ else do
+ hPutStrLn stderr $ "Incorrect output from makepkg."
+ return pkg
getMD5 _ = die "Malformed PkgBuild"
-- attempt to filter out core packages we've already satisified
View
1  cabal2arch.cabal
@@ -23,7 +23,6 @@ executable cabal2arch
containers,
bytestring,
Cabal > 1.8,
- pureMD5 >= 0.2.1,
filepath,
archlinux >= 0.3.3
Please sign in to comment.
Something went wrong with that request. Please try again.