on master help sign in
add locks for registry.dat and for individual package builds
71fa816Evan Czaplicki
builder/src/Deps/Solver.hs+1−1
@@ -349,9 +349,9 @@ data Env =
349
349
350initEnv :: IO (Either Exit.RegistryProblem Env)
350initEnv :: IO (Either Exit.RegistryProblem Env)
351initEnv =
351initEnv =
352+ Stuff.withRegistryLock $ \cache ->
352 do mvar <- newEmptyMVar
353 do mvar <- newEmptyMVar
353 _ <- forkIO $ putMVar mvar =<< Http.getManager
354 _ <- forkIO $ putMVar mvar =<< Http.getManager
354− cache <- Stuff.getPackageCache
355 maybeRegistry <- Registry.read cache
355 maybeRegistry <- Registry.read cache
356 manager <- readMVar mvar
356 manager <- readMVar mvar
357
357
builder/src/Elm/Details.hs+3−4
@@ -358,10 +358,9 @@ type Dep =
358
358
359verifyDep :: Env -> MVar (Map.Map Pkg.Name (MVar Dep)) -> Map.Map Pkg.Name Solver.Details -> Pkg.Name -> Solver.Details -> IO Dep
359verifyDep :: Env -> MVar (Map.Map Pkg.Name (MVar Dep)) -> Map.Map Pkg.Name Solver.Details -> Pkg.Name -> Solver.Details -> IO Dep
360verifyDep (Env key _ _ cache manager _ _) depsMVar solution pkg details@(Solver.Details vsn directDeps) =
360verifyDep (Env key _ _ cache manager _ _) depsMVar solution pkg details@(Solver.Details vsn directDeps) =
361− let
361+ Stuff.withPackageLock cache pkg vsn $
362− fingerprint = Map.intersectionWith (\(Solver.Details v _) _ -> v) solution directDeps
362+ do let fingerprint = Map.intersectionWith (\(Solver.Details v _) _ -> v) solution directDeps
363− in
364− do exists <- Dir.doesDirectoryExist (Stuff.package cache pkg vsn </> "src")
363+ exists <- Dir.doesDirectoryExist (Stuff.package cache pkg vsn </> "src")
365 if exists
364 if exists
366 then
365 then
367 do Reporting.report key Reporting.DCached
366 do Reporting.report key Reporting.DCached
builder/src/Stuff.hs+14−1
@@ -9,6 +9,8 @@ module Stuff
9 , temp
9 , temp
10 , findRoot
10 , findRoot
11 , withRootLock
11 , withRootLock
12+ , withRegistryLock
13+ , withPackageLock
12 , PackageCache
14 , PackageCache
13 , getPackageCache
15 , getPackageCache
14 , registry
16 , registry
@@ -123,7 +125,18 @@ withRootLock :: FilePath -> IO a -> IO a
123withRootLock root work =
125withRootLock root work =
124 do let dir = stuff root
126 do let dir = stuff root
125 Dir.createDirectoryIfMissing True dir
127 Dir.createDirectoryIfMissing True dir
126− Lock.withFileLock (dir </> "project.lock") Lock.Exclusive (\_ -> work)
128+ Lock.withFileLock (dir </> "lock") Lock.Exclusive (\_ -> work)
129+
130+
131+withRegistryLock :: (PackageCache -> IO a) -> IO a
132+withRegistryLock callback =
133+ do cache@(PackageCache dir) <- getPackageCache
134+ Lock.withFileLock (dir </> "lock") Lock.Exclusive (\_ -> callback cache)
135+
136+
137+withPackageLock :: PackageCache -> Pkg.Name -> V.Version -> IO a -> IO a
138+withPackageLock cache pkg vsn work =
139+ Lock.withFileLock (package cache pkg vsn </> "lock") Lock.Exclusive (\_ -> work)
127
140
128
141
129
142