Commit 4cef100e authored by Niels Bunkenburg's avatar Niels Bunkenburg

Add package store for multi-imports #56

parent f490c038
......@@ -85,14 +85,14 @@ importMultiplePackages paths = do
let tmpdir = "tmp/" ++ (getPathFileName tarpath)
untarPackage tmpdir tarpath
dirname <- getPackageDir tmpdir
return dirname) paths
return (dirname, tarpath)) paths
-- Split into dependency levels
get <- mapM (\path -> do
get <- mapM (\(path, tarpath) -> do
content <- getFileContent (path </> "package.json")
let spec = CPM.readPackageSpec content
case spec of
(Left error) -> fail ("Invalid package.json\n" ++ error)
(Right package) -> return (package, path)) dirs
(Right package) -> return (package, path, tarpath)) dirs
let order = dependencySplit get [] []
importOrder order
......@@ -101,15 +101,18 @@ importMultiplePackages paths = do
case packages of
[] -> done
(x:xs) -> do
mapM_ (\(p, path) -> do
mapM_ (\(p, path, tarpath) -> do
(_, _) <- createPackage p
(name, version) <- handleUploadNewPackage Nothing (path </> "package.json")
createDirectoryIfMissing True ("packages" </> name </> version)
renameDirectory path ("packages" </> name </> version)) x
renameDirectory path ("packages" </> name </> version)
-- Move tar file to package store
createDirectoryIfMissing True "packagestore"
copyFile tarpath ("packagestore" </> name ++ "-" ++ version ++ ".tar.gz")) x
importOrder xs
type PackagePair = (CPM.Package, String)
type PackagePair = (CPM.Package, String, String)
dependencySplit :: [PackagePair] -> [String] -> [[PackagePair]] -> [[PackagePair]]
dependencySplit todo base iter =
......@@ -122,9 +125,9 @@ dependencySplit todo base iter =
dependencySplit newTodo base (iter ++ [newIter])
where
isAllowed :: PackagePair -> Bool
isAllowed (package, _) = do
isAllowed (package, _, _) = do
let deps = CPM.dependencyNames package
let iterNames = map (\(p, _) -> CPM.name p) (concat iter)
let iterNames = map (\(p, _, _) -> CPM.name p) (concat iter)
let allowed = map (\dep -> dep `elem` base || dep `elem` iterNames) deps
foldl (&&) True allowed
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment