Use sync instead of copying the directory

This commit is contained in:
Eugene Yokota 2025-11-13 04:07:54 -05:00
parent 2459663387
commit 0e9eb00a7d
1 changed files with 15 additions and 12 deletions

View File

@ -4064,20 +4064,23 @@ object Classpaths {
def makeProducts: Initialize[Task[Seq[File]]] = Def.task { def makeProducts: Initialize[Task[Seq[File]]] = Def.task {
val c = fileConverter.value val c = fileConverter.value
val resources = copyResources.value.map(_._2).toSet val syncDir = target.value / (prefix(configuration.value.name) + "sync")
val classDir = classDirectory.value val factory = CacheStoreFactory(syncDir)
val cacheStore = factory.make("make-product")
val t = classDirectory.value
val vfBackendDir = compileIncremental.value._2 val vfBackendDir = compileIncremental.value._2
val backendDir = c.toPath(vfBackendDir) val backendDir = c.toPath(vfBackendDir)
// delete outdated files val flt: File => Option[File] = flat(t)
Path val transform: File => Option[File] =
.allSubpaths(classDir) (f: File) => rebase(backendDir.toFile(), t)(f).orElse(flt(f))
.collect { case (f, _) if f.isFile() && !resources.contains(f) => f } val resources = copyResources.value.map(_._2).toSet
.foreach(IO.delete) val view = fileTreeView.value
IO.copyDirectory( val classes = view.list((Glob(backendDir, RecursiveGlob / "*")))
source = backendDir.toFile(), val mappings: Seq[(File, File)] = classes.flatMap:
target = classDir, case (r, attr) if r != backendDir => transform(r.toFile()).map(r.toFile() -> _)
) case _ => None
classDir :: Nil Sync.sync(cacheStore, fileConverter = c)(mappings)
t :: Nil
} }
private[sbt] def makePickleProducts: Initialize[Task[Seq[VirtualFile]]] = Def.task { private[sbt] def makePickleProducts: Initialize[Task[Seq[VirtualFile]]] = Def.task {