scala/ScalaBook/chapter-09/src/main/scala/scalabook/file/VFS.scala

package scalabook.file

import path.Path

object VFS {
  type AnyFile = VFile[_]
}

trait VFS[T <: VFile[T]] {
  def name: String
  def mkpath(name: String): Path
  def roots: List[T]

  def root = roots(0)

  def container: Option[VFS.AnyFile]
  def isContained = container.isDefined

  def newTempFile(prefix: String, suffix: String): T

  def newFolder(path: Path) = newFile(path)
  def newFolder(path: String): T = newFolder(mkpath(path))

  def newFile(path: Path): T

  def newFile(path: String): T = newFile(mkpath(path))
  
  def resolve(path: Path): Option[T]
  def resolve(path: String): Option[T] = resolve(mkpath(path))

  def contains(path: Path) = resolve(path).isDefined
  def contains(path: String) = resolve(path).isDefined

  override def toString = "VFS(" + name + ")"
}