packages feed

codex 0.2.1.2 → 0.2.1.4

raw patch · 4 files changed

+123/−6 lines, 4 filesdep +curldep −download-curldep ~codexdep ~hackage-dbPVP ok

version bump matches the API change (PVP)

Dependencies added: curl

Dependencies removed: download-curl

Dependency ranges changed: codex, hackage-db

API changes (from Hackage documentation)

Files

codex.cabal view
@@ -1,5 +1,5 @@ name:                codex-version:             0.2.1.2+version:             0.2.1.4 synopsis:            A ctags file generator for cabal project dependencies. description:            This tool download and cache the source code of packages in your local hackage,@@ -28,16 +28,18 @@     Codex     Codex.Project     Codex.Internal+  other-modules:+    Network.Curl.DownloadLazy   build-depends:              base                >= 4.6.0.1    && < 5     , bytestring          >= 0.10.0.2   && < 0.11     , Cabal               >= 1.18       && < 1.21     , containers          >= 0.5.0.0    && < 0.6+    , curl                >= 1.3.8      && < 1.4     , directory           >= 1.2.0.1    && < 1.3-    , download-curl       >= 0.1.4      && < 0.2     , either              >= 4.3.0.1    && < 4.4     , filepath            >= 1.3.0.1    && < 1.4-    , hackage-db          >= 1.8        && < 1.11+    , hackage-db          >= 1.8        && < 1.12     , machines            >= 0.2        && < 0.5     , machines-directory  >= 0.0.0.2    && < 0.3     , MissingH            >= 1.2.1.0    && < 1.4@@ -68,7 +70,7 @@     , MissingH     , monad-loops         >= 0.4.2      && < 0.5     , yaml                >= 0.8.8.3    && < 0.9-    , codex               == 0.2.1.2+    , codex               == 0.2.1.4  source-repository head   type:     git
codex/Main.hs view
@@ -106,7 +106,7 @@   cx    <- loadConfig   args  <- getArgs   run cx args where-    run cx ["cache", clean] = cleanCache cx+    run cx ["cache", "clean"] = cleanCache cx     run cx ["update"]             = withConfig cx (\x -> update x False)     run cx ["update", "--force"]  = withConfig cx (\x -> update x True)     run cx ["set", "tagger", "ctags"]     = encodeConfig $ cx { tagsCmd = taggerCmd Ctags }
src/Codex.hs view
@@ -13,7 +13,7 @@ import Distribution.PackageDescription import Distribution.Text import Distribution.Verbosity-import Network.Curl.Download.Lazy+import Network.Curl.DownloadLazy import System.Directory import System.Directory.Machine (files, directoryWalk) import System.FilePath
+ src/Network/Curl/DownloadLazy.hs view
@@ -0,0 +1,115 @@+-- TODO Remove once https://github.com/GaloisInc/curl/pull/11 is released.++--------------------------------------------------------------------+-- |+-- Module    : Network.Curl.DownloadLazy+-- Copyright : (c) Don Stewart+-- License   : BSD3+--+-- Stability :  provisional+-- Portability: posix+--+-- This module is equivalent to download-curl's Network.Curl.Download.Lazy+-- A binding to curl, an efficient, high level library for+-- retrieving files using Uniform Resource Locators (URLs).+--+-- Content may be retrieved as a lazy "ByteString".+--+-- Error handling is encapsulated in the "Either" type.+--+--------------------------------------------------------------------++module Network.Curl.DownloadLazy (+        -- * The basic lazy interface to network content+          openLazyURI+        , openLazyURIWithOpts++    ) where++import           Foreign+import           Network.Curl++import           Data.IORef++import qualified Data.ByteString.Internal      as S+import qualified Data.ByteString.Lazy.Internal as L++------------------------------------------------------------------------++-- | Download content specified by a url using curl, returning the+-- content as a lazy "ByteString".+--+-- If an error occurs, "Left" is returned, with a+-- protocol-specific error string.+--+-- Examples:+--+-- > openLazyURI "http://haskell.org"+--+openLazyURI :: String -> IO (Either String L.ByteString)+openLazyURI = openLazyURIWithOpts []++-- | Like openURI, but takes curl options.+--+-- Examples:+--+-- > openLazyURIWithOpts [CurlPost True] "http://haskell.org"+--+openLazyURIWithOpts :: [CurlOption] -> String -> IO (Either String L.ByteString)+openLazyURIWithOpts opts s = case parseURL s of+     Nothing  -> return $ Left $ "Malformed url: "++ s+     Just url -> do+        e <- getFile url opts+        return $ case e of+             Left err   -> Left $ "Failed to connect: " ++ err+             Right src  -> Right src++------------------------------------------------------------------------+-- Internal:+--++newtype URL = URL String++parseURL :: String -> Maybe URL+parseURL s = Just (URL s) -- no parsing++getFile :: URL -> [CurlOption] -> IO (Either String L.ByteString)+getFile (URL url) flags = do+    h   <- initialize+    ref <- newIORef L.Empty++    _ <- setopt h (CurlFailOnError True)+    setDefaultSSLOpts h url+    _ <- setopt h (CurlURL url)+    _ <- setopt h (CurlWriteFunction (gather ref))+    mapM_ (setopt h) flags+    rc         <- perform h+    chunks     <- readIORef ref++    return $ if rc /= CurlOK+        then Left (show rc)+        else Right $! revSpine chunks++--          fp <- newForeignPtr finalizerFree buf'+--          return (Right $! S.fromForeignPtr fp 0 (fromIntegral sz))++gather :: IORef L.ByteString -> WriteFunction+gather r = writer $ \chunk -> do+    chunks <- readIORef r+    let chunks' = L.Chunk chunk chunks+    writeIORef r $! chunks'++-- memcpy chunks of data into our bytestring.+writer :: (S.ByteString -> IO ()) -> WriteFunction+writer f src sz nelems _ = do+    let n' = sz * nelems+    f =<< S.create (fromIntegral n') (\dest -> S.memcpy dest (castPtr src) (fromIntegral n'))+    return n'+++-- reverse just the spine of a lazy bytestring+revSpine :: L.ByteString -> L.ByteString+revSpine l =  rev l L.Empty+  where+    rev L.Empty a        = a+    rev (L.Chunk x xs) a = rev xs (L.Chunk x a)