Merge pull request #120 from duboisf/ro_file_projectref

Readonly file ProjectRef
This commit is contained in:
Mark Harrah 2011-07-23 19:33:37 -07:00
commit 671053c62f
1 changed files with 20 additions and 1 deletions

View File

@ -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))