create directories if they don't exist webid
authorHenry Story <henry.story@bblfish.net>
Wed, 04 Apr 2012 22:31:39 +0200
branchwebid
changeset 186 20b5f23f324f
parent 185 b11844b0eea8
child 187 7c66ffcf3853
create directories if they don't exist
src/main/scala/Filesystem.scala
--- a/src/main/scala/Filesystem.scala	Wed Apr 04 18:23:20 2012 +0200
+++ b/src/main/scala/Filesystem.scala	Wed Apr 04 22:31:39 2012 +0200
@@ -25,6 +25,7 @@
     def name() = url
     val relativePath: String = url.getPath.replaceAll("^"+basePath.toString+"/?", "")
     val fileOnDisk = new File(baseDirectory, relativePath)
+    lazy val parent = fileOnDisk.getParentFile
     
     private def parentMustExist(): Unit = {
       val parent = fileOnDisk.getParentFile
@@ -74,7 +75,7 @@
     
     def save(model: Model): Validation[Throwable, Unit] =
       try {
-        createFileOnDisk()
+        parent.mkdirs()
         val fos = new FileOutputStream(fileOnDisk)
         val writer = model.getWriter(lang.jenaLang)
         writer.write(model, fos, url.toString)