CurryInfo: cpm-3.3.0 / CPM.Package.Helpers.installPackageSourceTo

definition:
installPackageSourceTo :: Package -> PackageSource -> String -> ErrorLogger ()
---
--- @param pkg        - the package specification of the package
--- @param source     - the source of the package
--- @param installdir - the directory where the package subdirectory should be
---                     installed
installPackageSourceTo pkg (Git url rev) installdir = do
  let pkgDir = installdir </> pkgid
  c <- inDirectoryEL installdir $
         execQuietCmd (cloneCommand "-q") (cloneCommand "")
  if c == 0
    then case rev of
      Nothing           -> checkoutGitRef pkgDir "HEAD"
      Just (Tag tag)    -> checkoutGitRef pkgDir
                                          (replaceVersionInTag pkg tag)
      Just (Ref ref)    -> checkoutGitRef pkgDir ref
      Just VersionAsTag ->
        let tag = "v" ++ (showVersion $ version pkg)
        in do checkoutGitRef pkgDir tag
              logInfo $ "Package '" ++ packageId pkg ++ "' installed"
    else liftIOEL (removeDirectoryComplete pkgDir) >>
         fail ("Failed to clone repository from '" ++ url ++
                 "', return code " ++ show c)
 where
  pkgid  = packageId pkg
  cloneCommand q = unwords ["git clone", q, quote url, quote $ pkgid]

installPackageSourceTo pkg (FileSource zipfile) installdir =
  installPkgFromFile pkg zipfile (installdir </> packageId pkg) False

installPackageSourceTo pkg (Http url) installdir = do
  pid <- liftIOEL $ getPID
  let pkgDir  = installdir </> packageId pkg
      basepf  = "package" ++ show pid
      pkgfile = if takeExtension url == ".zip"
                  then basepf ++ ".zip"
                  else if ".tar.gz" `isSuffixOf` url
                         then basepf ++ ".tar.gz"
                         else ""
  if null pkgfile
    then fail $ "Illegal URL (only .zip or .tar.gz allowed):\n" ++ url
    else do
      tmpdir <- liftIOEL tempDir
      let tmppkgfile = tmpdir </> pkgfile
      curlcmd <- getCurlCmd
      c <- inTempDirEL $ showExecCmd $
             curlcmd ++ " -f -o " ++ tmppkgfile ++ " " ++ quote url
      if c == 0
        then installPkgFromFile pkg tmppkgfile pkgDir True
        else do liftIOEL cleanTempDir
                fail $ "`curl` failed with exit status " ++ show c
demand:
argument 2
deterministic:
deterministic operation
documentation:
------------------------------------------------------------------------------
--- Installs the source of the package from the given source location
--- into the subdirectory `packageId pkg` of the given directory.
failfree:
<FAILING>
indeterministic:
referentially transparent operation
infix:
no fixity defined
iotype:
{(_,{Git},_) |-> _ || (_,{FileSource},_) |-> _ || (_,{Http},_) |-> _}
name:
installPackageSourceTo
precedence:
no precedence defined
result-values:
_
signature:
CPM.Package.Package -> CPM.Package.PackageSource -> String
-> CPM.ErrorLogger.ErrorLogger ()
solution-complete:
operation might suspend on free variables
terminating:
possibly non-terminating
totally-defined:
possibly non-reducible on same data term