Commit 1e998287 authored by Duncan Coutts's avatar Duncan Coutts Committed by Alexis Williams
Browse files

Tweak the windows file locking hack

Put it in the cleanup handler so it always runs, exception or not.
parent 4a12f6f7
......@@ -5,8 +5,8 @@ import Distribution.Client.VCS
import Distribution.Client.RebuildMonad
( execRebuild )
import Distribution.Simple.Program
import Distribution.Simple.Utils
( withTempDirectory )
import Distribution.Compat.Internal.TempFile
( createTempDirectory )
import Distribution.Verbosity as Verbosity
import Distribution.Types.SourceRepo
......@@ -140,14 +140,6 @@ testSetup vcs mkVCSTestDriver repoRecipe theTest = do
-- actual test
result <- theTest vcsDriver tmpdir repoState
-- On Windows, file locks held by programs we run (in this case VCSs)
-- are not always released prior to completing process termination! (WTF!)
-- https://msdn.microsoft.com/en-us/library/windows/desktop/aa365202.aspx
-- This means we run into stale locks when trying to delete the test
-- directory. There is no sane way to wait on those locks being released,
-- we just have to wait and hope. Lets hope 10 second is enough.
when isWindows $ threadDelay 10000000
return result
where
verbosity = silent
......@@ -708,10 +700,19 @@ vcsTestDriverDarcs mtimeChange verbosity vcs repoRoot =
withTestDir :: (FilePath -> IO a) -> IO a
withTestDir action = do
systmpdir <- getTemporaryDirectory
withTempDirectory verbosity systmpdir "vcstest" action
bracket
(createTempDirectory systmpdir "vcstest")
(\dir -> windowsFileLockHack >> removeDirectoryRecursive dir)
action
where
verbosity = silent
isWindows :: Bool
isWindows = System.Info.os == "mingw32"
-- On Windows, file locks held by programs we run (in this case VCSs)
-- are not always released prior to completing process termination! (WTF!)
-- https://msdn.microsoft.com/en-us/library/windows/desktop/aa365202.aspx
-- This means we run into stale locks when trying to delete the test
-- directory. There is no sane way to wait on those locks being released,
-- we just have to wait and hope. Lets hope 1 second is enough.
windowsFileLockHack | isWindows = threadDelay 1000000
| otherwise = return ()
isWindows = System.Info.os == "mingw32"
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