summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2009-09-01 16:05:38 +0000
committerPaul Phillips <paulp@improving.org>2009-09-01 16:05:38 +0000
commitcfed2479dcfb88b3ded652a73a8a5278bbc0e8cd (patch)
tree73de3c20e40fbcb633172e908219963e11ac49f3
parent0ef9dbcef0a6a77388dd5bce78282b7892192019 (diff)
downloadscala-cfed2479dcfb88b3ded652a73a8a5278bbc0e8cd.tar.gz
scala-cfed2479dcfb88b3ded652a73a8a5278bbc0e8cd.tar.bz2
scala-cfed2479dcfb88b3ded652a73a8a5278bbc0e8cd.zip
Changed createDirectory and createFile to accept a
failIfExists argument (defaults to false) and eliminated the very short-lived ensureDirectory and ensureFile.
-rw-r--r--src/compiler/scala/tools/nsc/CompileServer.scala4
-rw-r--r--src/compiler/scala/tools/nsc/CompileSocket.scala4
-rw-r--r--src/compiler/scala/tools/nsc/io/AbstractFile.scala4
-rw-r--r--src/compiler/scala/tools/nsc/io/PlainFile.scala2
-rw-r--r--src/library/scala/io/Path.scala24
-rw-r--r--src/library/scala/xml/persistent/CachedFileStorage.scala2
6 files changed, 18 insertions, 22 deletions
diff --git a/src/compiler/scala/tools/nsc/CompileServer.scala b/src/compiler/scala/tools/nsc/CompileServer.scala
index 4e037201a4..85c992a9e2 100644
--- a/src/compiler/scala/tools/nsc/CompileServer.scala
+++ b/src/compiler/scala/tools/nsc/CompileServer.scala
@@ -142,10 +142,10 @@ class StandardCompileServer extends SocketServer
}
/** A directory holding redirected output */
- private val redirectDir = (compileSocket.tmpDir / "output-redirects").ensureDirectory()
+ private val redirectDir = (compileSocket.tmpDir / "output-redirects").createDirectory()
private def redirect(setter: PrintStream => Unit, filename: String): Unit =
- setter(new PrintStream((redirectDir / filename).ensureFile.bufferedOutput()))
+ setter(new PrintStream((redirectDir / filename).createFile().bufferedOutput()))
def main(args: Array[String]) {
redirect(System.setOut, "scala-compile-server-out.log")
diff --git a/src/compiler/scala/tools/nsc/CompileSocket.scala b/src/compiler/scala/tools/nsc/CompileSocket.scala
index d65485d998..30b8882904 100644
--- a/src/compiler/scala/tools/nsc/CompileSocket.scala
+++ b/src/compiler/scala/tools/nsc/CompileSocket.scala
@@ -59,7 +59,7 @@ class CompileSocket {
/** A temporary directory to use */
val tmpDir = {
val udir = Option(Properties.userName) getOrElse "shared"
- val f = (Path(Properties.tmpDir) / "scala-devel" / udir).ensureDirectory()
+ val f = (Path(Properties.tmpDir) / "scala-devel" / udir).createDirectory()
if (f.isDirectory && f.canWrite) {
info("[Temp directory: " + f + "]")
@@ -69,7 +69,7 @@ class CompileSocket {
}
/* A directory holding port identification files */
- val portsDir = (tmpDir / dirName).ensureDirectory()
+ val portsDir = (tmpDir / dirName).createDirectory()
/** Maximum number of polls for an available port */
private val MaxAttempts = 100
diff --git a/src/compiler/scala/tools/nsc/io/AbstractFile.scala b/src/compiler/scala/tools/nsc/io/AbstractFile.scala
index d54e982753..518dc1b9e6 100644
--- a/src/compiler/scala/tools/nsc/io/AbstractFile.scala
+++ b/src/compiler/scala/tools/nsc/io/AbstractFile.scala
@@ -223,7 +223,7 @@ abstract class AbstractFile extends AnyRef with Iterable[AbstractFile] {
*/
def fileNamed(name: String): AbstractFile = {
assert(isDirectory)
- Option(lookupName(name, false)) getOrElse new PlainFile((sfile / name).ensureFile())
+ Option(lookupName(name, false)) getOrElse new PlainFile((sfile / name).createFile())
}
/**
@@ -232,7 +232,7 @@ abstract class AbstractFile extends AnyRef with Iterable[AbstractFile] {
*/
def subdirectoryNamed(name: String): AbstractFile = {
assert (isDirectory)
- Option(lookupName(name, true)) getOrElse new PlainFile((sfile / name).ensureDirectory())
+ Option(lookupName(name, true)) getOrElse new PlainFile((sfile / name).createDirectory())
}
/** Returns the path of this abstract file. */
diff --git a/src/compiler/scala/tools/nsc/io/PlainFile.scala b/src/compiler/scala/tools/nsc/io/PlainFile.scala
index 359f062f41..7e5e8576b1 100644
--- a/src/compiler/scala/tools/nsc/io/PlainFile.scala
+++ b/src/compiler/scala/tools/nsc/io/PlainFile.scala
@@ -77,7 +77,7 @@ class PlainFile(val givenPath: Path) extends AbstractFile {
}
/** Does this abstract file denote an existing file? */
- def create: Unit = if (!exists) givenPath.ensureFile()
+ def create: Unit = if (!exists) givenPath.createFile()
/** Delete the underlying file or directory (recursively). */
def delete: Unit =
diff --git a/src/library/scala/io/Path.scala b/src/library/scala/io/Path.scala
index d5fde5d410..258076d0b5 100644
--- a/src/library/scala/io/Path.scala
+++ b/src/library/scala/io/Path.scala
@@ -138,22 +138,18 @@ class Path private[io] (val jfile: JFile)
// creations
def create(): Boolean = true
- def createDirectory(force: Boolean = true): Directory = {
+ def createDirectory(force: Boolean = true, failIfExists: Boolean = false): Directory = {
val res = if (force) jfile.mkdirs() else jfile.mkdir()
- if (res) new Directory(jfile)
- else fail("Failed to create new directory.")
+ if (!res && exists && failIfExists) fail("Directory '%s' already exists." format name)
+ else if (isDirectory) toDirectory
+ else new Directory(jfile)
+ }
+ def createFile(failIfExists: Boolean = false): File = {
+ val res = jfile.createNewFile()
+ if (!res && exists && failIfExists) fail("File '%s' already exists." format name)
+ else if (isFile) toFile
+ else new File(jfile)
}
- def createFile(): File =
- if (jfile.createNewFile()) new File(jfile)
- else fail("Failed to create new file.")
-
- /** Like createDirectory, but does not fail if it already exists. */
- def ensureDirectory(force: Boolean = true): Directory =
- if (this.isDirectory) this.toDirectory else createDirectory(force)
-
- /** This is temporary while I try to unbreak fsc. */
- def ensureFile(): File =
- if (this.isFile) this.toFile else createFile()
// deletions
def delete() = jfile.delete()
diff --git a/src/library/scala/xml/persistent/CachedFileStorage.scala b/src/library/scala/xml/persistent/CachedFileStorage.scala
index 8b3907b7f5..17194b4421 100644
--- a/src/library/scala/xml/persistent/CachedFileStorage.scala
+++ b/src/library/scala/xml/persistent/CachedFileStorage.scala
@@ -81,7 +81,7 @@ extends java.lang.Thread with scala.util.logging.Logged
log("[save]\ndeleting "+theFile);
theFile.delete();
log("creating new "+theFile);
- theFile.ensureFile();
+ theFile.createFile();
val fos = theFile.outputStream()
val c = fos.getChannel()