fix GlobalLock behavior when lock file's directory does not exist

This commit is contained in:
Mark Harrah 2010-01-29 20:29:23 -05:00
parent 586650d7a9
commit d01be91844
2 changed files with 20 additions and 1 deletions

View File

@ -9,7 +9,12 @@ object Locks extends xsbti.GlobalLock
{
private[this] val locks = new Cache[File, GlobalLock](new GlobalLock(_))
def apply[T](file: File, action: Callable[T]): T =
synchronized { locks(file.getCanonicalFile).withLock(action) }
synchronized
{
file.getParentFile.mkdirs()
file.createNewFile()
locks(file.getCanonicalFile).withLock(action)
}
private[this] class GlobalLock(file: File)
{

View File

@ -0,0 +1,14 @@
package xsbt.boot
import org.scalacheck._
import Prop._
import java.io.File
object LocksTest extends Properties("Locks")
{
property("Lock in nonexisting directory") =
FileUtilities.withTemporaryDirectory { dir =>
val lockFile = new File(dir, "doesntexist/lock")
Locks(lockFile, new java.util.concurrent.Callable[Boolean] { def call = true })
}
}