Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cabal-tests/lib/Test/Utils/TempTestDir.hs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ removeDirectoryRecursiveHack :: Verbosity -> FilePath -> IO ()
removeDirectoryRecursiveHack verbosity dir | isWindows = go 1
where
isWindows = System.Info.os == "mingw32"
limit = 3
limit = 5

go :: Int -> IO ()
go n = do
Expand Down
13 changes: 11 additions & 2 deletions cabal-install/src/Distribution/Client/CmdClean.hs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import Control.Monad
, mapM
)
import qualified Data.Set as Set
import qualified GHC.IO.Exception as GHC
import System.Directory
( canonicalizePath
, doesDirectoryExist
Expand All @@ -92,7 +93,8 @@ import System.FilePath
( (</>)
)
import System.IO.Error
( isPermissionError
( ioeGetErrorType
, isPermissionError
)
import qualified System.Process as Process

Expand Down Expand Up @@ -193,7 +195,14 @@ cleanAction (ProjectFlags{..}, CleanFlags{..}) extraArgs _ = do
"attrib -s -h -r " <> distRoot <> "\\*.* /s /d"
catch
(removePathForcibly distRoot)
(\e -> if isPermissionError e then threadDelay 1000 >> removePathForcibly distRoot else throw e)
( \e ->
-- Permission error is usually when some files are (temporarily) locked.
-- Unsatisfied constraints (directory is non empty) error happens
-- when some files inside the directory were not removed (perhaps because they are locked).
if isPermissionError e || ioeGetErrorType e == GHC.UnsatisfiedConstraints
then threadDelay 1000 >> removePathForcibly distRoot
else throw e
)

removeEnvFiles $ distProjectRootDirectory distLayout

Expand Down
2 changes: 1 addition & 1 deletion changelog.d/pr-11604.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
synopsis: Replace removeDirectoryRecursive with removePathForcibly
packages: [Cabal, cabal-install]
prs: 11604
prs: 11604 11938
---

We replace `System.Directory.removeDirectoryRecursive` calls with a more robust `System.Directory.removePathForcibly`. Additionally, some functions (most notably the one responsible for `cabal clean`) now run `removeDirectoryRecursive` twice on all platforms if the first time was not successful (previously only on Windows) and include a small delay in between.
Loading