From 4ffe240eca2e403e94e0e82d01503aedddda5747 Mon Sep 17 00:00:00 2001 From: Fred Dubois Date: Sat, 23 Jul 2011 12:58:24 -0400 Subject: [PATCH] Support for readonly file ProjectRef This allows using a project reference that points to a readonly directory. The use case for this is having sbt plugin projects on a network share (readonly) that you can just point to. The plugin projects get copied and built automatically, just like a git project reference gets cloned and built. This will ease plugin imcompatibilies between minor sbt versions, avoiding to have to cross build plugins against all compatible sbt versions. --- main/Build.scala | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/main/Build.scala b/main/Build.scala index 3e188e291..26b8c62ee 100644 --- a/main/Build.scala +++ b/main/Build.scala @@ -46,10 +46,29 @@ object RetrieveUnit case "http" | "https" => Some { () => downloadAndExtract(base, tmp); tmp } case "file" => val f = new File(base) - if(f.isDirectory) Some(() => f) else None + if(f.isDirectory) + { + val finalDir = if (!f.canWrite) retrieveRODir(f, tmp) else f + Some(() => finalDir) + } + else None case _ => None } } + def retrieveRODir(base: File, tempDir: File): File = + { + if (!tempDir.exists) + { + try { + IO.copyDirectory(base, tempDir) + } catch { + case e => + IO.delete(tempDir) + throw e + } + } + tempDir + } def downloadAndExtract(base: URI, tempDir: File): Unit = if(!tempDir.exists) IO.unzipURL(base.toURL, tempDir) def temporary(tempDir: File, uri: URI): File = new File(tempDir, Hash.halve(hash(uri))) def hash(uri: URI): String = Hash.toHex(Hash(uri.toASCIIString))