on master help sign in
add locks for registry.dat and for individual package builds
commit71fa816b77b81f4cd3fc8ac48f363e47f05e40be authorEvan Czaplicki <evancz@users.noreply.github.com> dateTue 2 Jul 2019, 22:13 (7 years ago) parent0fc1429
3 files changed+18−6
builder/src/Deps/Solver.hs+1−1 builder/src/Elm/Details.hs+3−4 builder/src/Stuff.hs+14−1
builder/src/Deps/Solver.hs+1−1
@@ -349,9 +349,9 @@ data Env =
349349
350350initEnv :: IO (Either Exit.RegistryProblem Env)
351351initEnv =
352+ Stuff.withRegistryLock $ \cache ->
352353 do mvar <- newEmptyMVar
353354 _ <- forkIO $ putMVar mvar =<< Http.getManager
354− cache <- Stuff.getPackageCache
355355 maybeRegistry <- Registry.read cache
356356 manager <- readMVar mvar
357357
builder/src/Elm/Details.hs+3−4
@@ -358,10 +358,9 @@ type Dep =
358358
359359verifyDep :: Env -> MVar (Map.Map Pkg.Name (MVar Dep)) -> Map.Map Pkg.Name Solver.Details -> Pkg.Name -> Solver.Details -> IO Dep
360360verifyDep (Env key _ _ cache manager _ _) depsMVar solution pkg details@(Solver.Details vsn directDeps) =
361− let
362− fingerprint = Map.intersectionWith (\(Solver.Details v _) _ -> v) solution directDeps
363− in
364− do exists <- Dir.doesDirectoryExist (Stuff.package cache pkg vsn </> "src")
361+ Stuff.withPackageLock cache pkg vsn $
362+ do let fingerprint = Map.intersectionWith (\(Solver.Details v _) _ -> v) solution directDeps
363+ exists <- Dir.doesDirectoryExist (Stuff.package cache pkg vsn </> "src")
365364 if exists
366365 then
367366 do Reporting.report key Reporting.DCached
builder/src/Stuff.hs+14−1
@@ -9,6 +9,8 @@ module Stuff
99 , temp
1010 , findRoot
1111 , withRootLock
12+ , withRegistryLock
13+ , withPackageLock
1214 , PackageCache
1315 , getPackageCache
1416 , registry
@@ -123,7 +125,18 @@ withRootLock :: FilePath -> IO a -> IO a
123125withRootLock root work =
124126 do let dir = stuff root
125127 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)
127140
128141
129142