Skip to content
This repository
Browse code

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

  • Loading branch information...
commit 0a16e7814c7107fc077b03b19d2204023d53fb22 1 parent 096c17d
authored October 14, 2010 magthe committed October 14, 2010

Showing 2 changed files with 19 additions and 20 deletions. Show diff stats Hide diff stats

  1. 38  Main.hs
  2. 1  cabal2arch.cabal
38  Main.hs
@@ -36,9 +36,6 @@ import Distribution.Simple.PackageIndex
36 36
 -- from the archlinux package:
37 37
 import Distribution.ArchLinux.PkgBuild
38 38
 
39  
-import Data.Digest.Pure.MD5
40  
-import qualified Data.ByteString.Lazy as B
41  
-
42 39
 import Control.Monad
43 40
 import Control.Concurrent
44 41
 import qualified Control.OldException as C
@@ -170,26 +167,29 @@ main =
170 167
 
171 168
 ------------------------------------------------------------------------
172 169
 
173  
--- | Given an abstract pkgbuild, download the source bundle,
174  
--- and compute its md5, returning a modified PkgBuild with
175  
--- the md5 set.
176  
---
177  
--- TODO we may want to use a local package.
  170
+-- | Given an abstract pkgbuild, run "makepkg -g" to compute md5
  171
+-- of source files (possibly cached locally), and modify the PkgBuild
  172
+-- accordingly.
178 173
 --
179 174
 getMD5 :: PkgBuild -> IO PkgBuild
180  
-getMD5 pkg@(PkgBuild { arch_source = ArchList [url] }) = do
181  
-   hPutStrLn stderr $ "Fetching " ++ url
182  
-   hFlush stderr
183  
-   eres <- myReadProcess "wget" [url] []
  175
+getMD5 pkg = do
  176
+   putStrLn "Feeding the PKGBUILD to `makepkg -g`..."
  177
+   eres <- readProcessWithExitCode "makepkg" ["-g"] (render $ disp pkg)
184 178
    case eres of
185  
-       Left (_,s,_) -> do
186  
-            hPutStrLn stderr s
187  
-            hPutStrLn stderr $ "Couldn't download package: " ++ show url
  179
+       (ExitFailure _,_,err) -> do
  180
+            hPutStrLn stderr err
  181
+            hPutStrLn stderr $ "makepkg encountered an error while calculating MD5."
188 182
             return pkg
189  
-       Right _ -> do
190  
-            src <- B.readFile (takeBaseName url <.> "gz")
191  
-            let !md5sum = show (md5 src)
192  
-            return pkg { arch_md5sum = ArchList [md5sum] }
  183
+       (ExitSuccess,out,err) -> do
  184
+            -- s should be "md5sums=(' ... ')"
  185
+            hPutStrLn stderr err
  186
+            if "md5sums=('" `isPrefixOf` out
  187
+               then
  188
+                 let md5sum = takeWhile (\x -> x `elem` "0123456789abcdef") $ drop 10 out
  189
+                 in return pkg { arch_md5sum = ArchList [md5sum] }
  190
+               else do
  191
+                 hPutStrLn stderr $ "Incorrect output from makepkg."
  192
+                 return pkg
193 193
 getMD5 _ = die "Malformed PkgBuild"
194 194
 
195 195
 -- attempt to filter out core packages we've already satisified
1  cabal2arch.cabal
@@ -23,7 +23,6 @@ executable cabal2arch
23 23
         containers,
24 24
         bytestring,
25 25
         Cabal   > 1.8,
26  
-        pureMD5 >= 0.2.1,
27 26
         filepath,
28 27
         archlinux >= 0.3.3
29 28
 

0 notes on commit 0a16e78

Please sign in to comment.
Something went wrong with that request. Please try again.