com-lihaoyi / mill

Mill is a fast JVM build tool that supports Java and Scala. 2-3x faster than Gradle and 5-10x faster than Maven for common workflows, Mill aims to make your project’s build process performant, maintainable, and flexible
https://mill-build.org/
MIT License
2.05k stars 333 forks source link

Windows read-only files are not cleaned up #2642

Open pieter-bos opened 1 year ago

pieter-bos commented 1 year ago

It seems that mill is not able to clean up files that are marked as read-only on windows. For example:

import mill._
import os._

object tasks extends Module {
  def task() = T.command {
    val path = T.dest / "result"
    os.write(path, "hi")
    path.toIO.setWritable(false)
    path
  }
}

I can only run this command once:

C:\(...)>millw tasks.task
[1/1] tasks.task

C:\(...)>millw tasks.task
[build.sc] [44/49] cliImports
Exception in thread "MillServerActionRunner" java.nio.file.AccessDeniedException: C:\(...)\out\tasks\task.dest\result
        at java.base/sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:89)
        at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:103)
        at java.base/sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:108)
        at java.base/sun.nio.fs.WindowsFileSystemProvider.implDelete(WindowsFileSystemProvider.java:275)
        at java.base/sun.nio.fs.AbstractFileSystemProvider.deleteIfExists(AbstractFileSystemProvider.java:110)
        at java.base/java.nio.file.Files.deleteIfExists(Files.java:1191)
        at os.remove$.apply(FileOps.scala:318)
        at os.remove$.apply(FileOps.scala:312)
        at os.remove$all$.$anonfun$apply$5(FileOps.scala:329)
        at os.remove$all$.$anonfun$apply$5$adapted(FileOps.scala:329)
        at geny.Generator.$anonfun$foreach$1(Generator.scala:50)
        at geny.Generator$Mapped.$anonfun$generate$4(Generator.scala:283)
        at os.walk$stream$$anon$2$$anon$3.visitFile(ListOps.scala:258)
        at os.walk$stream$$anon$2$$anon$3.visitFile(ListOps.scala:239)
        at java.base/java.nio.file.Files.walkFileTree(Files.java:2811)
        at os.walk$stream$$anon$2.generate(ListOps.scala:239)
        at geny.Generator$Mapped.generate(Generator.scala:283)
        at geny.Generator.foreach(Generator.scala:49)
        at geny.Generator.foreach$(Generator.scala:49)
        at geny.Generator$Mapped.foreach(Generator.scala:281)
        at os.remove$all$.apply(FileOps.scala:329)
        at mill.eval.GroupEvaluator.evaluateGroupCached(GroupEvaluator.scala:120)
        (...)

One of our windows users noticed this in practice from a task that clones a git repository. It appears that their git distribution marks all files in the .git directory as read-only.

lefou commented 1 year ago

We probably need to implement a force flag upstream in os-Lib os.remove.all.