Skip to content

Commit

Permalink
Remove top-level codebase locking
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPenner committed Jan 14, 2025
1 parent aaa4018 commit d7f3a37
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 8 deletions.
5 changes: 3 additions & 2 deletions unison-cli/src/Unison/CommandLine/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,10 @@ main dir welcome ppIds initialInputs runtime sbRuntime nRuntime codebase serverB
(!result, resultState) <-
FL.withTryFileLock (lockfilePath (Codebase.codebasePath codebase)) FL.Exclusive (\_flock -> do Cli.runCli env s0 (HandleInput.loop input))
>>= \case
Nothing -> pure (Cli.Continue, s0)
Just (result, s1) -> do
Nothing -> do
hPutStrLn stderr $ "Another client is running a command on this codebase, please close the other process or wait for it to finish. If issues persist, try deleting the lockfile at " <> lockfilePath (Codebase.codebasePath codebase)
pure (Cli.Continue, s0)
Just (result, s1) -> do
pure (result, s1)
let sNext = case input of
Left _ -> resultState
Expand Down
4 changes: 2 additions & 2 deletions unison-cli/src/Unison/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ prepareTranscriptDir verbosity shouldFork mCodePathOption shouldSaveCodebase = d
Path.copyDir (CodebaseInit.codebasePath cbInit path) (CodebaseInit.codebasePath cbInit tmp)
DontFork -> do
PT.putPrettyLn . P.wrap $ "Transcript will be run on a new, empty codebase."
CodebaseInit.withNewUcmCodebaseOrExit cbInit verbosity "main.transcript" tmp SC.DoLock (const $ pure ())
CodebaseInit.withNewUcmCodebaseOrExit cbInit verbosity "main.transcript" tmp SC.DontLock (const $ pure ())
pure tmp

runTranscripts' ::
Expand Down Expand Up @@ -553,7 +553,7 @@ getCodebaseOrExit :: Maybe CodebasePathOption -> SC.MigrationStrategy -> ((InitR
getCodebaseOrExit codebasePathOption migrationStrategy action = do
initOptions <- argsToCodebaseInitOptions codebasePathOption
let cbInit = SC.init
result <- CodebaseInit.withOpenOrCreateCodebase cbInit "main" initOptions SC.DoLock migrationStrategy \case
result <- CodebaseInit.withOpenOrCreateCodebase cbInit "main" initOptions SC.DontLock migrationStrategy \case
cbInit@(CreatedCodebase, dir, _) -> do
pDir <- prettyDir dir
PT.putPrettyLn' ""
Expand Down
6 changes: 3 additions & 3 deletions unison-cli/tests/Unison/Test/Ucm.hs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ initCodebase fmt = do
tmp <-
Temp.getCanonicalTemporaryDirectory
>>= flip Temp.createTempDirectory "ucm-test"
result <- Codebase.Init.withCreatedCodebase cbInit "ucm-test" tmp SC.DoLock (const $ pure ())
result <- Codebase.Init.withCreatedCodebase cbInit "ucm-test" tmp SC.DontLock (const $ pure ())
case result of
Left CreateCodebaseAlreadyExists -> fail $ P.toANSI 80 "Codebase already exists"
Right _ -> pure $ Codebase tmp fmt
Expand All @@ -70,7 +70,7 @@ runTranscript (Codebase codebasePath fmt) transcript = do
isTest = True
Transcript.withRunner isTest Verbosity.Silent "Unison.Test.Ucm.runTranscript Invalid Version String" rtp $
\runner -> do
result <- Codebase.Init.withOpenCodebase cbInit "transcript" codebasePath SC.DoLock SC.DontMigrate \codebase -> do
result <- Codebase.Init.withOpenCodebase cbInit "transcript" codebasePath SC.DontLock SC.DontMigrate \codebase -> do
Codebase.runTransaction codebase (Codebase.installUcmDependencies codebase)
let transcriptSrc = stripMargin . Text.pack $ unTranscript transcript
output <-
Expand All @@ -87,7 +87,7 @@ runTranscript (Codebase codebasePath fmt) transcript = do
lowLevel :: Codebase -> (Codebase.Codebase IO Symbol Ann -> IO a) -> IO a
lowLevel (Codebase root fmt) action = do
let cbInit = case fmt of CodebaseFormat2 -> SC.init
result <- Codebase.Init.withOpenCodebase cbInit "lowLevel" root SC.DoLock SC.DontMigrate action
result <- Codebase.Init.withOpenCodebase cbInit "lowLevel" root SC.DontLock SC.DontMigrate action
case result of
Left e -> PT.putPrettyLn (P.shown e) *> pure (error "This really should have loaded")
Right a -> pure a
2 changes: 1 addition & 1 deletion unison-cli/transcripts/Transcripts.hs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ testBuilder ::
testBuilder expectFailure replaceOriginal recordFailure runtimePath inputDir outputDir prelude transcript =
scope transcript do
outputs <-
io $ withTemporaryUcmCodebase SC.init Verbosity.Silent "transcript" SC.DoLock \(codebasePath, codebase) ->
io $ withTemporaryUcmCodebase SC.init Verbosity.Silent "transcript" SC.DontLock \(codebasePath, codebase) ->
let isTest = True
in Transcript.withRunner isTest Verbosity.Silent "TODO: pass version here" runtimePath \runTranscript ->
for files \filePath -> do
Expand Down

0 comments on commit d7f3a37

Please sign in to comment.