Skip to content

Commit

Permalink
Remove read-only in cabal clean on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
jasagredo committed Jul 16, 2024
1 parent 2fbfd55 commit 3545f2b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
21 changes: 20 additions & 1 deletion cabal-install/src/Distribution/Client/CmdClean.hs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ import Distribution.Simple.Utils
, info
, wrapText
)
import Distribution.System
( OS (Windows)
, buildOS
)
import Distribution.Utils.Path hiding
( (<.>)
, (</>)
Expand All @@ -60,6 +64,9 @@ import Distribution.Verbosity
( normal
)

import Control.Exception
( throw
)
import Control.Monad
( forM
, forM_
Expand All @@ -78,6 +85,10 @@ import System.Directory
import System.FilePath
( (</>)
)
import System.IO.Error
( isPermissionError
)
import qualified System.Process as Process

data CleanFlags = CleanFlags
{ cleanSaveConfig :: Flag Bool
Expand Down Expand Up @@ -168,7 +179,15 @@ cleanAction (ProjectFlags{..}, CleanFlags{..}) extraArgs _ = do
let distRoot = distDirectory distLayout

info verbosity ("Deleting dist-newstyle (" ++ distRoot ++ ")")
handleDoesNotExist () $ removeDirectoryRecursive distRoot
handleDoesNotExist () $ do
if buildOS == Windows
then do
-- Windows can't delete some git files #10182
void $ Process.createProcess_ "attrib" $ Process.shell $ "attrib -s -h -r " <> distRoot <> "\\*.* /s /d"
catch
(removeDirectoryRecursive distRoot)
(\e -> if isPermissionError e then removeDirectoryRecursive distRoot else throw e)
else removeDirectoryRecursive distRoot

removeEnvFiles $ distProjectRootDirectory distLayout

Expand Down
11 changes: 11 additions & 0 deletions changelog.d/pr-10190
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
synopsis: Fix `cabal clean` permissions on Windows
packages: cabal-install
prs: #10190
issues: #10182
significance:

description: {

- `cabal clean` now removes the read-only mark recursively in the `dist-newstyle` folder on Windows before attempting to delete it.

}

0 comments on commit 3545f2b

Please sign in to comment.