CurryInfo: cpm-3.3.0 / CPM.PackageCache.Global.readInstalledPackagesFromDir

definition:
readInstalledPackagesFromDir :: Repository -> String
                             -> ErrorLogger (Either String GlobalCache)
readInstalledPackagesFromDir repo path = do
  logDebug $ "Reading global package cache from '" ++ path ++ "'..."
  pkgPaths <- liftIOEL $ checkAndGetVisibleDirectoryContents path
  specs <- mapM loadPackageSpecFromDir pkgPaths
  if null (lefts specs)
    then do logDebug "Finished reading global package cache"
            return (Right $ GlobalCache (rights specs))
    else return (Left $ intercalate "; " (lefts specs))
 where
  readPackageSpecIO = liftIOEL . fmap readPackageSpec

  loadPackageSpecFromDir pkgdir = case packageVersionFromFile pkgdir of
    Nothing -> readPackageSpecFromFile pkgdir
    Just (pn,pv) -> case CPM.Repository.findVersion repo pn pv of
      Nothing -> readPackageSpecFromFile pkgdir
      Just p  -> return (Right p)

  readPackageSpecFromFile pkgdir = do
    let f = path </> pkgdir </> packageSpecFile
    logDebug $ "Reading package spec from '" ++ f ++ "'..."
    spec <- readPackageSpecIO $ readCompleteFile f
    return $ case spec of
      Left err -> Left $ err ++ " for file '" ++ f ++ "'"
      Right  v -> Right v

  packageVersionFromFile :: String -> Maybe (String, Version)
  packageVersionFromFile fn =
    let ps = split (=='-') fn
        l  = length ps
    in if l < 2
         then Nothing
         else case readVersion (last ps) of
                Nothing -> Nothing
                Just v  -> Just (intercalate "-" (take (l-1) ps), v)
demand:
no demanded arguments
deterministic:
deterministic operation
documentation:
--- Tries to read package specifications from a GC directory structure.
--- If some GC package directory has the same name as a package from
--- the repository index, the package specification from the repository
--- is used, otherwise (this case should not occur) the package specification
--- stored in the directory is read.
--- This should result in faster GC loading.
failfree:
<FAILING>
indeterministic:
referentially transparent operation
infix:
no fixity defined
iotype:
{(_,_) |-> _}
name:
readInstalledPackagesFromDir
precedence:
no precedence defined
result-values:
_
signature:
CPM.Repository.Repository -> String
-> CPM.ErrorLogger.ErrorLogger (Prelude.Either String GlobalCache)
solution-complete:
operation might suspend on free variables
terminating:
possibly non-terminating
totally-defined:
possibly non-reducible on same data term